Implement media fragment for tv shows
This commit is contained in:
@ -3,10 +3,10 @@ package org.mosad.teapod.util
|
||||
import java.util.Locale
|
||||
|
||||
class DataTypes {
|
||||
enum class MediaType {
|
||||
OTHER,
|
||||
MOVIE,
|
||||
TVSHOW
|
||||
enum class MediaType(val str: String) {
|
||||
OTHER("other"),
|
||||
MOVIE("movie"), // TODO
|
||||
TVSHOW("series")
|
||||
}
|
||||
|
||||
enum class Theme(val str: String) {
|
||||
@ -37,7 +37,8 @@ data class ThirdPartyComponent(
|
||||
data class ItemMedia(
|
||||
val id: Int, // aod path id
|
||||
val title: String,
|
||||
val posterUrl: String
|
||||
val posterUrl: String,
|
||||
val idStr: String = "" // crunchyroll id
|
||||
)
|
||||
|
||||
// TODO replace playlist: List<AoDEpisode> with a map?
|
||||
|
@ -4,19 +4,18 @@ import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemEpisodeBinding
|
||||
import org.mosad.teapod.util.AoDEpisode
|
||||
import org.mosad.teapod.parser.crunchyroll.Episodes
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVEpisode
|
||||
|
||||
class EpisodeItemAdapter(private val episodes: List<AoDEpisode>, private val tmdbEpisodes: List<TMDBTVEpisode>?) : RecyclerView.Adapter<EpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
class EpisodeItemAdapter(private val episodes: Episodes, private val tmdbEpisodes: List<TMDBTVEpisode>?) : RecyclerView.Adapter<EpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
|
||||
var onImageClick: ((String, Int) -> Unit)? = null
|
||||
var onImageClick: ((seasonId: String, episodeId: String) -> Unit)? = null
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EpisodeViewHolder {
|
||||
return EpisodeViewHolder(ItemEpisodeBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
@ -24,52 +23,63 @@ class EpisodeItemAdapter(private val episodes: List<AoDEpisode>, private val tmd
|
||||
|
||||
override fun onBindViewHolder(holder: EpisodeViewHolder, position: Int) {
|
||||
val context = holder.binding.root.context
|
||||
val ep = episodes[position]
|
||||
val ep = episodes.items[position]
|
||||
|
||||
val titleText = if (ep.hasDub()) {
|
||||
context.getString(R.string.component_episode_title, ep.numberStr, ep.description)
|
||||
val titleText = if (ep.isDubbed) {
|
||||
context.getString(R.string.component_episode_title, ep.episode, ep.title)
|
||||
} else {
|
||||
context.getString(R.string.component_episode_title_sub, ep.numberStr, ep.description)
|
||||
context.getString(R.string.component_episode_title_sub, ep.episode, ep.title)
|
||||
}
|
||||
|
||||
holder.binding.textEpisodeTitle.text = titleText
|
||||
holder.binding.textEpisodeDesc.text = if (ep.shortDesc.isNotEmpty()) {
|
||||
ep.shortDesc
|
||||
holder.binding.textEpisodeDesc.text = if (ep.description.isNotEmpty()) {
|
||||
ep.description
|
||||
} else if (tmdbEpisodes != null && position < tmdbEpisodes.size){
|
||||
tmdbEpisodes[position].overview
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
if (ep.imageURL.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.imageURL)
|
||||
// TODO is isNotEmpty() needed?
|
||||
if (ep.images.thumbnail[0][0].source.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.images.thumbnail[0][0].source)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.apply(RequestOptions.bitmapTransform(RoundedCornersTransformation(10, 0)))
|
||||
.into(holder.binding.imageEpisode)
|
||||
}
|
||||
|
||||
if (ep.watched) {
|
||||
holder.binding.imageWatched.setImageDrawable(
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_baseline_check_circle_24)
|
||||
)
|
||||
} else {
|
||||
holder.binding.imageWatched.setImageDrawable(null)
|
||||
}
|
||||
// TODO
|
||||
// if (ep.watched) {
|
||||
// holder.binding.imageWatched.setImageDrawable(
|
||||
// ContextCompat.getDrawable(context, R.drawable.ic_baseline_check_circle_24)
|
||||
// )
|
||||
// } else {
|
||||
// holder.binding.imageWatched.setImageDrawable(null)
|
||||
// }
|
||||
// disable watched icon until implemented
|
||||
holder.binding.imageWatched.setImageDrawable(null)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return episodes.size
|
||||
return episodes.items.size
|
||||
}
|
||||
|
||||
fun updateWatchedState(watched: Boolean, position: Int) {
|
||||
// use getOrNull as there could be a index out of bound when running this in onResume()
|
||||
episodes.getOrNull(position)?.watched = watched
|
||||
|
||||
// TODO
|
||||
//episodes.getOrNull(position)?.watched = watched
|
||||
}
|
||||
|
||||
inner class EpisodeViewHolder(val binding: ItemEpisodeBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
inner class EpisodeViewHolder(val binding: ItemEpisodeBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
// on image click return the episode id and index (within the adapter)
|
||||
binding.imageEpisode.setOnClickListener {
|
||||
onImageClick?.invoke(episodes[adapterPosition].title, adapterPosition)
|
||||
onImageClick?.invoke(
|
||||
episodes.items[bindingAdapterPosition].seasonId,
|
||||
episodes.items[bindingAdapterPosition].id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import java.util.*
|
||||
|
||||
class MediaItemAdapter(private val initMedia: List<ItemMedia>) : RecyclerView.Adapter<MediaItemAdapter.MediaViewHolder>(), Filterable {
|
||||
|
||||
var onItemClick: ((Int, Int) -> Unit)? = null
|
||||
var onItemClick: ((String, Int) -> Unit)? = null
|
||||
private val filter = MediaFilter()
|
||||
private var filteredMedia = initMedia.map { it.copy() }
|
||||
|
||||
@ -42,7 +42,7 @@ class MediaItemAdapter(private val initMedia: List<ItemMedia>) : RecyclerView.Ad
|
||||
inner class MediaViewHolder(val binding: ItemMediaBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
binding.root.setOnClickListener {
|
||||
onItemClick?.invoke(filteredMedia[adapterPosition].id, adapterPosition)
|
||||
onItemClick?.invoke(filteredMedia[adapterPosition].idStr, adapterPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user