mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-15 00:42:54 +01:00
ui: preserve pending older queue loads
This commit is contained in:
@@ -120,6 +120,7 @@ class QueueViewModel(
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
private var reorderPending = false
|
private var reorderPending = false
|
||||||
|
private var olderLoadPending = false
|
||||||
private var dragRollback: ReorderRollback? = null
|
private var dragRollback: ReorderRollback? = null
|
||||||
|
|
||||||
private var nextId = 0L
|
private var nextId = 0L
|
||||||
@@ -189,7 +190,7 @@ class QueueViewModel(
|
|||||||
val scanned = loaded.map { rowFor(it, reused, snapshot.resetVersion) }
|
val scanned = loaded.map { rowFor(it, reused, snapshot.resetVersion) }
|
||||||
val firstRow = rows.minByOrNull { it.position }
|
val firstRow = rows.minByOrNull { it.position }
|
||||||
val windowStart =
|
val windowStart =
|
||||||
if (firstRow == null) {
|
if (firstRow == null || olderLoadPending) {
|
||||||
start
|
start
|
||||||
} else {
|
} else {
|
||||||
scanned.firstOrNull { it.id == firstRow.id && it.position < firstPosition }?.position ?: firstPosition
|
scanned.firstOrNull { it.id == firstRow.id && it.position < firstPosition }?.position ?: firstPosition
|
||||||
@@ -214,7 +215,9 @@ class QueueViewModel(
|
|||||||
fun loadOlder() {
|
fun loadOlder() {
|
||||||
val top = rows.minOfOrNull { it.position } ?: return
|
val top = rows.minOfOrNull { it.position } ?: return
|
||||||
if (top <= 0L) return
|
if (top <= 0L) return
|
||||||
|
olderLoadPending = true
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
val first = rows.minOfOrNull { it.position } ?: return@withLock
|
val first = rows.minOfOrNull { it.position } ?: return@withLock
|
||||||
if (first <= 0L) return@withLock
|
if (first <= 0L) return@withLock
|
||||||
@@ -230,6 +233,9 @@ class QueueViewModel(
|
|||||||
rows.addAll(0, collected.map { newRow(it, snapshot.resetVersion) })
|
rows.addAll(0, collected.map { newRow(it, snapshot.resetVersion) })
|
||||||
while (rows.size > QUEUE_WINDOW_ROWS) rows.removeAt(rows.size - 1)
|
while (rows.size > QUEUE_WINDOW_ROWS) rows.removeAt(rows.size - 1)
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
olderLoadPending = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user