playback: fix more state restore issues

They just keep coming. I hate how complicated this system is.
This commit is contained in:
Alexander Capehart 2024-02-28 22:58:35 -07:00
parent 2f36fcfb45
commit 2a0624f860
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 9 additions and 7 deletions

View file

@ -470,8 +470,9 @@ constructor(
ack?.let { playbackManager.ack(this, it) }
}
override fun reset() {
override fun reset(ack: StateAck.NewPlayback) {
player.setMediaItems(emptyList())
playbackManager.ack(this, ack)
}
// --- PLAYER OVERRIDES ---

View file

@ -155,7 +155,7 @@ interface PlaybackStateHolder {
fun applySavedState(parent: MusicParent?, rawQueue: RawQueue, ack: StateAck.NewPlayback?)
/** Reset this instance to an empty state. */
fun reset()
fun reset(ack: StateAck.NewPlayback)
}
/**

View file

@ -743,19 +743,20 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
}
// Make sure we re-align the index to point to the previously playing song.
fun pointingAtSong(): Boolean {
fun pointingAtSong(index: Int): Boolean {
val currentSong =
if (shuffledMapping.isNotEmpty()) {
shuffledMapping.getOrNull(savedState.index)?.let { heap.getOrNull(it) }
shuffledMapping.getOrNull(index)?.let { heap.getOrNull(it) }
} else {
heap.getOrNull(savedState.index)
heap.getOrNull(index)
}
logD(currentSong)
return currentSong?.uid == savedState.songUid
}
var index = savedState.index
while (!pointingAtSong() && index > -1) {
while (!pointingAtSong(index) && index > -1) {
index--
}
@ -766,7 +767,7 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
}
if (index < 0) {
stateHolder.reset()
stateHolder.reset(StateAck.NewPlayback)
return
}