up next rework
* start playback, when up next episode is clicked * add playhead progress indicator to up next episodes
This commit is contained in:
@ -0,0 +1,70 @@
|
||||
package org.mosad.teapod.util.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemMediaBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.ContinueWatchingItem
|
||||
|
||||
class MediaEpisodeListAdapter(private val onClickListener: OnClickListener) : ListAdapter<ContinueWatchingItem, MediaEpisodeListAdapter.MediaViewHolder>(DiffCallback) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaViewHolder {
|
||||
return MediaViewHolder(
|
||||
ItemMediaBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MediaViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.binding.root.setOnClickListener {
|
||||
onClickListener.onClick(item)
|
||||
}
|
||||
holder.bind(item)
|
||||
}
|
||||
|
||||
inner class MediaViewHolder(val binding: ItemMediaBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(item: ContinueWatchingItem) {
|
||||
val metadata = item.panel.episodeMetadata
|
||||
|
||||
binding.textTitle.text = binding.root.context.getString(R.string.season_episode_title,
|
||||
metadata.seasonNumber, metadata.episodeNumber, metadata.seriesTitle
|
||||
)
|
||||
|
||||
Glide.with(binding.imagePoster)
|
||||
.load(item.panel.images.thumbnail[0][0].source)
|
||||
.into(binding.imagePoster)
|
||||
|
||||
// add watched progress
|
||||
val playheadProgress = ((item.playhead.toFloat() / (metadata.durationMs / 1000)) * 100)
|
||||
.toInt()
|
||||
binding.progressPlayhead.setProgressCompat(playheadProgress, false)
|
||||
binding.progressPlayhead.visibility = if (playheadProgress <= 0)
|
||||
View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
companion object DiffCallback : DiffUtil.ItemCallback<ContinueWatchingItem>() {
|
||||
override fun areItemsTheSame(oldItem: ContinueWatchingItem, newItem: ContinueWatchingItem): Boolean {
|
||||
return oldItem.panel.id == newItem.panel.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: ContinueWatchingItem, newItem: ContinueWatchingItem): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
|
||||
class OnClickListener(val clickListener: (item: ContinueWatchingItem) -> Unit) {
|
||||
fun onClick(item: ContinueWatchingItem) = clickListener(item)
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package org.mosad.teapod.util.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@ -34,8 +35,13 @@ class MediaItemListAdapter(private val onClickListener: OnClickListener) : ListA
|
||||
|
||||
fun bind(item: ItemMedia) {
|
||||
binding.textTitle.text = item.title
|
||||
// can we use the view instead of context here?
|
||||
Glide.with(binding.root.context).load(item.posterUrl).into(binding.imagePoster)
|
||||
|
||||
Glide.with(binding.imagePoster)
|
||||
.load(item.posterUrl)
|
||||
.into(binding.imagePoster)
|
||||
|
||||
binding.imageEpisodePlay.isVisible = false
|
||||
binding.progressPlayhead.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemEpisodePlayerBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.Episodes
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVEpisode
|
||||
|
||||
class PlayerEpisodeItemAdapter(private val episodes: Episodes) : RecyclerView.Adapter<PlayerEpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
|
||||
@ -37,11 +36,7 @@ class PlayerEpisodeItemAdapter(private val episodes: Episodes) : RecyclerView.Ad
|
||||
}
|
||||
|
||||
holder.binding.textEpisodeTitle2.text = titleText
|
||||
holder.binding.textEpisodeDesc2.text = if (ep.description.isNotEmpty()) {
|
||||
ep.description
|
||||
} else {
|
||||
""
|
||||
}
|
||||
holder.binding.textEpisodeDesc2.text = ep.description.ifEmpty { "" }
|
||||
|
||||
if (ep.images.thumbnail[0][0].source.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.images.thumbnail[0][0].source)
|
||||
|
Reference in New Issue
Block a user