mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-12 23:56:33 +01:00
playback: turn off shuffle when a song is tapped
This commit is contained in:
@@ -106,7 +106,6 @@ private data class ReloadUndo(
|
||||
private data class PendingPlay(
|
||||
val entries: List<QueueEntry>,
|
||||
val position: Long,
|
||||
val disableShuffle: Boolean,
|
||||
)
|
||||
|
||||
class PlaybackController(
|
||||
@@ -191,7 +190,7 @@ class PlaybackController(
|
||||
val shuffle = pendingShuffle
|
||||
pendingShuffle = null
|
||||
when {
|
||||
pending != null -> start(pending.entries, pending.position, pending.disableShuffle)
|
||||
pending != null -> start(pending.entries, pending.position)
|
||||
shuffle != null -> startShuffled(shuffle)
|
||||
else -> restore()
|
||||
}
|
||||
@@ -240,16 +239,6 @@ class PlaybackController(
|
||||
startOrdinal: Long,
|
||||
) = playContext(queueRepository.starredEntry(sourceId), startOrdinal)
|
||||
|
||||
fun playAlbumInOrder(
|
||||
sourceId: Long,
|
||||
albumId: String,
|
||||
) = playContext(queueRepository.albumEntry(sourceId, albumId), 0, disableShuffle = true)
|
||||
|
||||
fun playPlaylistInOrder(
|
||||
sourceId: Long,
|
||||
playlistId: String,
|
||||
) = playContext(queueRepository.playlistEntry(sourceId, playlistId), 0, disableShuffle = true)
|
||||
|
||||
fun shuffleAlbum(
|
||||
sourceId: Long,
|
||||
albumId: String,
|
||||
@@ -277,8 +266,7 @@ class PlaybackController(
|
||||
private fun playContext(
|
||||
entry: QueueEntry,
|
||||
start: Long,
|
||||
disableShuffle: Boolean = false,
|
||||
) = play(listOf(entry), start, disableShuffle)
|
||||
) = play(listOf(entry), start)
|
||||
|
||||
private fun shuffleContext(entry: QueueEntry) = shufflePlay(listOf(entry))
|
||||
|
||||
@@ -982,20 +970,18 @@ class PlaybackController(
|
||||
private fun play(
|
||||
entries: List<QueueEntry>,
|
||||
startPosition: Long,
|
||||
disableShuffle: Boolean = false,
|
||||
) {
|
||||
if (player == null) {
|
||||
pendingPlay = PendingPlay(entries, startPosition, disableShuffle)
|
||||
pendingPlay = PendingPlay(entries, startPosition)
|
||||
connect()
|
||||
return
|
||||
}
|
||||
scope.launch { start(entries, startPosition, disableShuffle) }
|
||||
scope.launch { start(entries, startPosition) }
|
||||
}
|
||||
|
||||
private suspend fun start(
|
||||
entries: List<QueueEntry>,
|
||||
startPosition: Long,
|
||||
disableShuffle: Boolean = false,
|
||||
) = startLock.withLock {
|
||||
windowJob?.cancel()
|
||||
windowStart = 0
|
||||
@@ -1003,7 +989,7 @@ class PlaybackController(
|
||||
lastEdit = null
|
||||
endedHandled = false
|
||||
val modes = queueRepository.modes()
|
||||
shuffleEnabled = !disableShuffle && modes.shuffle
|
||||
shuffleEnabled = false
|
||||
repeatMode = modes.repeat.toRepeatMode()
|
||||
player?.setRepeatOne(repeatMode == RepeatMode.One)
|
||||
queueRepository.replace(entries)
|
||||
@@ -1014,14 +1000,7 @@ class PlaybackController(
|
||||
stopLocked()
|
||||
return@withLock
|
||||
}
|
||||
val start = startPosition.coerceIn(0, snapshot.contextSize - 1)
|
||||
val position =
|
||||
if (shuffleEnabled) {
|
||||
queueRepository.setShuffle(pinnedSeed(snapshot.contextSize, start))
|
||||
0L
|
||||
} else {
|
||||
start
|
||||
}
|
||||
val position = startPosition.coerceIn(0, snapshot.contextSize - 1)
|
||||
queueRepository.setCursor(position)
|
||||
this.snapshot = readSnapshot()
|
||||
loadWindow(position, autoplay = true)
|
||||
|
||||
@@ -96,7 +96,7 @@ class AlbumDetailViewModel(
|
||||
|
||||
fun playAll() {
|
||||
viewModelScope.launch {
|
||||
playbackController.playAlbumInOrder(sourceId.first(), albumId)
|
||||
playbackController.playAlbum(sourceId.first(), albumId, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class PlaylistDetailViewModel(
|
||||
|
||||
fun playAll() {
|
||||
viewModelScope.launch {
|
||||
playbackController.playPlaylistInOrder(sourceId.first(), playlistId)
|
||||
playbackController.playPlaylist(sourceId.first(), playlistId, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2494,7 +2494,7 @@ class PlaybackControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tappingASongWhileShuffledPlaysThatSong() {
|
||||
fun tappingASongTurnsOffShuffleAndPlaysThatSong() {
|
||||
seedAlbum(5, sourceId = 1)
|
||||
|
||||
controller.playAlbum(1, "al1", 0)
|
||||
@@ -2509,12 +2509,14 @@ class PlaybackControllerTest {
|
||||
controller.playAlbum(1, "al1", 3)
|
||||
await {
|
||||
controller.state.value.item
|
||||
?.id == "s4"
|
||||
?.id == "s4" && !controller.state.value.shuffle
|
||||
}
|
||||
|
||||
assertEquals("s4", handle.currentItem?.id)
|
||||
val shuffled = runBlocking { queues.snapshot() }
|
||||
assertEquals("s4", runBlocking { queues.itemAt(shuffled, controller.state.value.position!!)?.song?.id })
|
||||
assertEquals(3L, controller.state.value.position)
|
||||
val snapshot = runBlocking { queues.snapshot() }
|
||||
assertFalse(snapshot.shuffled)
|
||||
assertEquals("s4", runBlocking { queues.itemAt(snapshot, controller.state.value.position!!)?.song?.id })
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2730,24 +2732,6 @@ class PlaybackControllerTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun playInOrderTurnsOffShuffle() {
|
||||
seedAlbum(3, sourceId = 1)
|
||||
|
||||
controller.shuffleAlbum(1, "al1")
|
||||
await { controller.state.value.shuffle }
|
||||
|
||||
controller.playAlbumInOrder(1, "al1")
|
||||
await { !controller.state.value.shuffle }
|
||||
|
||||
assertEquals(
|
||||
"s1",
|
||||
controller.state.value.item
|
||||
?.id,
|
||||
)
|
||||
assertEquals(0L, controller.state.value.position)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shufflePlayOnASingleTrackAlbumPlaysIt() {
|
||||
seedAlbum(1, sourceId = 1)
|
||||
|
||||
Reference in New Issue
Block a user