Part 3 update for named seasons

This commit is contained in:
Blatzar 2022-09-12 17:22:48 +02:00
parent e830595c5f
commit 7f475ba059
2 changed files with 12 additions and 10 deletions

View file

@ -1203,9 +1203,12 @@ data class AnimeLoadResponse(
override var backgroundPosterUrl: String? = null, override var backgroundPosterUrl: String? = null,
) : LoadResponse, EpisodeResponse ) : LoadResponse, EpisodeResponse
/**
* If episodes already exist appends the list.
* */
fun AnimeLoadResponse.addEpisodes(status: DubStatus, episodes: List<Episode>?) { fun AnimeLoadResponse.addEpisodes(status: DubStatus, episodes: List<Episode>?) {
if (episodes.isNullOrEmpty()) return if (episodes.isNullOrEmpty()) return
this.episodes[status] = episodes this.episodes[status] = (this.episodes[status] ?: emptyList()) + episodes
} }
suspend fun MainAPI.newAnimeLoadResponse( suspend fun MainAPI.newAnimeLoadResponse(

View file

@ -1592,8 +1592,8 @@ class ResultViewModel2 : ViewModel() {
val idIndex = ep.key.id val idIndex = ep.key.id
for ((index, i) in ep.value.withIndex()) { for ((index, i) in ep.value.withIndex()) {
val episode = i.episode ?: (index + 1) val episode = i.episode ?: (index + 1)
val id = mainId + episode + idIndex * 1000000 val id = mainId + episode + idIndex * 1_000_000 + (i.season?.times(10_000) ?: 0)
if (!existingEpisodes.contains(episode)) { if (!existingEpisodes.contains(id)) {
existingEpisodes.add(id) existingEpisodes.add(id)
val seasonData = loadResponse.seasonNames.getSeason(i.season) val seasonData = loadResponse.seasonNames.getSeason(i.season)
val eps = val eps =
@ -1602,7 +1602,7 @@ class ResultViewModel2 : ViewModel() {
filterName(i.name), filterName(i.name),
i.posterUrl, i.posterUrl,
episode, episode,
null, seasonData?.season ?: i.season,
if (seasonData != null) seasonData.displaySeason else i.season, if (seasonData != null) seasonData.displaySeason else i.season,
i.data, i.data,
loadResponse.apiName, loadResponse.apiName,
@ -1615,7 +1615,7 @@ class ResultViewModel2 : ViewModel() {
mainId mainId
) )
val season = eps.season ?: 0 val season = eps.seasonIndex ?: 0
val indexer = EpisodeIndexer(ep.key, season) val indexer = EpisodeIndexer(ep.key, season)
episodes[indexer]?.add(eps) ?: run { episodes[indexer]?.add(eps) ?: run {
episodes[indexer] = mutableListOf(eps) episodes[indexer] = mutableListOf(eps)
@ -1630,14 +1630,13 @@ class ResultViewModel2 : ViewModel() {
mutableMapOf() mutableMapOf()
val existingEpisodes = HashSet<Int>() val existingEpisodes = HashSet<Int>()
for ((index, episode) in loadResponse.episodes.sortedBy { for ((index, episode) in loadResponse.episodes.sortedBy {
(it.season?.times(10000) ?: 0) + (it.episode ?: 0) (it.season?.times(10_000) ?: 0) + (it.episode ?: 0)
}.withIndex()) { }.withIndex()) {
val episodeIndex = episode.episode ?: (index + 1) val episodeIndex = episode.episode ?: (index + 1)
val id = val id =
mainId + (episode.season?.times(100000) ?: 0) + episodeIndex + 1 mainId + (episode.season?.times(100_000) ?: 0) + episodeIndex + 1
if (!existingEpisodes.contains(id)) { if (!existingEpisodes.contains(id)) {
existingEpisodes.add(id) existingEpisodes.add(id)
val seasonIndex = episode.season?.minus(1)
val seasonData = val seasonData =
loadResponse.seasonNames.getSeason(episode.season) loadResponse.seasonNames.getSeason(episode.season)
@ -1647,7 +1646,7 @@ class ResultViewModel2 : ViewModel() {
filterName(episode.name), filterName(episode.name),
episode.posterUrl, episode.posterUrl,
episodeIndex, episodeIndex,
seasonIndex, seasonData?.season ?: episode.season,
if (seasonData != null) seasonData.displaySeason else episode.season, if (seasonData != null) seasonData.displaySeason else episode.season,
episode.data, episode.data,
loadResponse.apiName, loadResponse.apiName,
@ -1660,7 +1659,7 @@ class ResultViewModel2 : ViewModel() {
mainId mainId
) )
val season = episode.season ?: 0 val season = ep.seasonIndex ?: 0
val indexer = EpisodeIndexer(DubStatus.None, season) val indexer = EpisodeIndexer(DubStatus.None, season)
episodes[indexer]?.add(ep) ?: kotlin.run { episodes[indexer]?.add(ep) ?: kotlin.run {