UI changes to now playing nav drawer item

This commit is contained in:
Damontecres 2026-02-28 19:02:14 -05:00
parent dd7795e2fd
commit 6fa3f550b0
No known key found for this signature in database
5 changed files with 50 additions and 35 deletions

View file

@ -208,9 +208,10 @@ data class MusicServiceState(
val currentIndex: Int,
val currentItemId: UUID?,
val isPlaying: Boolean,
val currentItemTitle: String?,
) {
companion object {
val EMPTY = MusicServiceState(0, 0, null, false)
val EMPTY = MusicServiceState(0, 0, null, false, null)
}
}
@ -263,9 +264,12 @@ private class MusicPlayerListener(
state.update { state ->
player.currentMediaItemIndex.takeIf { it >= 0 }?.let { currentMediaItemIndex ->
if (currentMediaItemIndex in (0..<player.mediaItemCount)) {
val item =
player.getMediaItemAt(currentMediaItemIndex).localConfiguration?.tag as? AudioItem
state.copy(
currentIndex = currentMediaItemIndex,
currentItemId = player.getMediaItemAt(currentMediaItemIndex).mediaId.toUUIDOrNull(),
currentItemTitle = item?.title,
)
} else {
state

View file

@ -76,18 +76,24 @@ class NavDrawerService
_state.update { it.copy(discoverEnabled = discoverActive) }
}.launchIn(coroutineScope)
coroutineScope.launchDefault {
musicService.state.collectLatest {
musicService.state.collectLatest { music ->
Timber.v("MusicService updated")
if (it.isPlaying) {
if (music.isPlaying) {
_state.update {
it.copy(nowPlayingEnabled = true)
it.copy(
nowPlayingEnabled = true,
nowPlayingTitle = music.currentItemTitle,
)
}
} else {
// Don't immediately remove the now playing
// TODO need better now playing state to distinguish between paused & stopped
delay(30_000)
_state.update {
it.copy(nowPlayingEnabled = false)
it.copy(
nowPlayingEnabled = false,
nowPlayingTitle = null,
)
}
}
}
@ -203,9 +209,10 @@ data class NavDrawerItemState(
val moreItems: List<NavDrawerItem>,
val discoverEnabled: Boolean,
val nowPlayingEnabled: Boolean,
val nowPlayingTitle: String?,
) {
companion object {
val EMPTY = NavDrawerItemState(emptyList(), emptyList(), false, false)
val EMPTY = NavDrawerItemState(emptyList(), emptyList(), false, false, null)
}
}