2018-11-30 01:06:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017. Alexander Bilchuk <a.bilchuk@sandrlab.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
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-26 14:35:21 +00:00
|
|
|
import android.app.Activity
|
|
|
|
import android.app.ActivityOptions
|
2018-11-30 01:06:16 +00:00
|
|
|
import android.util.DisplayMetrics
|
2019-12-26 14:35:21 +00:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2018-11-30 01:06:16 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
2020-02-25 13:15:23 +00:00
|
|
|
import code.name.monkey.retromusic.glide.AlbumGlideRequest
|
2019-12-26 14:35:21 +00:00
|
|
|
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
2018-11-30 01:06:16 +00:00
|
|
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
|
|
|
import code.name.monkey.retromusic.model.Album
|
|
|
|
import code.name.monkey.retromusic.util.NavigationUtil
|
|
|
|
import code.name.monkey.retromusic.views.MetalRecyclerViewPager
|
2019-09-16 18:02:40 +00:00
|
|
|
import com.bumptech.glide.Glide
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-11-15 17:44:42 +00:00
|
|
|
class AlbumFullWidthAdapter(
|
2020-01-02 03:53:43 +00:00
|
|
|
private val activity: Activity,
|
2020-02-17 11:20:08 +00:00
|
|
|
private val dataSet: List<Album>,
|
2020-01-02 03:53:43 +00:00
|
|
|
metrics: DisplayMetrics
|
2019-11-15 17:44:42 +00:00
|
|
|
) : MetalRecyclerViewPager.MetalAdapter<AlbumFullWidthAdapter.FullMetalViewHolder>(metrics) {
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-26 14:35:21 +00:00
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FullMetalViewHolder {
|
2020-02-25 13:15:23 +00:00
|
|
|
return FullMetalViewHolder(
|
|
|
|
LayoutInflater.from(parent.context).inflate(
|
|
|
|
R.layout.pager_item,
|
|
|
|
parent,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
)
|
2019-12-26 14:35:21 +00:00
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-26 14:35:21 +00:00
|
|
|
override fun onBindViewHolder(holder: FullMetalViewHolder, position: Int) {
|
|
|
|
// don't forget about calling supper.onBindViewHolder!
|
|
|
|
super.onBindViewHolder(holder, position)
|
|
|
|
val album = dataSet[position]
|
|
|
|
holder.title?.text = getAlbumTitle(album)
|
|
|
|
holder.text?.text = getAlbumText(album)
|
2020-01-02 03:53:43 +00:00
|
|
|
holder.playSongs?.setOnClickListener {
|
|
|
|
album.songs?.let { songs ->
|
|
|
|
MusicPlayerRemote.openQueue(
|
|
|
|
songs,
|
|
|
|
0,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-12-26 14:35:21 +00:00
|
|
|
loadAlbumCover(album, holder)
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-26 14:35:21 +00:00
|
|
|
private fun getAlbumTitle(album: Album): String? {
|
|
|
|
return album.title
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-26 14:35:21 +00:00
|
|
|
private fun getAlbumText(album: Album): String? {
|
|
|
|
return album.artistName
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-26 14:35:21 +00:00
|
|
|
private fun loadAlbumCover(album: Album, holder: FullMetalViewHolder) {
|
|
|
|
if (holder.image == null) {
|
|
|
|
return
|
|
|
|
}
|
2020-02-25 13:15:23 +00:00
|
|
|
AlbumGlideRequest.Builder.from(Glide.with(activity), album.safeGetFirstSong())
|
2020-01-02 03:53:43 +00:00
|
|
|
.checkIgnoreMediaStore(activity)
|
|
|
|
.generatePalette(activity)
|
|
|
|
.build()
|
|
|
|
.into(object : RetroMusicColoredTarget(holder.image!!) {
|
|
|
|
override fun onColorReady(color: Int) {
|
|
|
|
}
|
|
|
|
})
|
2019-12-26 14:35:21 +00:00
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-26 14:35:21 +00:00
|
|
|
override fun getItemCount(): Int {
|
|
|
|
return dataSet.size
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-02-25 13:15:23 +00:00
|
|
|
inner class FullMetalViewHolder(itemView: View) :
|
|
|
|
MetalRecyclerViewPager.MetalViewHolder(itemView) {
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-26 14:35:21 +00:00
|
|
|
override fun onClick(v: View?) {
|
2020-01-02 03:53:43 +00:00
|
|
|
val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
|
|
|
|
activity,
|
|
|
|
imageContainerCard ?: image,
|
|
|
|
"${activity.getString(R.string.transition_album_art)}_${dataSet[adapterPosition].id}"
|
|
|
|
)
|
2019-12-26 14:35:21 +00:00
|
|
|
NavigationUtil.goToAlbumOptions(activity, dataSet[adapterPosition].id, activityOptions)
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|