mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
UI changes to now playing nav drawer item
This commit is contained in:
parent
dd7795e2fd
commit
6fa3f550b0
5 changed files with 50 additions and 35 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue