Skip to content

Commit 876ce09

Browse files
authored
Fix: Show the correct season names in episode list in the player
1 parent 2687613 commit 876ce09

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed

app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import com.lagradost.cloudstream3.ui.result.EpisodeAdapter
8686
import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
8787
import com.lagradost.cloudstream3.ui.result.ResultEpisode
8888
import com.lagradost.cloudstream3.ui.result.ResultFragment
89+
import com.lagradost.cloudstream3.ui.result.ResultViewModel2
8990
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
9091
import com.lagradost.cloudstream3.ui.result.SyncViewModel
9192
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
@@ -1857,6 +1858,7 @@ class GeneratorPlayer : FullScreenPlayer() {
18571858
" - "
18581859
}
18591860
}$extra"
1861+
18601862
4 -> headerName
18611863
5 -> "$headerName${
18621864
if (headerName.isBlank()) {
@@ -1865,6 +1867,7 @@ class GeneratorPlayer : FullScreenPlayer() {
18651867
" - "
18661868
}
18671869
}$extra"
1870+
18681871
else -> ""
18691872
}
18701873
playerBinding?.playerVideoTitleRez?.apply {
@@ -2038,11 +2041,15 @@ class GeneratorPlayer : FullScreenPlayer() {
20382041
val topIndex = layoutManager.findFirstCompletelyVisibleItemPosition()
20392042
if (topIndex != RecyclerView.NO_POSITION && topIndex != lastTopIndex) {
20402043
lastTopIndex = topIndex
2041-
val topItem = episodes.getOrNull(topIndex)?.season
2044+
val topItem = episodes.getOrNull(topIndex)
2045+
20422046
topItem?.let {
2043-
val paddedSeasonString = String.format("%02d", topItem)
2044-
playerEpisodeOverlayTitle.text =
2045-
"${context?.getString(R.string.episodes)}:${context?.getString(R.string.season_short)}${paddedSeasonString}"
2047+
playerEpisodeOverlayTitle.setText(
2048+
ResultViewModel2.seasonToTxt(
2049+
topItem.seasonData,
2050+
topItem.seasonIndex
2051+
)
2052+
)
20462053
}
20472054
}
20482055
}

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.lagradost.cloudstream3.DubStatus
77
import com.lagradost.cloudstream3.R
88
import com.lagradost.cloudstream3.Score
99
import com.lagradost.cloudstream3.SearchResponse
10+
import com.lagradost.cloudstream3.SeasonData
1011
import com.lagradost.cloudstream3.TvType
1112
import com.lagradost.cloudstream3.ui.result.EpisodeAdapter.Companion.getPlayerAction
1213
import com.lagradost.cloudstream3.utils.AppContextUtils.getApiDubstatusSettings
@@ -53,6 +54,7 @@ data class ResultEpisode(
5354
val totalEpisodeIndex: Int? = null,
5455
val airDate: Long? = null,
5556
val runTime: Int? = null,
57+
val seasonData: SeasonData? = null,
5658
)
5759

5860
fun ResultEpisode.getRealPosition(): Long {
@@ -90,31 +92,33 @@ fun buildResultEpisode(
9092
totalEpisodeIndex: Int? = null,
9193
airDate: Long? = null,
9294
runTime: Int? = null,
95+
seasonData: SeasonData? = null,
9396
): ResultEpisode {
9497
val posDur = getViewPos(id)
9598
val videoWatchState = getVideoWatchState(id) ?: VideoWatchState.None
9699
return ResultEpisode(
97-
headerName,
98-
name,
99-
poster,
100-
episode,
101-
seasonIndex,
102-
season,
103-
data,
104-
apiName,
105-
id,
106-
index,
107-
posDur?.position ?: 0,
108-
posDur?.duration ?: 0,
109-
rating,
110-
description,
111-
isFiller,
112-
tvType,
113-
parentId,
114-
videoWatchState,
115-
totalEpisodeIndex,
116-
airDate,
117-
runTime,
100+
headerName = headerName,
101+
name = name,
102+
poster = poster,
103+
episode = episode,
104+
seasonIndex = seasonIndex,
105+
season = season,
106+
data = data,
107+
apiName = apiName,
108+
id = id,
109+
index = index,
110+
position = posDur?.position ?: 0,
111+
duration = posDur?.duration ?: 0,
112+
score = rating,
113+
description = description,
114+
isFiller = isFiller,
115+
tvType = tvType,
116+
parentId = parentId,
117+
videoWatchState = videoWatchState,
118+
totalEpisodeIndex = totalEpisodeIndex,
119+
airDate = airDate,
120+
runTime = runTime,
121+
seasonData = seasonData
118122
)
119123
}
120124

@@ -158,7 +162,7 @@ object ResultFragment {
158162
fun newInstance(
159163
url: String,
160164
apiName: String,
161-
name : String,
165+
name: String,
162166
startAction: Int = 0,
163167
startValue: Int = 0
164168
): Bundle {
@@ -173,9 +177,10 @@ object ResultFragment {
173177
}
174178

175179
fun updateUI(id: Int? = null) {
176-
// updateUIListener?.invoke()
180+
// updateUIListener?.invoke()
177181
updateUIEvent.invoke(id)
178182
}
183+
179184
val updateUIEvent = Event<Int?>()
180185

181186
//private var updateUIListener: (() -> Unit)? = null
@@ -223,12 +228,12 @@ object ResultFragment {
223228
data class StoredData(
224229
val url: String,
225230
val apiName: String,
226-
val name : String,
231+
val name: String,
227232
val showFillers: Boolean,
228233
val dubStatus: DubStatus,
229234
val start: AutoResume?,
230235
val playerAction: Int,
231-
val restart : Boolean,
236+
val restart: Boolean,
232237
)
233238

234239
fun Fragment.getStoredData(): StoredData? {

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,11 @@ class ResultViewModel2 : ViewModel() {
524524
return this?.firstOrNull { it.season == season }
525525
}
526526

527-
private fun List<SeasonData>?.getSeasonTxt(season: Int?): UiText? {
527+
fun seasonToTxt(seasonData: SeasonData?, season: Int?): UiText? {
528528
if (season == 0) {
529529
return txt(R.string.no_season)
530530
}
531531

532-
val seasonData = getSeason(season)
533532
// If displaySeason is null then only show the name!
534533
return if (seasonData?.name != null && seasonData.displaySeason == null) {
535534
txt(seasonData.name)
@@ -544,6 +543,10 @@ class ResultViewModel2 : ViewModel() {
544543
}
545544
}
546545

546+
private fun List<SeasonData>?.getSeasonTxt(season: Int?): UiText? =
547+
seasonToTxt(getSeason(season), season)
548+
549+
547550
private fun filterName(name: String?): String? {
548551
if (name == null) return null
549552
Regex("^[eE]pisode [0-9]*(.*)").find(name)?.groupValues?.get(1)?.let {
@@ -2340,7 +2343,7 @@ class ResultViewModel2 : ViewModel() {
23402343
filterName(i.name),
23412344
i.posterUrl,
23422345
episode,
2343-
seasonData?.season ?: i.season,
2346+
i.season,
23442347
if (seasonData != null) seasonData.displaySeason else i.season,
23452348
i.data,
23462349
loadResponse.apiName,
@@ -2354,6 +2357,7 @@ class ResultViewModel2 : ViewModel() {
23542357
totalIndex,
23552358
airDate = i.date,
23562359
runTime = i.runTime,
2360+
seasonData = seasonData,
23572361
)
23582362

23592363
val season = eps.seasonIndex ?: 0
@@ -2396,7 +2400,7 @@ class ResultViewModel2 : ViewModel() {
23962400
filterName(episode.name),
23972401
episode.posterUrl,
23982402
episodeIndex,
2399-
seasonData?.season ?: episode.season,
2403+
episode.season,
24002404
if (seasonData != null) seasonData.displaySeason else episode.season,
24012405
episode.data,
24022406
loadResponse.apiName,
@@ -2410,6 +2414,7 @@ class ResultViewModel2 : ViewModel() {
24102414
totalIndex,
24112415
airDate = episode.date,
24122416
runTime = episode.runTime,
2417+
seasonData = seasonData,
24132418
)
24142419

24152420
val season = ep.seasonIndex ?: 0

0 commit comments

Comments
 (0)