Browse Source

update playheads on season change

updated playheads are needed for the "completed ep" indicator
develop
Jannik 3 months ago
parent
commit
1af82f8370
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 37
      app/src/main/java/org/mosad/teapod/ui/activity/main/viewmodel/MediaFragmentViewModel.kt

37
app/src/main/java/org/mosad/teapod/ui/activity/main/viewmodel/MediaFragmentViewModel.kt

@ -8,7 +8,6 @@ import kotlinx.coroutines.launch
import org.mosad.teapod.parser.crunchyroll.*
import org.mosad.teapod.preferences.Preferences
import org.mosad.teapod.util.DataTypes.MediaType
import org.mosad.teapod.util.metadb.Meta
import org.mosad.teapod.util.tmdb.*
/**
@ -42,8 +41,6 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
internal set
var tmdbTVSeason: TMDBTVSeason = NoneTMDBTVSeason
internal set
var mediaMeta: Meta? = null
internal set
/**
* @param crunchyId the crunchyroll series id
@ -57,20 +54,14 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
viewModelScope.launch { isWatchlist = Crunchyroll.isWatchlist(crunchyId) },
viewModelScope.launch { upNextSeries = Crunchyroll.upNextSeries(crunchyId) }
).joinAll()
// println("series: $seriesCrunchy")
// println("seasons: $seasonsCrunchy")
// println(upNextSeries)
// load the preferred season (preferred language, language per season, not per stream)
currentSeasonCrunchy = seasonsCrunchy.getPreferredSeason(Preferences.preferredLocale)
// load episodes and metaDB in parallel (tmdb needs mediaType, which is set via episodes)
listOf(
viewModelScope.launch { episodesCrunchy = Crunchyroll.episodes(currentSeasonCrunchy.id) },
viewModelScope.launch { mediaMeta = null }, // TODO metaDB
).joinAll()
// println("episodes: $episodesCrunchy")
// Note: if we need to query metaDB, do it now
// load episodes and metaDB in parallel (tmdb needs mediaType, which is set via episodes)
viewModelScope.launch { episodesCrunchy = Crunchyroll.episodes(currentSeasonCrunchy.id) }.join()
currentEpisodesCrunchy.clear()
currentEpisodesCrunchy.addAll(episodesCrunchy.items)
@ -103,7 +94,7 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
MediaType.TVSHOW -> tmdbApiController.searchTVShow(seriesCrunchy.title)
else -> NoneTMDBSearch
}
println(tmdbSearchResult)
// println(tmdbSearchResult)
tmdbResult = if (tmdbSearchResult.results.isNotEmpty()) {
when (val result = tmdbSearchResult.results.first()) {
@ -112,8 +103,7 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
else -> NoneTMDB
}
} else NoneTMDB
println(tmdbResult)
// println(tmdbResult)
// currently not used
// tmdbTVSeason = if (tmdbResult is TMDBTVShow) {
@ -139,6 +129,11 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
episodesCrunchy = Crunchyroll.episodes(currentSeasonCrunchy.id)
currentEpisodesCrunchy.clear()
currentEpisodesCrunchy.addAll(episodesCrunchy.items)
// update playheads playheads (including fully watched state)
val episodeIDs = episodesCrunchy.items.map { it.id }
currentPlayheads.clear()
currentPlayheads.putAll(Crunchyroll.playheads(episodeIDs))
}
suspend fun setWatchlist() {
@ -162,16 +157,4 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
)
}
/**
* get the next episode based on episodeId
* if no matching is found, use first episode
*/
fun updateNextEpisode(episodeId: Int) {
// TODO reimplement if needed
// if (media.type == MediaType.MOVIE) return // return if movie
//
// nextEpisodeId = media.playlist.firstOrNull { it.index > media.getEpisodeById(episodeId).index }?.mediaId
// ?: media.playlist.first().mediaId
}
}

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close