From bab303ef9180ee311dc28cc990fbd9314ed3527c Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Wed, 23 Sep 2026 06:02:58 +0000 Subject: [PATCH] anchor the queue window at the playing track --- .../com/subtracks/ui/playback/QueueScreen.kt | 19 +++---------------- .../ui/playback/QueueViewModelTest.kt | 14 +++++++------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt b/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt index 85f09d2b..a9a6869a 100644 --- a/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt +++ b/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt @@ -35,7 +35,6 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow -import androidx.compose.runtime.withFrameNanos import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -102,7 +101,7 @@ class QueueViewModel( withTimeoutOrNull(POSITION_TIMEOUT_MS) { playbackController.state.first { it.position != null }.position }?.coerceIn(0, size - 1) ?: 0L - val start = (cursor - QUEUE_CHUNK / 2).coerceAtLeast(0) + val start = cursor val end = (start + QUEUE_CHUNK - 1).coerceAtMost(size - 1) rows.addAll(queueRepository.range(snapshot, start, end).map(::newRow)) first = rows.first().position @@ -289,17 +288,6 @@ fun QueueScreen( val scope = rememberCoroutineScope() var dragFrom by remember { mutableStateOf(null) } var dragTo by remember { mutableStateOf(null) } - var centered by remember { mutableStateOf(false) } - - LaunchedEffect(ready, rows.size, currentPosition) { - if (centered || !ready) return@LaunchedEffect - val position = currentPosition ?: return@LaunchedEffect - val index = rows.indexOfFirst { it.position == position } - if (index >= 0) { - listState.requestScrollToItem(index) - centered = true - } - } val reorderState = rememberReorderableLazyListState(listState) { from, to -> @@ -310,9 +298,8 @@ fun QueueScreen( dragTo = toPosition } - LaunchedEffect(listState, centered) { - if (!centered) return@LaunchedEffect - withFrameNanos { } + LaunchedEffect(listState, ready) { + if (!ready) return@LaunchedEffect snapshotFlow { val info = listState.layoutInfo val firstVisible = info.visibleItemsInfo.firstOrNull()?.index ?: -1 diff --git a/app/src/test/kotlin/com/subtracks/ui/playback/QueueViewModelTest.kt b/app/src/test/kotlin/com/subtracks/ui/playback/QueueViewModelTest.kt index 26171743..8debd903 100644 --- a/app/src/test/kotlin/com/subtracks/ui/playback/QueueViewModelTest.kt +++ b/app/src/test/kotlin/com/subtracks/ui/playback/QueueViewModelTest.kt @@ -63,7 +63,7 @@ class QueueViewModelTest { } @Test - fun openingLoadsAWindowAroundTheCursorAndExtendingGrowsIt() { + fun openingLoadsAWindowAtTheCursorAndExtendingGrowsIt() { runBlocking { seedSongs(200) } controller.playSongs(1, 100) await { controller.state.value.position == 100L } @@ -71,15 +71,15 @@ class QueueViewModelTest { viewModel.open() await { viewModel.ready } - assertEquals((70L..129L).toList(), viewModel.rows.map { it.position }) + assertEquals((100L..159L).toList(), viewModel.rows.map { it.position }) viewModel.loadNewer() - await { viewModel.rows.lastOrNull()?.position == 189L } - assertEquals((70L..189L).toList(), viewModel.rows.map { it.position }) + await { viewModel.rows.lastOrNull()?.position == 199L } + assertEquals((100L..199L).toList(), viewModel.rows.map { it.position }) viewModel.loadOlder() - await { viewModel.rows.firstOrNull()?.position == 10L } - assertEquals((10L..189L).toList(), viewModel.rows.map { it.position }) + await { viewModel.rows.firstOrNull()?.position == 40L } + assertEquals((40L..199L).toList(), viewModel.rows.map { it.position }) } @Test @@ -94,7 +94,7 @@ class QueueViewModelTest { viewModel.reorder(fromIndex = 0, toIndex = 2) val positions = viewModel.rows.map { it.position } - assertEquals(listOf(71L, 72L, 70L), positions.take(3)) + assertEquals(listOf(101L, 102L, 100L), positions.take(3)) } private suspend fun seedSongs(count: Int) {