mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-17 20:18:35 -04:00
DownloadWorker: Also consider speed when updating progress
This should fix the issue where progress gets stuck because download speed gets really low but UI still mentions old speed and time remaining Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -285,13 +285,12 @@ class DownloadWorker @AssistedInject constructor(
|
||||
private suspend fun onProgress(downloadInfo: DownloadInfo) {
|
||||
if (!isStopped && !download.isFinished) {
|
||||
val progress = ((downloadedBytes + downloadInfo.bytesCopied) * 100 / totalBytes).toInt()
|
||||
val bytesRemaining = totalBytes - (downloadedBytes + downloadInfo.bytesCopied)
|
||||
val speed = if (downloadInfo.speed == 0L) 1 else downloadInfo.speed
|
||||
|
||||
// Individual file progress can be negligible in contrast to total progress
|
||||
// Only notify the UI if progress is greater to avoid being rate-limited by Android
|
||||
if (progress > totalProgress) {
|
||||
val bytesRemaining = totalBytes - (downloadedBytes + downloadInfo.bytesCopied)
|
||||
val speed = if (downloadInfo.speed == 0L) 1 else downloadInfo.speed
|
||||
|
||||
// Only notify the UI if progress is greater or speed has changed to avoid being rate-limited by Android
|
||||
if (progress > totalProgress || speed != download.speed) {
|
||||
if (downloadInfo.progress == 100) {
|
||||
downloadedBytes += downloadInfo.bytesCopied
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user