2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.adapter.album
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-09-18 15:44:14 +00:00
|
|
|
import android.app.ActivityOptions
|
2018-11-30 01:06:16 +00:00
|
|
|
import android.content.res.ColorStateList
|
|
|
|
import android.graphics.drawable.Drawable
|
2019-12-10 17:36:20 +00:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2018-11-30 01:06:16 +00:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2019-12-10 17:36:20 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
|
|
|
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
2019-09-18 15:44:14 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
2019-12-10 17:36:20 +00:00
|
|
|
import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
|
|
|
|
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
|
|
|
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
|
|
|
import code.name.monkey.retromusic.glide.SongGlideRequest
|
|
|
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
|
|
|
import code.name.monkey.retromusic.helper.SortOrder
|
2018-11-30 01:06:16 +00:00
|
|
|
import code.name.monkey.retromusic.helper.menu.SongsMenuHelper
|
|
|
|
import code.name.monkey.retromusic.interfaces.CabHolder
|
2019-12-10 17:36:20 +00:00
|
|
|
import code.name.monkey.retromusic.model.Album
|
|
|
|
import code.name.monkey.retromusic.model.Song
|
|
|
|
import code.name.monkey.retromusic.util.MusicUtil
|
|
|
|
import code.name.monkey.retromusic.util.NavigationUtil
|
|
|
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
2019-09-16 18:02:40 +00:00
|
|
|
import com.bumptech.glide.Glide
|
2018-11-30 01:06:16 +00:00
|
|
|
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
|
|
|
|
2019-11-15 17:44:42 +00:00
|
|
|
open class AlbumAdapter(
|
2019-12-10 17:36:20 +00:00
|
|
|
protected val activity: AppCompatActivity,
|
|
|
|
dataSet: ArrayList<Album>,
|
|
|
|
protected var itemLayoutRes: Int,
|
|
|
|
usePalette: Boolean,
|
|
|
|
cabHolder: CabHolder?
|
2019-11-15 17:44:42 +00:00
|
|
|
) : AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album>(
|
2019-12-10 17:36:20 +00:00
|
|
|
activity,
|
|
|
|
cabHolder,
|
|
|
|
R.menu.menu_media_selection
|
2019-11-15 17:44:42 +00:00
|
|
|
), FastScrollRecyclerView.SectionedAdapter {
|
2019-12-10 17:36:20 +00:00
|
|
|
var dataSet: ArrayList<Album>
|
|
|
|
protected set
|
|
|
|
|
|
|
|
protected var usePalette = false
|
|
|
|
|
|
|
|
init {
|
|
|
|
this.dataSet = dataSet
|
|
|
|
this.usePalette = usePalette
|
|
|
|
this.setHasStableIds(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun useItemLayout(itemLayoutRes: Int) {
|
|
|
|
this.itemLayoutRes = itemLayoutRes
|
|
|
|
notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun usePalette(usePalette: Boolean) {
|
|
|
|
this.usePalette = usePalette
|
|
|
|
notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun swapDataSet(dataSet: ArrayList<Album>) {
|
|
|
|
this.dataSet = dataSet
|
|
|
|
notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
|
|
|
val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
|
|
|
|
return createViewHolder(view, viewType)
|
|
|
|
}
|
|
|
|
|
|
|
|
protected open fun createViewHolder(view: View, viewType: Int): ViewHolder {
|
|
|
|
return ViewHolder(view)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getAlbumTitle(album: Album): String? {
|
|
|
|
return album.title
|
|
|
|
}
|
|
|
|
|
|
|
|
protected open fun getAlbumText(album: Album): String? {
|
|
|
|
return album.artistName
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
|
val album = dataSet[position]
|
|
|
|
val isChecked = isChecked(album)
|
|
|
|
holder.itemView.isActivated = isChecked
|
|
|
|
holder.title?.text = getAlbumTitle(album)
|
|
|
|
holder.text?.text = getAlbumText(album)
|
|
|
|
holder.playSongs?.setOnClickListener { album.songs?.let { songs -> MusicPlayerRemote.openQueue(songs, 0, true) } }
|
|
|
|
loadAlbumCover(album, holder)
|
|
|
|
}
|
|
|
|
|
|
|
|
protected open fun setColors(color: Int, holder: ViewHolder) {
|
|
|
|
if (holder.paletteColorContainer != null) {
|
|
|
|
holder.title?.setTextColor(MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(color)))
|
|
|
|
holder.text?.setTextColor(MaterialValueHelper.getSecondaryTextColor(activity, ColorUtil.isColorLight(color)))
|
|
|
|
holder.paletteColorContainer?.setBackgroundColor(color)
|
|
|
|
}
|
|
|
|
holder.mask?.backgroundTintList = ColorStateList.valueOf(color)
|
|
|
|
}
|
|
|
|
|
|
|
|
protected open fun loadAlbumCover(album: Album, holder: ViewHolder) {
|
|
|
|
if (holder.image == null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
SongGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
|
|
|
|
.checkIgnoreMediaStore(activity).generatePalette(activity).build()
|
|
|
|
.into(object : RetroMusicColoredTarget(holder.image!!) {
|
|
|
|
override fun onLoadCleared(placeholder: Drawable?) {
|
|
|
|
super.onLoadCleared(placeholder)
|
|
|
|
setColors(defaultFooterColor, holder)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onColorReady(color: Int) {
|
|
|
|
setColors(color, holder)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItemCount(): Int {
|
|
|
|
return dataSet.size
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItemId(position: Int): Long {
|
|
|
|
return dataSet[position].id.toLong()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getIdentifier(position: Int): Album? {
|
|
|
|
return dataSet[position]
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getName(album: Album): String {
|
|
|
|
return album.title!!
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onMultipleItemAction(
|
|
|
|
menuItem: MenuItem, selection: ArrayList<Album>
|
|
|
|
) {
|
|
|
|
SongsMenuHelper.handleMenuClick(activity, getSongList(selection), menuItem.itemId)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getSongList(albums: List<Album>): ArrayList<Song> {
|
|
|
|
val songs = ArrayList<Song>()
|
|
|
|
for (album in albums) {
|
|
|
|
songs.addAll(album.songs!!)
|
|
|
|
}
|
|
|
|
return songs
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getSectionName(position: Int): String {
|
|
|
|
var sectionName: String? = null
|
|
|
|
when (PreferenceUtil.getInstance(activity).albumSortOrder) {
|
|
|
|
SortOrder.AlbumSortOrder.ALBUM_A_Z, SortOrder.AlbumSortOrder.ALBUM_Z_A -> sectionName = dataSet[position].title
|
|
|
|
SortOrder.AlbumSortOrder.ALBUM_ARTIST -> sectionName = dataSet[position].artistName
|
|
|
|
SortOrder.AlbumSortOrder.ALBUM_YEAR -> return MusicUtil.getYearString(
|
|
|
|
dataSet[position].year
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return MusicUtil.getSectionName(sectionName)
|
|
|
|
}
|
|
|
|
|
|
|
|
inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
|
|
|
|
|
|
|
|
init {
|
|
|
|
setImageTransitionName(activity.getString(R.string.transition_album_art))
|
|
|
|
menu?.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onClick(v: View?) {
|
|
|
|
super.onClick(v)
|
|
|
|
if (isInQuickSelectMode) {
|
|
|
|
toggleChecked(adapterPosition)
|
|
|
|
} else {
|
|
|
|
val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
|
|
|
|
activity, image, activity.getString(
|
|
|
|
R.string.transition_album_art
|
|
|
|
)
|
|
|
|
)
|
|
|
|
NavigationUtil.goToAlbumOptions(
|
|
|
|
activity, dataSet[adapterPosition].id, activityOptions
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onLongClick(v: View?): Boolean {
|
|
|
|
toggleChecked(adapterPosition)
|
|
|
|
return super.onLongClick(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
val TAG: String = AlbumAdapter::class.java.simpleName
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|