mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Simplify playback next up
This commit is contained in:
parent
34959a4e3c
commit
8ab092d2ca
2 changed files with 27 additions and 27 deletions
|
|
@ -72,7 +72,7 @@ fun NextUpEpisode(
|
|||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(32.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(8.dp),
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.github.damontecres.dolphin.data.model.BaseItem
|
|||
import com.github.damontecres.dolphin.data.model.Chapter
|
||||
import com.github.damontecres.dolphin.preferences.UserPreferences
|
||||
import com.github.damontecres.dolphin.ui.DefaultItemFields
|
||||
import com.github.damontecres.dolphin.ui.indexOfFirstOrNull
|
||||
import com.github.damontecres.dolphin.ui.nav.Destination
|
||||
import com.github.damontecres.dolphin.util.ApiRequestPager
|
||||
import com.github.damontecres.dolphin.util.ExceptionHandler
|
||||
|
|
@ -427,19 +428,17 @@ class PlaybackViewModel
|
|||
|
||||
fun getEpisodes(seriesId: UUID) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val episodes =
|
||||
if (!this@PlaybackViewModel.episodes.isInitialized) {
|
||||
val request =
|
||||
GetEpisodesRequest(seriesId = seriesId, fields = DefaultItemFields)
|
||||
val pager =
|
||||
ApiRequestPager(api, request, GetEpisodesRequestHandler, viewModelScope)
|
||||
pager.init()
|
||||
currentEpisodeIndex = pager.indexOfBlocking { it?.id == itemId }
|
||||
pager
|
||||
} else {
|
||||
this@PlaybackViewModel.episodes.value!!
|
||||
}
|
||||
GetEpisodesRequest(
|
||||
seriesId = seriesId,
|
||||
fields = DefaultItemFields,
|
||||
startItemId = itemId,
|
||||
limit = 2,
|
||||
)
|
||||
val episodes = GetEpisodesRequestHandler.execute(api, request).content.items
|
||||
val currentEpisodeIndex = episodes.indexOfFirstOrNull { it.id == itemId }
|
||||
Timber.v("Current episode is $currentEpisodeIndex of ${episodes.size}")
|
||||
if (currentEpisodeIndex != null) {
|
||||
val nextIndex = currentEpisodeIndex + 1
|
||||
if (nextIndex < episodes.size) {
|
||||
val listener =
|
||||
|
|
@ -447,8 +446,8 @@ class PlaybackViewModel
|
|||
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||
if (playbackState == Player.STATE_ENDED) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val nextItem = episodes.getBlocking(nextIndex)
|
||||
Timber.v("Setting next up episode to ${nextItem?.id}")
|
||||
val nextItem = BaseItem.from(episodes[nextIndex], api)
|
||||
Timber.v("Setting next up episode to ${nextItem.id}")
|
||||
withContext(Dispatchers.Main) {
|
||||
nextUpEpisode.value = nextItem
|
||||
}
|
||||
|
|
@ -479,6 +478,7 @@ class PlaybackViewModel
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun playUpNextEpisode() {
|
||||
nextUpEpisode.value?.let {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue