From 97e165e8c2dbcdf83735c5fb2d601bdd4c940625 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sat, 14 Nov 2026 05:33:31 +0000 Subject: [PATCH] ui: preserve queue windows during reconciliation --- .../kotlin/com/subtracks/ui/playback/QueueScreen.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 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 e473d27a..67e6dfa5 100644 --- a/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt +++ b/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt @@ -180,12 +180,21 @@ class QueueViewModel( rows.clear() return } - val start = ((rows.minOfOrNull { it.position } ?: OLDER_LOAD.toLong()) - OLDER_LOAD.toLong()).coerceAtLeast(0) + val firstPosition = rows.minOfOrNull { it.position } ?: OLDER_LOAD.toLong() + val start = (firstPosition - OLDER_LOAD).coerceAtLeast(0) val rawEnd = (rows.maxOfOrNull { it.position } ?: (start + QUEUE_CHUNK - 1)).coerceIn(start, snapshot.size - 1) val end = rawEnd.coerceAtMost(start + MAX_SCAN_POSITIONS - 1) val loaded = queueRepository.range(snapshot, start, end).filter(::visible) val reused = reusedIds() - val updated = loaded.map { rowFor(it, reused, snapshot.resetVersion) } + val scanned = loaded.map { rowFor(it, reused, snapshot.resetVersion) } + val firstRow = rows.minByOrNull { it.position } + val windowStart = + if (firstRow == null) { + start + } else { + scanned.firstOrNull { it.id == firstRow.id && it.position < firstPosition }?.position ?: firstPosition + } + val updated = scanned.filter { it.position >= windowStart } if (end >= rawEnd) { if (updated.size == rows.size) { updated.forEachIndexed { index, row -> if (rows[index] != row) rows[index] = row }