2020-10-06 08:46:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Hemanth Savarla.
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License v3
|
|
|
|
*
|
|
|
|
* This is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.adapter.album
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-10 17:36:20 +00:00
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2020-08-11 18:29:44 +00:00
|
|
|
import androidx.fragment.app.FragmentActivity
|
2020-02-25 13:15:23 +00:00
|
|
|
import code.name.monkey.retromusic.glide.AlbumGlideRequest
|
2019-12-10 17:36:20 +00:00
|
|
|
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
2018-11-30 01:06:16 +00:00
|
|
|
import code.name.monkey.retromusic.helper.HorizontalAdapterHelper
|
2020-09-27 18:59:09 +00:00
|
|
|
import code.name.monkey.retromusic.interfaces.IAlbumClickListener
|
2020-09-23 20:55:12 +00:00
|
|
|
import code.name.monkey.retromusic.interfaces.ICabHolder
|
2018-11-30 01:06:16 +00:00
|
|
|
import code.name.monkey.retromusic.model.Album
|
|
|
|
import code.name.monkey.retromusic.util.MusicUtil
|
2020-05-05 19:44:59 +00:00
|
|
|
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
2019-09-16 18:02:40 +00:00
|
|
|
import com.bumptech.glide.Glide
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-09-16 18:02:40 +00:00
|
|
|
class HorizontalAlbumAdapter(
|
2020-08-11 18:29:44 +00:00
|
|
|
activity: FragmentActivity,
|
2020-02-17 11:20:08 +00:00
|
|
|
dataSet: List<Album>,
|
2020-09-23 20:55:12 +00:00
|
|
|
ICabHolder: ICabHolder?,
|
2020-09-27 18:59:09 +00:00
|
|
|
albumClickListener: IAlbumClickListener
|
2019-09-16 18:02:40 +00:00
|
|
|
) : AlbumAdapter(
|
2020-09-23 20:55:12 +00:00
|
|
|
activity, dataSet, HorizontalAdapterHelper.LAYOUT_RES, ICabHolder, albumClickListener
|
2019-09-16 18:02:40 +00:00
|
|
|
) {
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun createViewHolder(view: View, viewType: Int): ViewHolder {
|
|
|
|
val params = view.layoutParams as ViewGroup.MarginLayoutParams
|
|
|
|
HorizontalAdapterHelper.applyMarginToLayoutParams(activity, params, viewType)
|
|
|
|
return ViewHolder(view)
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-05-11 09:51:22 +00:00
|
|
|
override fun setColors(color: MediaNotificationProcessor, holder: ViewHolder) {
|
2020-10-06 08:46:04 +00:00
|
|
|
// holder.title?.setTextColor(ATHUtil.resolveColor(activity, android.R.attr.textColorPrimary))
|
|
|
|
// holder.text?.setTextColor(ATHUtil.resolveColor(activity, android.R.attr.textColorSecondary))
|
2020-01-17 17:19:06 +00:00
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun loadAlbumCover(album: Album, holder: ViewHolder) {
|
|
|
|
if (holder.image == null) return
|
2020-02-25 13:15:23 +00:00
|
|
|
AlbumGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
|
2020-09-05 15:52:10 +00:00
|
|
|
.checkIgnoreMediaStore()
|
2020-02-25 13:15:23 +00:00
|
|
|
.generatePalette(activity)
|
|
|
|
.build()
|
2020-01-17 17:19:06 +00:00
|
|
|
.into(object : RetroMusicColoredTarget(holder.image!!) {
|
2020-05-05 19:44:59 +00:00
|
|
|
override fun onColorReady(colors: MediaNotificationProcessor) {
|
2020-05-09 13:41:20 +00:00
|
|
|
setColors(colors, holder)
|
2020-01-17 17:19:06 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun getAlbumText(album: Album): String? {
|
|
|
|
return MusicUtil.getYearString(album.year)
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun getItemViewType(position: Int): Int {
|
|
|
|
return HorizontalAdapterHelper.getItemViewtype(position, itemCount)
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
override fun getItemCount(): Int {
|
|
|
|
return dataSet.size
|
|
|
|
}
|
2019-01-02 03:55:55 +00:00
|
|
|
|
2020-01-17 17:19:06 +00:00
|
|
|
companion object {
|
|
|
|
val TAG: String = AlbumAdapter::class.java.simpleName
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|