mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-14 23:20:25 +02:00
fix: distinguish preparing from downloading in native worker progress
Prevent premature 'downloading' status before actual byte transfer starts, and cache async provider values to avoid UI flicker during queue library reloads. Progress pipeline: - StartItemProgress now initializes with 'preparing' status instead of 'downloading' - SetItemProgress ignores synthetic pre-download progress updates while status is still 'preparing' (no byte data yet) - DownloadService reads backend status field and propagates preparing/ downloading/finalizing to native worker item snapshot - Dart progress stream maps 'preparing' to DownloadStatus.downloading with progress 0.0 (indeterminate spinner) Queue tab: - Add _queueLibraryCountsCache and _queueLibraryPageDataCache to retain last successful data during FutureProvider refetches - Prevents empty-state flash when loadedIndexVersion bumps trigger provider invalidation - Caches trimmed to max 24 entries via FIFO eviction
This commit is contained in:
@@ -564,12 +564,12 @@ class DownloadService : Service() {
|
||||
nativeWorkerCurrentItemId = request.itemId
|
||||
currentTrackName = request.trackName
|
||||
currentArtistName = request.artistName
|
||||
currentStatus = "downloading"
|
||||
currentStatus = "preparing"
|
||||
lastProgress = 0L
|
||||
lastTotal = 0L
|
||||
updateNotification(0, 0)
|
||||
updateNativeWorkerItem(request.itemId) {
|
||||
it.status = "downloading"
|
||||
it.status = "preparing"
|
||||
it.progress = 0.0
|
||||
it.bytesReceived = 0L
|
||||
it.bytesTotal = 0L
|
||||
@@ -580,7 +580,7 @@ class DownloadService : Service() {
|
||||
isRunning = true,
|
||||
isPaused = false,
|
||||
currentItemId = request.itemId,
|
||||
message = "Downloading",
|
||||
message = "Preparing",
|
||||
settingsJson = settingsJson,
|
||||
includeItems = true
|
||||
)
|
||||
@@ -1100,14 +1100,34 @@ class DownloadService : Service() {
|
||||
val root = JSONObject(raw)
|
||||
val items = root.optJSONObject("items") ?: return
|
||||
val progress = items.optJSONObject(itemId) ?: return
|
||||
val backendStatus = progress.optString("status", "downloading")
|
||||
val bytesReceived = progress.optLong("bytes_received", 0L)
|
||||
val bytesTotal = progress.optLong("bytes_total", 0L)
|
||||
if (backendStatus == "preparing") {
|
||||
currentStatus = "preparing"
|
||||
updateNativeWorkerItem(itemId) {
|
||||
it.status = "preparing"
|
||||
it.progress = 0.0
|
||||
it.bytesReceived = 0L
|
||||
it.bytesTotal = 0L
|
||||
}
|
||||
lastProgress = 0L
|
||||
lastTotal = 0L
|
||||
updateNotification(0L, 0L)
|
||||
return
|
||||
}
|
||||
val progressValue = if (bytesTotal > 0L) {
|
||||
bytesReceived.toDouble() / bytesTotal.toDouble()
|
||||
} else {
|
||||
progress.optDouble("progress", 0.0)
|
||||
}.coerceIn(0.0, 1.0)
|
||||
currentStatus = if (backendStatus == "finalizing") {
|
||||
"finalizing"
|
||||
} else {
|
||||
"downloading"
|
||||
}
|
||||
updateNativeWorkerItem(itemId) {
|
||||
it.status = currentStatus
|
||||
it.progress = progressValue
|
||||
it.bytesReceived = bytesReceived
|
||||
it.bytesTotal = bytesTotal
|
||||
|
||||
Reference in New Issue
Block a user