2021-05-18 13:43:32 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.result
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.ImageView
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
import android.widget.TextView
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import com.lagradost.cloudstream3.*
|
|
|
|
import kotlinx.android.synthetic.main.result_episode.view.*
|
|
|
|
|
2021-05-20 20:56:21 +00:00
|
|
|
const val ACTION_PLAY_EPISODE = 1
|
|
|
|
const val ACTION_RELOAD_EPISODE = 2
|
|
|
|
|
|
|
|
data class EpisodeClickEvent(val action: Int, val data: ResultEpisode)
|
2021-05-18 13:43:32 +00:00
|
|
|
|
|
|
|
class EpisodeAdapter(
|
2021-05-20 15:22:28 +00:00
|
|
|
private var activity: Activity,
|
|
|
|
var cardList: ArrayList<ResultEpisode>,
|
|
|
|
val resView: RecyclerView,
|
2021-05-20 20:56:21 +00:00
|
|
|
val clickCallback: (EpisodeClickEvent) -> Unit,
|
2021-05-18 13:43:32 +00:00
|
|
|
) :
|
|
|
|
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
|
|
|
return CardViewHolder(
|
|
|
|
LayoutInflater.from(parent.context).inflate(R.layout.result_episode, parent, false),
|
|
|
|
activity,
|
2021-05-20 15:22:28 +00:00
|
|
|
resView,
|
|
|
|
clickCallback
|
2021-05-18 13:43:32 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
|
|
|
when (holder) {
|
|
|
|
is CardViewHolder -> {
|
|
|
|
holder.bind(cardList[position])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItemCount(): Int {
|
|
|
|
return cardList.size
|
|
|
|
}
|
|
|
|
|
|
|
|
class CardViewHolder
|
2021-05-20 20:56:21 +00:00
|
|
|
constructor(
|
|
|
|
itemView: View,
|
2021-06-06 18:06:01 +00:00
|
|
|
val activity: Activity,
|
2021-05-20 20:56:21 +00:00
|
|
|
resView: RecyclerView,
|
2021-06-06 18:06:01 +00:00
|
|
|
private val clickCallback: (EpisodeClickEvent) -> Unit,
|
2021-05-20 20:56:21 +00:00
|
|
|
) : RecyclerView.ViewHolder(itemView) {
|
2021-06-06 18:06:01 +00:00
|
|
|
private val episodeViewPrecentage: View = itemView.episode_view_procentage
|
|
|
|
private val episodeViewPercentageOff: View = itemView.episode_view_procentage_off
|
|
|
|
private val episodeText: TextView = itemView.episode_text
|
|
|
|
val episodeExtra: ImageView = itemView.episode_extra
|
|
|
|
private val episodePlay: ImageView = itemView.episode_play
|
|
|
|
private val episodeHolder = itemView.episode_holder
|
2021-05-18 13:43:32 +00:00
|
|
|
|
|
|
|
fun bind(card: ResultEpisode) {
|
2021-06-06 18:06:01 +00:00
|
|
|
episodeText.text = card.name ?: "Episode ${card.episode}"
|
2021-05-18 13:43:32 +00:00
|
|
|
|
|
|
|
fun setWidth(v: View, procentage: Float) {
|
|
|
|
val param = LinearLayout.LayoutParams(
|
|
|
|
v.layoutParams.width,
|
|
|
|
v.layoutParams.height,
|
|
|
|
procentage
|
|
|
|
)
|
|
|
|
v.layoutParams = param
|
|
|
|
}
|
2021-06-06 18:06:01 +00:00
|
|
|
setWidth(episodeViewPrecentage, card.watchProgress)
|
|
|
|
setWidth(episodeViewPercentageOff, 1 - card.watchProgress)
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-06-06 18:06:01 +00:00
|
|
|
episodeHolder.setOnClickListener {
|
2021-05-20 20:56:21 +00:00
|
|
|
clickCallback.invoke(EpisodeClickEvent(ACTION_PLAY_EPISODE, card))
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|