From a2e63174be95489af7b6ce4ba7c93e6bad6026a0 Mon Sep 17 00:00:00 2001 From: KingLucius Date: Tue, 19 Mar 2024 17:47:36 +0200 Subject: [PATCH] Set play button to first unwatched episode on TV --- .../cloudstream3/ui/result/ResultFragmentTv.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt index 3263ee93..69f8e8aa 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt @@ -781,25 +781,28 @@ class ResultFragmentTv : Fragment() { // resultEpisodeLoading.isVisible = episodes is Resource.Loading if (episodes is Resource.Success) { - val first = episodes.value.firstOrNull() - if (first != null) { + + val lastWatchedIndex = episodes.value.indexOfLast { ep -> ep.videoWatchState == VideoWatchState.Watched } + val firstUnwatched = episodes.value.getOrElse(lastWatchedIndex + 1) { episodes.value.firstOrNull() } + + if (firstUnwatched != null) { resultPlaySeriesText.text = when { - first.season != null -> - "${getString(R.string.season_short)}${first.season}:${getString(R.string.episode_short)}${first.episode}" - else -> "${getString(R.string.episode)} ${first.episode}" + firstUnwatched.season != null -> + "${getString(R.string.season_short)}${firstUnwatched.season}:${getString(R.string.episode_short)}${firstUnwatched.episode}" + else -> "${getString(R.string.episode)} ${firstUnwatched.episode}" } resultPlaySeriesButton.setOnClickListener { viewModel.handleAction( EpisodeClickEvent( ACTION_CLICK_DEFAULT, - first + firstUnwatched ) ) } resultPlaySeriesButton.setOnLongClickListener { viewModel.handleAction( - EpisodeClickEvent(ACTION_SHOW_OPTIONS, first) + EpisodeClickEvent(ACTION_SHOW_OPTIONS, firstUnwatched) ) return@setOnLongClickListener true }