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(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
horizontalArrangement = Arrangement.spacedBy(32.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.padding(8.dp),
|
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.data.model.Chapter
|
||||||
import com.github.damontecres.dolphin.preferences.UserPreferences
|
import com.github.damontecres.dolphin.preferences.UserPreferences
|
||||||
import com.github.damontecres.dolphin.ui.DefaultItemFields
|
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.ui.nav.Destination
|
||||||
import com.github.damontecres.dolphin.util.ApiRequestPager
|
import com.github.damontecres.dolphin.util.ApiRequestPager
|
||||||
import com.github.damontecres.dolphin.util.ExceptionHandler
|
import com.github.damontecres.dolphin.util.ExceptionHandler
|
||||||
|
|
@ -427,37 +428,35 @@ class PlaybackViewModel
|
||||||
|
|
||||||
fun getEpisodes(seriesId: UUID) {
|
fun getEpisodes(seriesId: UUID) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val episodes =
|
val request =
|
||||||
if (!this@PlaybackViewModel.episodes.isInitialized) {
|
GetEpisodesRequest(
|
||||||
val request =
|
seriesId = seriesId,
|
||||||
GetEpisodesRequest(seriesId = seriesId, fields = DefaultItemFields)
|
fields = DefaultItemFields,
|
||||||
val pager =
|
startItemId = itemId,
|
||||||
ApiRequestPager(api, request, GetEpisodesRequestHandler, viewModelScope)
|
limit = 2,
|
||||||
pager.init()
|
)
|
||||||
currentEpisodeIndex = pager.indexOfBlocking { it?.id == itemId }
|
val episodes = GetEpisodesRequestHandler.execute(api, request).content.items
|
||||||
pager
|
val currentEpisodeIndex = episodes.indexOfFirstOrNull { it.id == itemId }
|
||||||
} else {
|
|
||||||
this@PlaybackViewModel.episodes.value!!
|
|
||||||
}
|
|
||||||
Timber.v("Current episode is $currentEpisodeIndex of ${episodes.size}")
|
Timber.v("Current episode is $currentEpisodeIndex of ${episodes.size}")
|
||||||
val nextIndex = currentEpisodeIndex + 1
|
if (currentEpisodeIndex != null) {
|
||||||
if (nextIndex < episodes.size) {
|
val nextIndex = currentEpisodeIndex + 1
|
||||||
val listener =
|
if (nextIndex < episodes.size) {
|
||||||
object : Player.Listener {
|
val listener =
|
||||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
object : Player.Listener {
|
||||||
if (playbackState == Player.STATE_ENDED) {
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
if (playbackState == Player.STATE_ENDED) {
|
||||||
val nextItem = episodes.getBlocking(nextIndex)
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
Timber.v("Setting next up episode to ${nextItem?.id}")
|
val nextItem = BaseItem.from(episodes[nextIndex], api)
|
||||||
withContext(Dispatchers.Main) {
|
Timber.v("Setting next up episode to ${nextItem.id}")
|
||||||
nextUpEpisode.value = nextItem
|
withContext(Dispatchers.Main) {
|
||||||
|
nextUpEpisode.value = nextItem
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
player.removeListener(this)
|
||||||
}
|
}
|
||||||
player.removeListener(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
player.addListener(listener)
|
||||||
player.addListener(listener)
|
|
||||||
|
|
||||||
// viewModelScope.launch(Dispatchers.IO) {
|
// viewModelScope.launch(Dispatchers.IO) {
|
||||||
// while (this.isActive) {
|
// while (this.isActive) {
|
||||||
|
|
@ -476,6 +475,7 @@ class PlaybackViewModel
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue