Part 2 update for named seasons

This commit is contained in:
Blatzar 2022-09-12 16:00:27 +02:00
parent 6f60298fc9
commit e830595c5f
2 changed files with 39 additions and 23 deletions

View file

@ -1118,6 +1118,11 @@ data class NextAiring(
val unixTime: Long, val unixTime: Long,
) )
/**
* @param season To be mapped with episode season, not shown in UI if displaySeason is defined
* @param name To be shown next to the season like "Season $displaySeason $name" but if displaySeason is null then "$name"
* @param displaySeason What to be displayed next to the season name, if null then the name is the only thing shown.
* */
data class SeasonData( data class SeasonData(
val season: Int, val season: Int,
val name: String? = null, val name: String? = null,

View file

@ -1483,15 +1483,20 @@ class ResultViewModel2 : ViewModel() {
0 -> txt(R.string.no_season) 0 -> txt(R.string.no_season)
else -> { else -> {
val seasonNames = (currentResponse as? EpisodeResponse)?.seasonNames val seasonNames = (currentResponse as? EpisodeResponse)?.seasonNames
val seasonData = val seasonData = seasonNames.getSeason(indexer.season)
seasonNames.getSeason(indexer.season)
val suffix = seasonData?.name?.let { " $it" } ?: "" // If displaySeason is null then only show the name!
txt( if (seasonData?.name != null && seasonData.displaySeason == null) {
R.string.season_format, txt(seasonData.name)
txt(R.string.season), } else {
seasonData?.displaySeason ?: indexer.season, val suffix = seasonData?.name?.let { " $it" } ?: ""
suffix txt(
) R.string.season_format,
txt(R.string.season),
seasonData?.displaySeason ?: indexer.season,
suffix
)
}
} }
} }
) )
@ -1598,7 +1603,7 @@ class ResultViewModel2 : ViewModel() {
i.posterUrl, i.posterUrl,
episode, episode,
null, null,
seasonData?.displaySeason ?: i.season, if (seasonData != null) seasonData.displaySeason else i.season,
i.data, i.data,
loadResponse.apiName, loadResponse.apiName,
id, id,
@ -1633,7 +1638,7 @@ class ResultViewModel2 : ViewModel() {
if (!existingEpisodes.contains(id)) { if (!existingEpisodes.contains(id)) {
existingEpisodes.add(id) existingEpisodes.add(id)
val seasonIndex = episode.season?.minus(1) val seasonIndex = episode.season?.minus(1)
val currentSeason = val seasonData =
loadResponse.seasonNames.getSeason(episode.season) loadResponse.seasonNames.getSeason(episode.season)
val ep = val ep =
@ -1643,7 +1648,7 @@ class ResultViewModel2 : ViewModel() {
episode.posterUrl, episode.posterUrl,
episodeIndex, episodeIndex,
seasonIndex, seasonIndex,
currentSeason?.displaySeason ?: episode.season, if (seasonData != null) seasonData.displaySeason else episode.season,
episode.data, episode.data,
loadResponse.apiName, loadResponse.apiName,
id, id,
@ -1747,16 +1752,17 @@ class ResultViewModel2 : ViewModel() {
val seasonData = loadResponse.seasonNames.getSeason(seasonNumber) val seasonData = loadResponse.seasonNames.getSeason(seasonNumber)
val fixedSeasonNumber = seasonData?.displaySeason ?: seasonNumber val fixedSeasonNumber = seasonData?.displaySeason ?: seasonNumber
val suffix = seasonData?.name?.let { " $it" } ?: "" val suffix = seasonData?.name?.let { " $it" } ?: ""
// If displaySeason is null then only show the name!
val name = val name = if (seasonData?.name != null && seasonData.displaySeason == null) {
/*loadResponse.seasonNames?.firstOrNull { it.season == seasonNumber }?.name?.let { seasonData -> txt(seasonData.name)
txt(seasonData) } else {
} ?:*/txt( txt(
R.string.season_format, R.string.season_format,
txt(R.string.season), txt(R.string.season),
fixedSeasonNumber, fixedSeasonNumber,
suffix suffix
) )
}
name to seasonNumber name to seasonNumber
}) })
} }
@ -1812,7 +1818,12 @@ class ResultViewModel2 : ViewModel() {
} }
private fun loadTrailers(loadResponse: LoadResponse) = ioSafe { private fun loadTrailers(loadResponse: LoadResponse) = ioSafe {
_trailers.postValue(getTrailers(loadResponse, 3)) // we dont want to fetch too many trailers _trailers.postValue(
getTrailers(
loadResponse,
3
)
) // we dont want to fetch too many trailers
} }
private suspend fun getTrailers( private suspend fun getTrailers(