mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-20 00:55:20 +01:00
Updated
Item list to support big screen Fix search for playlist Fix playlist crash
This commit is contained in:
parent
f2e290d274
commit
209e3d58eb
80 changed files with 1025 additions and 448 deletions
|
@ -1,6 +1,5 @@
|
|||
package code.name.monkey.retromusic.adapter
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -23,14 +22,12 @@ class GenreAdapter(
|
|||
var dataSet: List<Genre>,
|
||||
private val mItemLayoutRes: Int
|
||||
) : RecyclerView.Adapter<GenreAdapter.ViewHolder>() {
|
||||
val colors = listOf<Int>(Color.RED, Color.BLUE)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(LayoutInflater.from(activity).inflate(mItemLayoutRes, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val genre = dataSet[position]
|
||||
|
||||
holder.title?.text = genre.name
|
||||
holder.text?.text = String.format(
|
||||
Locale.getDefault(),
|
||||
|
|
|
@ -4,12 +4,15 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.*
|
||||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
||||
import code.name.monkey.retromusic.glide.AlbumGlideRequest
|
||||
import code.name.monkey.retromusic.glide.ArtistGlideRequest
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
|
@ -19,6 +22,7 @@ import code.name.monkey.retromusic.model.smartplaylist.AbsSmartPlaylist
|
|||
import code.name.monkey.retromusic.repository.PlaylistSongsLoader
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import java.util.*
|
||||
|
||||
class SearchAdapter(
|
||||
private val activity: FragmentActivity,
|
||||
|
@ -34,7 +38,7 @@ class SearchAdapter(
|
|||
if (dataSet[position] is Album) return ALBUM
|
||||
if (dataSet[position] is Artist) return ARTIST
|
||||
if (dataSet[position] is Genre) return GENRE
|
||||
if (dataSet[position] is Playlist) return PLAYLIST
|
||||
if (dataSet[position] is PlaylistWithSongs) return PLAYLIST
|
||||
return if (dataSet[position] is Song) SONG else HEADER
|
||||
}
|
||||
|
||||
|
@ -56,42 +60,52 @@ class SearchAdapter(
|
|||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
when (getItemViewType(position)) {
|
||||
ALBUM -> {
|
||||
val album = dataSet.get(position) as Album
|
||||
holder. imageTextContainer?.isVisible = true
|
||||
val album = dataSet[position] as Album
|
||||
holder.title?.text = album.title
|
||||
holder.text?.text = album.artistName
|
||||
AlbumGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
|
||||
.checkIgnoreMediaStore().build().into(holder.image)
|
||||
}
|
||||
ARTIST -> {
|
||||
val artist = dataSet.get(position) as Artist
|
||||
holder. imageTextContainer?.isVisible = true
|
||||
val artist = dataSet[position] as Artist
|
||||
holder.title?.text = artist.name
|
||||
holder.text?.text = MusicUtil.getArtistInfoString(activity, artist)
|
||||
ArtistGlideRequest.Builder.from(Glide.with(activity), artist).build()
|
||||
.into(holder.image)
|
||||
}
|
||||
SONG -> {
|
||||
val song = dataSet.get(position) as Song
|
||||
val song = dataSet[position] as Song
|
||||
holder.title?.text = song.title
|
||||
holder.text?.text = song.albumName
|
||||
}
|
||||
GENRE -> {
|
||||
val genre = dataSet.get(position) as Genre
|
||||
val genre = dataSet[position] as Genre
|
||||
holder.title?.text = genre.name
|
||||
holder.text?.text = String.format(
|
||||
Locale.getDefault(),
|
||||
"%d %s",
|
||||
genre.songCount,
|
||||
if (genre.songCount > 1) activity.getString(R.string.songs) else activity.getString(
|
||||
R.string.song
|
||||
)
|
||||
)
|
||||
}
|
||||
PLAYLIST -> {
|
||||
val playlist = dataSet.get(position) as Playlist
|
||||
holder.title?.text = playlist.name
|
||||
holder.text?.text = MusicUtil.getPlaylistInfoString(activity, getSongs(playlist))
|
||||
val playlist = dataSet[position] as PlaylistWithSongs
|
||||
holder.title?.text = playlist.playlistEntity.playlistName
|
||||
holder.text?.text = MusicUtil.playlistInfoString(activity, playlist.songs)
|
||||
}
|
||||
else -> {
|
||||
holder.title?.text = dataSet.get(position).toString()
|
||||
holder.title?.text = dataSet[position].toString()
|
||||
holder.title?.setTextColor(ThemeStore.accentColor(activity))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSongs(playlist: Playlist): java.util.ArrayList<Song> {
|
||||
val songs = java.util.ArrayList<Song>()
|
||||
private fun getSongs(playlist: Playlist): List<Song> {
|
||||
val songs = mutableListOf<Song>()
|
||||
if (playlist is AbsSmartPlaylist) {
|
||||
songs.addAll(playlist.getSongs())
|
||||
} else {
|
||||
|
@ -107,7 +121,7 @@ class SearchAdapter(
|
|||
inner class ViewHolder(itemView: View, itemViewType: Int) : MediaEntryViewHolder(itemView) {
|
||||
init {
|
||||
itemView.setOnLongClickListener(null)
|
||||
|
||||
imageTextContainer?.isInvisible = true
|
||||
if (itemViewType == SONG) {
|
||||
menu?.visibility = View.VISIBLE
|
||||
menu?.setOnClickListener(object : SongMenuHelper.OnClickSongMenu(activity) {
|
||||
|
@ -156,7 +170,7 @@ class SearchAdapter(
|
|||
)
|
||||
}
|
||||
SONG -> {
|
||||
val playList = ArrayList<Song>()
|
||||
val playList = mutableListOf<Song>()
|
||||
playList.add(item as Song)
|
||||
MusicPlayerRemote.openQueue(playList, 0, true)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package code.name.monkey.retromusic.adapter.base;
|
|||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
@ -41,15 +40,13 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
|
|||
|
||||
@Nullable
|
||||
public ImageView image;
|
||||
|
||||
@Nullable
|
||||
public ImageView artistImage;
|
||||
|
||||
@Nullable
|
||||
public ImageView playerImage;
|
||||
|
||||
@Nullable
|
||||
public ViewGroup imageContainer;
|
||||
|
||||
@Nullable
|
||||
public MaterialCardView imageContainerCard;
|
||||
|
||||
|
@ -77,6 +74,9 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
|
|||
@Nullable
|
||||
public TextView text;
|
||||
|
||||
@Nullable
|
||||
public TextView text2;
|
||||
|
||||
@Nullable
|
||||
public TextView time;
|
||||
|
||||
|
@ -87,6 +87,7 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
|
|||
super(itemView);
|
||||
title = itemView.findViewById(R.id.title);
|
||||
text = itemView.findViewById(R.id.text);
|
||||
text2 = itemView.findViewById(R.id.text2);
|
||||
|
||||
image = itemView.findViewById(R.id.image);
|
||||
artistImage = itemView.findViewById(R.id.artistImage);
|
||||
|
@ -94,7 +95,6 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
|
|||
time = itemView.findViewById(R.id.time);
|
||||
|
||||
imageText = itemView.findViewById(R.id.imageText);
|
||||
imageContainer = itemView.findViewById(R.id.imageContainer);
|
||||
imageTextContainer = itemView.findViewById(R.id.imageTextContainer);
|
||||
imageContainerCard = itemView.findViewById(R.id.imageContainerCard);
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.interfaces.ICabHolder
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
|
||||
abstract class AbsOffsetSongAdapter(
|
||||
activity: AppCompatActivity,
|
||||
activity: FragmentActivity,
|
||||
dataSet: MutableList<Song>,
|
||||
@LayoutRes itemLayoutRes: Int,
|
||||
ICabHolder: ICabHolder?
|
||||
|
|
|
@ -173,7 +173,7 @@ class PlayingQueueAdapter(
|
|||
}
|
||||
|
||||
override fun onGetSwipeReactionType(holder: ViewHolder, position: Int, x: Int, y: Int): Int {
|
||||
return if (onCheckCanStartDrag(holder!!, position, x, y)) {
|
||||
return if (onCheckCanStartDrag(holder, position, x, y)) {
|
||||
SwipeableItemConstants.REACTION_CAN_NOT_SWIPE_BOTH_H
|
||||
} else {
|
||||
SwipeableItemConstants.REACTION_CAN_SWIPE_BOTH_H
|
||||
|
|
|
@ -2,22 +2,21 @@ package code.name.monkey.retromusic.adapter.song
|
|||
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.navigation.findNavController
|
||||
import code.name.monkey.retromusic.EXTRA_ALBUM_ID
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.db.PlaylistEntity
|
||||
import code.name.monkey.retromusic.db.toSongEntity
|
||||
import code.name.monkey.retromusic.dialogs.RemoveSongFromPlaylistDialog
|
||||
import code.name.monkey.retromusic.interfaces.ICabHolder
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import com.google.android.material.button.MaterialButton
|
||||
|
||||
open class PlaylistSongAdapter(
|
||||
activity: AppCompatActivity,
|
||||
private val playlist: PlaylistEntity,
|
||||
activity: FragmentActivity,
|
||||
dataSet: MutableList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
ICabHolder: ICabHolder?
|
||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, ICabHolder) {
|
||||
) : SongAdapter(activity, dataSet, itemLayoutRes, ICabHolder) {
|
||||
|
||||
init {
|
||||
this.setMultiSelectMenuRes(R.menu.menu_cannot_delete_single_songs_playlist_songs_selection)
|
||||
|
@ -27,43 +26,21 @@ open class PlaylistSongAdapter(
|
|||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
|
||||
if (holder.itemViewType == OFFSET_ITEM) {
|
||||
val viewHolder = holder as ViewHolder
|
||||
viewHolder.playAction?.let {
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openQueue(dataSet, 0, true)
|
||||
}
|
||||
}
|
||||
viewHolder.shuffleAction?.let {
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onBindViewHolder(holder, position - 1)
|
||||
}
|
||||
}
|
||||
|
||||
open inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
|
||||
|
||||
val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
|
||||
val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
|
||||
open inner class ViewHolder(itemView: View) : SongAdapter.ViewHolder(itemView) {
|
||||
|
||||
override var songMenuRes: Int
|
||||
get() = R.menu.menu_item_cannot_delete_single_songs_playlist_song
|
||||
get() = R.menu.menu_item_playlist_song
|
||||
set(value) {
|
||||
super.songMenuRes = value
|
||||
}
|
||||
|
||||
override fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||
if (item.itemId == R.id.action_go_to_album) {
|
||||
activity.findNavController(R.id.fragment_container)
|
||||
.navigate(
|
||||
R.id.albumDetailsFragment,
|
||||
bundleOf(EXTRA_ALBUM_ID to song.albumId)
|
||||
)
|
||||
return true
|
||||
when (item.itemId) {
|
||||
R.id.action_remove_from_playlist -> {
|
||||
RemoveSongFromPlaylistDialog.create(song.toSongEntity(playlist.playListId))
|
||||
.show(activity.supportFragmentManager, "REMOVE_FROM_PLAYLIST")
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onSongMenuItemClick(item)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.view.MenuItem
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.navigation.findNavController
|
||||
import code.name.monkey.retromusic.EXTRA_ALBUM_ID
|
||||
|
@ -87,6 +88,7 @@ open class SongAdapter(
|
|||
}
|
||||
holder.title?.text = getSongTitle(song)
|
||||
holder.text?.text = getSongText(song)
|
||||
holder.text2?.text = getSongText(song)
|
||||
loadAlbumCover(song, holder)
|
||||
}
|
||||
|
||||
|
@ -121,6 +123,10 @@ open class SongAdapter(
|
|||
return song.artistName
|
||||
}
|
||||
|
||||
private fun getSongText2(song: Song): String? {
|
||||
return song.albumName
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return dataSet.size
|
||||
}
|
||||
|
@ -172,7 +178,7 @@ open class SongAdapter(
|
|||
}
|
||||
|
||||
protected open fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||
if (image != null && image!!.visibility == View.VISIBLE) {
|
||||
if (image != null && image!!.isVisible) {
|
||||
when (item.itemId) {
|
||||
R.id.action_go_to_album -> {
|
||||
activity.findNavController(R.id.fragment_container)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue