2021-05-18 13:43:32 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.result
|
|
|
|
|
2021-06-26 19:32:50 +00:00
|
|
|
import android.annotation.SuppressLint
|
2021-05-18 13:43:32 +00:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.ImageView
|
|
|
|
import android.widget.TextView
|
2021-06-26 19:32:50 +00:00
|
|
|
import androidx.annotation.LayoutRes
|
|
|
|
import androidx.core.widget.ContentLoadingProgressBar
|
2021-05-18 13:43:32 +00:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2021-06-26 19:32:50 +00:00
|
|
|
import com.bumptech.glide.Glide
|
|
|
|
import com.bumptech.glide.load.model.GlideUrl
|
2021-07-23 23:44:54 +00:00
|
|
|
import com.lagradost.cloudstream3.R
|
2021-06-26 19:32:50 +00:00
|
|
|
import kotlinx.android.synthetic.main.result_episode.view.episode_holder
|
|
|
|
import kotlinx.android.synthetic.main.result_episode.view.episode_text
|
|
|
|
import kotlinx.android.synthetic.main.result_episode_large.view.*
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-06-29 23:14:48 +00:00
|
|
|
const val ACTION_PLAY_EPISODE_IN_PLAYER = 1
|
2021-07-17 21:36:50 +00:00
|
|
|
const val ACTION_PLAY_EPISODE_IN_VLC_PLAYER = 2
|
2021-07-17 14:14:25 +00:00
|
|
|
const val ACTION_PLAY_EPISODE_IN_BROWSER = 3
|
|
|
|
|
|
|
|
const val ACTION_CHROME_CAST_EPISODE = 4
|
|
|
|
const val ACTION_CHROME_CAST_MIRROR = 5
|
|
|
|
|
|
|
|
const val ACTION_DOWNLOAD_EPISODE = 6
|
|
|
|
const val ACTION_DOWNLOAD_MIRROR = 7
|
|
|
|
|
|
|
|
const val ACTION_RELOAD_EPISODE = 8
|
|
|
|
const val ACTION_COPY_LINK = 9
|
|
|
|
|
|
|
|
const val ACTION_SHOW_OPTIONS = 10
|
2021-05-20 20:56:21 +00:00
|
|
|
|
2021-07-23 23:44:54 +00:00
|
|
|
const val ACTION_CLICK_DEFAULT = 11
|
|
|
|
|
2021-05-20 20:56:21 +00:00
|
|
|
data class EpisodeClickEvent(val action: Int, val data: ResultEpisode)
|
2021-05-18 13:43:32 +00:00
|
|
|
|
|
|
|
class EpisodeAdapter(
|
2021-06-15 16:07:20 +00:00
|
|
|
var cardList: List<ResultEpisode>,
|
2021-07-23 23:44:54 +00:00
|
|
|
val hasDownloadSupport : Boolean,
|
2021-06-10 15:15:14 +00:00
|
|
|
private val clickCallback: (EpisodeClickEvent) -> Unit,
|
2021-05-18 13:43:32 +00:00
|
|
|
) :
|
|
|
|
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
2021-06-26 19:32:50 +00:00
|
|
|
@LayoutRes
|
|
|
|
private var layout: Int = 0
|
|
|
|
fun updateLayout() {
|
|
|
|
layout = if (cardList.filter { it.poster != null }.size >= cardList.size / 2)
|
|
|
|
R.layout.result_episode_large
|
|
|
|
else R.layout.result_episode
|
|
|
|
}
|
2021-05-18 13:43:32 +00:00
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
2021-06-26 19:32:50 +00:00
|
|
|
/*val layout = if (cardList.filter { it.poster != null }.size >= cardList.size / 2)
|
|
|
|
R.layout.result_episode_large
|
|
|
|
else R.layout.result_episode*/
|
|
|
|
|
2021-05-18 13:43:32 +00:00
|
|
|
return CardViewHolder(
|
2021-06-26 19:32:50 +00:00
|
|
|
LayoutInflater.from(parent.context).inflate(layout, parent, false),
|
2021-07-23 23:44:54 +00:00
|
|
|
hasDownloadSupport,
|
2021-05-20 15:22:28 +00:00
|
|
|
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-07-23 23:44:54 +00:00
|
|
|
private val hasDownloadSupport : Boolean,
|
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 episodeText: TextView = itemView.episode_text
|
2021-06-26 19:32:50 +00:00
|
|
|
private val episodeRating: TextView? = itemView.episode_rating
|
|
|
|
private val episodeDescript: TextView? = itemView.episode_descript
|
|
|
|
private val episodeProgress: ContentLoadingProgressBar? = itemView.episode_progress
|
|
|
|
private val episodePoster: ImageView? = itemView.episode_poster
|
2021-07-15 16:45:25 +00:00
|
|
|
private val episodeDownload: ImageView? = itemView.episode_download
|
2021-06-26 19:32:50 +00:00
|
|
|
|
2021-06-06 18:06:01 +00:00
|
|
|
private val episodeHolder = itemView.episode_holder
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-06-26 19:32:50 +00:00
|
|
|
@SuppressLint("SetTextI18n")
|
2021-05-18 13:43:32 +00:00
|
|
|
fun bind(card: ResultEpisode) {
|
2021-06-26 22:15:19 +00:00
|
|
|
val name = if (card.name == null) "Episode ${card.episode}" else "${card.episode}. ${card.name}"
|
|
|
|
episodeText.text = name
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-06-10 15:15:14 +00:00
|
|
|
val watchProgress = card.getWatchProgress()
|
2021-06-26 19:32:50 +00:00
|
|
|
|
|
|
|
episodeProgress?.progress = (watchProgress * 50).toInt()
|
|
|
|
episodeProgress?.visibility = if (watchProgress > 0.0f) View.VISIBLE else View.GONE
|
|
|
|
|
|
|
|
if (card.poster != null) {
|
|
|
|
episodePoster?.visibility = View.VISIBLE
|
|
|
|
if (episodePoster != null) {
|
|
|
|
val glideUrl =
|
|
|
|
GlideUrl(card.poster)
|
2021-07-15 16:45:25 +00:00
|
|
|
Glide.with(episodePoster.context)
|
|
|
|
.load(glideUrl)
|
|
|
|
.into(episodePoster)
|
2021-06-26 19:32:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
episodePoster?.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
|
|
|
if (card.rating != null) {
|
2021-06-26 22:15:19 +00:00
|
|
|
episodeRating?.text = "Rated: %.1f".format(card.rating.toFloat() / 10f).replace(",", ".")
|
2021-06-26 19:32:50 +00:00
|
|
|
} else {
|
|
|
|
episodeRating?.text = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if (card.descript != null) {
|
|
|
|
episodeDescript?.visibility = View.VISIBLE
|
|
|
|
episodeDescript?.text = card.descript
|
|
|
|
} else {
|
|
|
|
episodeDescript?.visibility = View.GONE
|
|
|
|
}
|
2021-05-18 13:43:32 +00:00
|
|
|
|
2021-06-06 18:06:01 +00:00
|
|
|
episodeHolder.setOnClickListener {
|
2021-07-23 23:44:54 +00:00
|
|
|
clickCallback.invoke(EpisodeClickEvent(ACTION_CLICK_DEFAULT, card))
|
2021-07-17 14:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
episodeHolder.setOnLongClickListener {
|
|
|
|
clickCallback.invoke(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
|
2021-07-15 16:45:25 +00:00
|
|
|
|
2021-07-17 14:14:25 +00:00
|
|
|
return@setOnLongClickListener true
|
2021-07-15 16:45:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 23:44:54 +00:00
|
|
|
episodeDownload?.visibility = if(hasDownloadSupport) View.VISIBLE else View.GONE
|
|
|
|
|
2021-07-15 16:45:25 +00:00
|
|
|
episodeDownload?.setOnClickListener {
|
|
|
|
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|