mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
address offline review: refresh, cursor, and cold-start fixes
This commit is contained in:
@@ -88,7 +88,7 @@ class SourceRepository(
|
||||
_quality.value = quality
|
||||
val sourceChanged = config?.id != activeSourceId
|
||||
activeSourceId = config?.id
|
||||
if (!_offline.value && sourceChanged && config != null && config.useTokenAuth) {
|
||||
if (sourceChanged && config != null && config.useTokenAuth && !prefs.offlineMode().first()) {
|
||||
scope.launch { runCatching { config.toClient().check("ping") } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +416,6 @@ class PlaybackController(
|
||||
if (offline) {
|
||||
queueRepository.setCursor(target)
|
||||
loadWindow(target, autoplay = playing, startPositionMs = 0)
|
||||
refresh(target)
|
||||
return@withLock
|
||||
}
|
||||
if (snapshot.upNextSize > 0L || updated.upNextSize > 0L || snapshot.shuffled) {
|
||||
@@ -509,7 +508,6 @@ class PlaybackController(
|
||||
if (offline) {
|
||||
queueRepository.setCursor(target)
|
||||
loadWindow(target, autoplay = player.playWhenReady, startPositionMs = player.currentPositionMs)
|
||||
refresh(target)
|
||||
return@withLock
|
||||
}
|
||||
when {
|
||||
@@ -564,9 +562,8 @@ class PlaybackController(
|
||||
val restoredId = queueRepository.itemAt(restored, target)?.song?.id
|
||||
windowJob?.cancel()
|
||||
if (offline) {
|
||||
loadWindow(target, autoplay = playing, startPositionMs = 0)
|
||||
queueRepository.setCursor(target)
|
||||
refresh(target)
|
||||
loadWindow(target, autoplay = playing, startPositionMs = 0)
|
||||
return@withLock
|
||||
}
|
||||
val canMirror =
|
||||
@@ -1054,6 +1051,10 @@ class PlaybackController(
|
||||
val snapshot = snapshot ?: return@withLock
|
||||
if (snapshot.size == 0L || player.isEnded) return@withLock
|
||||
downloads.awaitLoaded()
|
||||
if (offline) {
|
||||
reloadWindowLocked()
|
||||
return@withLock
|
||||
}
|
||||
val position = (currentPosition() ?: return@withLock).coerceIn(0, snapshot.size - 1)
|
||||
val window = queueRepository.window(snapshot, position, QUEUE_WINDOW_RADIUS)
|
||||
val uris = player.itemUris()
|
||||
|
||||
@@ -252,24 +252,9 @@ class QueueViewModel(
|
||||
fun undo() {
|
||||
viewModelScope.launch {
|
||||
playbackController.undo()
|
||||
mutex.withLock { reload() }
|
||||
mutex.withLock { reconcileLocked() }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun reload() {
|
||||
val snapshot = queueRepository.snapshot()
|
||||
if (snapshot.size == 0L) {
|
||||
rows.clear()
|
||||
return
|
||||
}
|
||||
val start = (rows.minOfOrNull { it.position } ?: 0L).coerceIn(0, snapshot.size - 1)
|
||||
val end = (rows.maxOfOrNull { it.position } ?: (start + QUEUE_CHUNK - 1)).coerceIn(start, snapshot.size - 1)
|
||||
val loaded = queueRepository.range(snapshot, start, end).filter(::visible)
|
||||
val reused = reusedIds()
|
||||
val updated = loaded.map { rowFor(it, reused) }
|
||||
rows.clear()
|
||||
rows.addAll(updated)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
Reference in New Issue
Block a user