mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
keep playback running when offline mode is toggled, and swap the recently-added header icon
This commit is contained in:
@@ -1321,8 +1321,7 @@ class PlaybackController(
|
|||||||
if (snapshot.size == 0L) return@withLock
|
if (snapshot.size == 0L) return@withLock
|
||||||
downloads.awaitLoaded()
|
downloads.awaitLoaded()
|
||||||
val current = currentPosition() ?: return@withLock
|
val current = currentPosition() ?: return@withLock
|
||||||
val positionMs = player.currentPositionMs
|
windowJob?.cancel()
|
||||||
val autoplay = player.playWhenReady
|
|
||||||
val target =
|
val target =
|
||||||
if (offline) {
|
if (offline) {
|
||||||
downloadedAtOrAfter(snapshot, current) ?: run {
|
downloadedAtOrAfter(snapshot, current) ?: run {
|
||||||
@@ -1332,9 +1331,15 @@ class PlaybackController(
|
|||||||
} else {
|
} else {
|
||||||
current
|
current
|
||||||
}
|
}
|
||||||
windowJob?.cancel()
|
|
||||||
queueRepository.setCursor(target)
|
queueRepository.setCursor(target)
|
||||||
loadWindow(target, autoplay = autoplay, startPositionMs = if (target == current) positionMs else 0)
|
if (target == current) {
|
||||||
|
// Keep the playing item in place and only add/remove its neighbours, so a downloaded
|
||||||
|
// track does not re-prepare (and audibly gap) when offline mode is toggled.
|
||||||
|
rebuildWindow(queueRepository.window(snapshot, target, QUEUE_WINDOW_RADIUS), target)
|
||||||
|
refresh(target)
|
||||||
|
} else {
|
||||||
|
loadWindow(target, autoplay = player.playWhenReady, startPositionMs = 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun movedCursor(
|
private fun movedCursor(
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ import androidx.compose.material.icons.rounded.CalendarMonth
|
|||||||
import androidx.compose.material.icons.rounded.Category
|
import androidx.compose.material.icons.rounded.Category
|
||||||
import androidx.compose.material.icons.rounded.Groups
|
import androidx.compose.material.icons.rounded.Groups
|
||||||
import androidx.compose.material.icons.rounded.History
|
import androidx.compose.material.icons.rounded.History
|
||||||
|
import androidx.compose.material.icons.rounded.LibraryAdd
|
||||||
import androidx.compose.material.icons.rounded.LocalFireDepartment
|
import androidx.compose.material.icons.rounded.LocalFireDepartment
|
||||||
import androidx.compose.material.icons.rounded.MusicNote
|
import androidx.compose.material.icons.rounded.MusicNote
|
||||||
import androidx.compose.material.icons.rounded.NewReleases
|
|
||||||
import androidx.compose.material.icons.rounded.Person
|
import androidx.compose.material.icons.rounded.Person
|
||||||
import androidx.compose.material.icons.rounded.Replay
|
import androidx.compose.material.icons.rounded.Replay
|
||||||
import androidx.compose.material.icons.rounded.Star
|
import androidx.compose.material.icons.rounded.Star
|
||||||
@@ -496,7 +496,7 @@ private val HomeSection.icon: ImageVector
|
|||||||
HomeSection.Genres -> Icons.Rounded.Category
|
HomeSection.Genres -> Icons.Rounded.Category
|
||||||
HomeSection.Decades -> Icons.Rounded.CalendarMonth
|
HomeSection.Decades -> Icons.Rounded.CalendarMonth
|
||||||
HomeSection.RecentlyStarredSongs -> Icons.Rounded.Star
|
HomeSection.RecentlyStarredSongs -> Icons.Rounded.Star
|
||||||
HomeSection.RecentlyAddedAlbums -> Icons.Rounded.NewReleases
|
HomeSection.RecentlyAddedAlbums -> Icons.Rounded.LibraryAdd
|
||||||
HomeSection.Rediscover -> Icons.Rounded.Replay
|
HomeSection.Rediscover -> Icons.Rounded.Replay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2535,7 +2535,8 @@ class PlaybackControllerTest {
|
|||||||
handle.operations.clear()
|
handle.operations.clear()
|
||||||
setOnline()
|
setOnline()
|
||||||
|
|
||||||
await { handle.operations.any { it.startsWith("setWindow") } }
|
await { handle.operations.any { it.startsWith("add") } }
|
||||||
|
assertFalse(handle.operations.any { it.startsWith("setWindow") })
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"s5",
|
"s5",
|
||||||
controller.state.value.item
|
controller.state.value.item
|
||||||
@@ -2801,7 +2802,8 @@ class PlaybackControllerTest {
|
|||||||
|
|
||||||
setOffline()
|
setOffline()
|
||||||
|
|
||||||
await { handle.operations.any { it.startsWith("setWindow") } }
|
await { handle.operations.any { it.startsWith("remove") || it.startsWith("add") } }
|
||||||
|
assertFalse(handle.operations.any { it.startsWith("setWindow") })
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"s2",
|
"s2",
|
||||||
controller.state.value.item
|
controller.state.value.item
|
||||||
|
|||||||
Reference in New Issue
Block a user