mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Basic show/hide now playing nav drawer item
This commit is contained in:
parent
cd06c0380e
commit
1d47220991
4 changed files with 82 additions and 17 deletions
|
|
@ -179,7 +179,7 @@ private class MusicPlayerListener(
|
|||
Timber.v("MusicPlayerListener init")
|
||||
state.update {
|
||||
it.copy(
|
||||
queue = PlayerMediaItemList(player),
|
||||
queue = PlayerMediaItemList(player, player.mediaItemCount),
|
||||
currentIndex = player.currentMediaItemIndex,
|
||||
isPlaying = player.isPlaying,
|
||||
)
|
||||
|
|
@ -215,7 +215,7 @@ private class MusicPlayerListener(
|
|||
if (reason == Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED) {
|
||||
state.update {
|
||||
it.copy(
|
||||
queue = PlayerMediaItemList(player),
|
||||
queue = PlayerMediaItemList(player, player.mediaItemCount),
|
||||
currentIndex = player.currentMediaItemIndex,
|
||||
)
|
||||
}
|
||||
|
|
@ -225,15 +225,28 @@ private class MusicPlayerListener(
|
|||
|
||||
private class PlayerMediaItemList(
|
||||
private val player: Player,
|
||||
override val size: Int,
|
||||
) : AbstractList<AudioItem>() {
|
||||
override fun get(index: Int): AudioItem {
|
||||
// Timber.v("get %s", index)
|
||||
return player.getMediaItemAt(index).localConfiguration?.tag as AudioItem
|
||||
}
|
||||
|
||||
override val size: Int
|
||||
get() {
|
||||
// Timber.v("size %s", player.mediaItemCount)
|
||||
return player.mediaItemCount
|
||||
}
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is PlayerMediaItemList) return false
|
||||
if (!super.equals(other)) return false
|
||||
|
||||
if (size != other.size) return false
|
||||
if (player != other.player) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = super.hashCode()
|
||||
result = 31 * result + size
|
||||
result = 31 * result + player.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.github.damontecres.wholphin.data.ServerRepository
|
|||
import com.github.damontecres.wholphin.data.model.JellyfinUser
|
||||
import com.github.damontecres.wholphin.data.model.NavPinType
|
||||
import com.github.damontecres.wholphin.services.hilt.DefaultCoroutineScope
|
||||
import com.github.damontecres.wholphin.ui.launchDefault
|
||||
import com.github.damontecres.wholphin.ui.main.settings.Library
|
||||
import com.github.damontecres.wholphin.ui.nav.Destination
|
||||
import com.github.damontecres.wholphin.ui.nav.NavDrawerItem
|
||||
|
|
@ -14,8 +15,10 @@ import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem
|
|||
import com.github.damontecres.wholphin.util.supportedCollectionTypes
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
|
@ -40,6 +43,7 @@ class NavDrawerService
|
|||
private val serverRepository: ServerRepository,
|
||||
private val serverPreferencesDao: ServerPreferencesDao,
|
||||
private val seerrServerRepository: SeerrServerRepository,
|
||||
private val musicService: MusicService,
|
||||
) {
|
||||
private val _state = MutableStateFlow(NavDrawerItemState.EMPTY)
|
||||
val state: StateFlow<NavDrawerItemState> = _state
|
||||
|
|
@ -65,6 +69,23 @@ class NavDrawerService
|
|||
.onEach { discoverActive ->
|
||||
_state.update { it.copy(discoverEnabled = discoverActive) }
|
||||
}.launchIn(coroutineScope)
|
||||
coroutineScope.launchDefault {
|
||||
musicService.state.collectLatest {
|
||||
Timber.v("MusicService updated")
|
||||
if (it.isPlaying) {
|
||||
_state.update {
|
||||
it.copy(nowPlayingEnabled = true)
|
||||
}
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getAllUserLibraries(
|
||||
|
|
@ -175,9 +196,10 @@ data class NavDrawerItemState(
|
|||
val items: List<NavDrawerItem>,
|
||||
val moreItems: List<NavDrawerItem>,
|
||||
val discoverEnabled: Boolean,
|
||||
val nowPlayingEnabled: Boolean,
|
||||
) {
|
||||
companion object {
|
||||
val EMPTY = NavDrawerItemState(emptyList(), emptyList(), false)
|
||||
val EMPTY = NavDrawerItemState(emptyList(), emptyList(), false, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue