fix: upload progress stuck at 0%
setProgressAsync (fire-and-forget) was dropping/coalescing updates before they were persisted. Switch to awaited suspend setProgress() in both UploadWorker and DownloadWorker so each progress write lands and the LiveData observer actually sees pct advance.
This commit is contained in:
@@ -139,7 +139,7 @@ class DownloadWorker(
|
|||||||
lastProgressMs = now
|
lastProgressMs = now
|
||||||
val pct = if (total > 0) ((downloaded * 100) / total).toInt() else 0
|
val pct = if (total > 0) ((downloaded * 100) / total).toInt() else 0
|
||||||
setForeground(createForegroundInfo(filename, pct, downloaded, total))
|
setForeground(createForegroundInfo(filename, pct, downloaded, total))
|
||||||
setProgressAsync(workDataOf("pct" to pct))
|
setProgress(workDataOf("pct" to pct))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,14 +55,14 @@ class UploadWorker(
|
|||||||
try {
|
try {
|
||||||
// Promote to foreground immediately so large files aren't killed during hashing
|
// Promote to foreground immediately so large files aren't killed during hashing
|
||||||
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Preparing $filename", 0))
|
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Preparing $filename", 0))
|
||||||
setProgressAsync(workDataOf("pct" to 0, "status" to "Hashing…"))
|
setProgress(workDataOf("pct" to 0, "status" to "Hashing…"))
|
||||||
|
|
||||||
// Compute SHA256
|
// Compute SHA256
|
||||||
val sha256 = computeSha256(file)
|
val sha256 = computeSha256(file)
|
||||||
val relativePath = filename // Using filename as relative_path since flat dir
|
val relativePath = filename // Using filename as relative_path since flat dir
|
||||||
|
|
||||||
// Check status
|
// Check status
|
||||||
setProgressAsync(workDataOf("pct" to 0, "status" to "Checking server…"))
|
setProgress(workDataOf("pct" to 0, "status" to "Checking server…"))
|
||||||
val statusUrl = "$serverUrl/api/v1/dashcam/upload/status?relative_path=$relativePath&sha256=$sha256"
|
val statusUrl = "$serverUrl/api/v1/dashcam/upload/status?relative_path=$relativePath&sha256=$sha256"
|
||||||
val statusReq = Request.Builder().url(statusUrl)
|
val statusReq = Request.Builder().url(statusUrl)
|
||||||
.addHeader("X-Device-Name", deviceName)
|
.addHeader("X-Device-Name", deviceName)
|
||||||
@@ -82,7 +82,7 @@ class UploadWorker(
|
|||||||
|
|
||||||
val totalChunks = ((file.length() + CHUNK_SIZE - 1) / CHUNK_SIZE).toInt()
|
val totalChunks = ((file.length() + CHUNK_SIZE - 1) / CHUNK_SIZE).toInt()
|
||||||
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Uploading $filename", 0))
|
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Uploading $filename", 0))
|
||||||
setProgressAsync(workDataOf("pct" to 0, "status" to "Uploading…"))
|
setProgress(workDataOf("pct" to 0, "status" to "Uploading…"))
|
||||||
|
|
||||||
// Upload missing chunks
|
// Upload missing chunks
|
||||||
for (i in 0 until totalChunks) {
|
for (i in 0 until totalChunks) {
|
||||||
@@ -120,7 +120,7 @@ class UploadWorker(
|
|||||||
|
|
||||||
val pct = ((i + 1) * 100) / totalChunks
|
val pct = ((i + 1) * 100) / totalChunks
|
||||||
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Uploading $filename", pct))
|
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Uploading $filename", pct))
|
||||||
setProgressAsync(workDataOf("pct" to pct, "status" to "Uploading…"))
|
setProgress(workDataOf("pct" to pct, "status" to "Uploading…"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return@withContext Result.success(workDataOf("filename" to filename))
|
return@withContext Result.success(workDataOf("filename" to filename))
|
||||||
|
|||||||
Reference in New Issue
Block a user