From 41d81a0c406915afc5d7b70adbe18b99e2a757cf Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sat, 26 Jun 2021 21:32:50 +0200 Subject: [PATCH] sff --- .../com/lagradost/cloudstream3/MainAPI.kt | 9 ++- .../cloudstream3/ui/result/EpisodeAdapter.kt | 72 +++++++++++++++++-- .../cloudstream3/ui/result/ResultFragment.kt | 15 +++- .../cloudstream3/ui/result/ResultViewModel.kt | 10 ++- app/src/main/res/layout/fragment_search.xml | 8 ++- .../main/res/layout/result_episode_large.xml | 58 +++++++++------ app/src/main/res/values/colors.xml | 2 +- 7 files changed, 134 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 9ff3050b..bfdba811 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -193,7 +193,14 @@ fun LoadResponse?.isAnimeBased(): Boolean { return (this.type == TvType.Anime || this.type == TvType.ONA) // && (this is AnimeLoadResponse) } -data class AnimeEpisode(val url: String, val name: String? = null) +data class AnimeEpisode( + val url: String, + val name: String? = null, + val posterUrl: String? = null, + val date: String? = null, + val rating: Int? = null, + val descript: String? = null, +) data class AnimeLoadResponse( val engName: String?, diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt index 5babc16a..dbd3a977 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt @@ -1,5 +1,6 @@ package com.lagradost.cloudstream3.ui.result +import android.annotation.SuppressLint import android.app.Activity import android.view.LayoutInflater import android.view.View @@ -7,12 +8,19 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView +import androidx.annotation.LayoutRes +import androidx.core.widget.ContentLoadingProgressBar import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.load.model.GlideUrl import com.google.android.gms.cast.framework.CastContext import com.google.android.gms.cast.framework.CastState import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.UIHelper.isCastApiAvailable import kotlinx.android.synthetic.main.result_episode.view.* +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.* const val ACTION_PLAY_EPISODE_IN_PLAYER = 1 const val ACTION_RELOAD_EPISODE = 4 @@ -27,10 +35,21 @@ class EpisodeAdapter( private val clickCallback: (EpisodeClickEvent) -> Unit, ) : RecyclerView.Adapter() { + @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 + } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + /*val layout = if (cardList.filter { it.poster != null }.size >= cardList.size / 2) + R.layout.result_episode_large + else R.layout.result_episode*/ + return CardViewHolder( - LayoutInflater.from(parent.context).inflate(R.layout.result_episode, parent, false), + LayoutInflater.from(parent.context).inflate(layout, parent, false), activity, resView, clickCallback @@ -56,13 +75,19 @@ class EpisodeAdapter( resView: RecyclerView, private val clickCallback: (EpisodeClickEvent) -> Unit, ) : RecyclerView.ViewHolder(itemView) { - private val episodeViewPrecentage: View = itemView.episode_view_procentage - private val episodeViewPercentageOff: View = itemView.episode_view_procentage_off + 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 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 + + // val episodeExtra: ImageView = itemView.episode_extra + // private val episodePlay: ImageView = itemView.episode_play private val episodeHolder = itemView.episode_holder + @SuppressLint("SetTextI18n") fun bind(card: ResultEpisode) { episodeText.text = card.name ?: "Episode ${card.episode}" @@ -76,8 +101,41 @@ class EpisodeAdapter( } val watchProgress = card.getWatchProgress() - setWidth(episodeViewPrecentage, watchProgress) - setWidth(episodeViewPercentageOff, 1 - watchProgress) + if (episodeViewPrecentage != null && episodeViewPercentageOff != null) { + setWidth(episodeViewPrecentage, watchProgress) + setWidth(episodeViewPercentageOff, 1 - watchProgress) + } + + 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) + activity.let { + Glide.with(it) + .load(glideUrl) + .into(episodePoster) + } + } + } else { + episodePoster?.visibility = View.GONE + } + + if (card.rating != null) { + episodeRating?.text = "%.1f".format(card.rating.toFloat() / 10f).replace(",", ".") + } else { + episodeRating?.text = "" + } + + if (card.descript != null) { + episodeDescript?.visibility = View.VISIBLE + episodeDescript?.text = card.descript + } else { + episodeDescript?.visibility = View.GONE + } episodeHolder.setOnClickListener { if (activity.isCastApiAvailable()) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index fd6bb98c..7a2bf721 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -64,6 +64,8 @@ data class ResultEpisode( val index: Int, val position: Long, // time in MS val duration: Long, // duration in MS + val rating: Int?, + val descript: String?, ) fun ResultEpisode.getRealPosition(): Long { @@ -91,9 +93,12 @@ fun Context.buildResultEpisode( apiName: String, id: Int, index: Int, + rating: Int?, + descript: String?, ): ResultEpisode { val posDur = getViewPos(id) - return ResultEpisode(name, + return ResultEpisode( + name, poster, episode, season, @@ -102,7 +107,10 @@ fun Context.buildResultEpisode( id, index, posDur?.position ?: 0, - posDur?.duration ?: 0) + posDur?.duration ?: 0, + rating, + descript, + ) } fun ResultEpisode.getWatchProgress(): Float { @@ -355,6 +363,7 @@ class ResultFragment : Fragment() { result_episodes_text.text = "${episodes.size} Episode${if (episodes.size == 1) "" else "s"}" currentEpisodes = episodes (result_episodes.adapter as EpisodeAdapter).cardList = episodes + (result_episodes.adapter as EpisodeAdapter).updateLayout() (result_episodes.adapter as EpisodeAdapter).notifyDataSetChanged() } @@ -400,7 +409,7 @@ class ResultFragment : Fragment() { if (d.year != null) metadataInfoArray.add(Pair("Year", d.year.toString())) val rating = d.rating if (rating != null) metadataInfoArray.add(Pair("Rating", - "%.2f/10.0".format(rating.toFloat() / 10f).replace(",", "."))) + "%.1f/10.0".format(rating.toFloat() / 10f).replace(",", "."))) val duration = d.duration if (duration != null) metadataInfoArray.add(Pair("Duration", duration)) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt index 5cd3f56f..3f2f8c2c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel.kt @@ -87,13 +87,15 @@ class ResultViewModel : ViewModel() { for ((index, i) in dataList.withIndex()) { episodes.add(context.buildResultEpisode( i.name, - null, + i.posterUrl, index + 1, //TODO MAKE ABLE TO NOT HAVE SOME EPISODE null, // TODO FIX SEASON i.url, apiName, (mainId + index + 1), index, + i.rating, + i.descript, )) } _episodes.postValue(episodes) @@ -106,13 +108,15 @@ class ResultViewModel : ViewModel() { episodes.add(context.buildResultEpisode( (i.name ?: (if (i.season != null && i.episode != null) "S${i.season}:E${i.episode}" else null)), // TODO ADD NAMES - null, + i.posterUrl, i.episode ?: (index + 1), i.season, i.data, apiName, (mainId + index + 1).hashCode(), index, + i.rating, + i.descript )) } _episodes.postValue(episodes) @@ -126,6 +130,8 @@ class ResultViewModel : ViewModel() { d.apiName, (mainId + 1), 0, + null, + null, ))) } } diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 83b2af96..4001aa7a 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -17,9 +17,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content" > - + - - + @@ -30,11 +33,12 @@ android:layout_height="match_parent" android:contentDescription="@string/episode_poster"> - + - - - - + + + - + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 45a2e76d..7927bef6 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -12,7 +12,7 @@ #2B2C30 #1C1C20 #1C1C20 - #17171B + #17171B #e9eaee #9ba0a4