Skip to content

Commit

Permalink
Improved the resuming of downloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitMaliDeveloper committed Dec 16, 2024
1 parent 068508d commit a1bbd1e
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class DownloadManagerMonitor @Inject constructor(
// due to some reason.
Error.PAUSED_UNKNOWN,
Error.WAITING_TO_RETRY -> {
resumeDownload(downloadRoomEntity.downloadId)
resumeDownload(downloadRoomEntity.downloadId, shouldUpdateStatus = false)
false
}

Expand All @@ -499,7 +499,7 @@ class DownloadManagerMonitor @Inject constructor(
* @return `true` to update the status and attempt to resume the download.
*/
private fun handleRetryablePausedDownload(downloadRoomEntity: DownloadRoomEntity): Boolean {
resumeDownload(downloadRoomEntity.downloadId)
resumeDownload(downloadRoomEntity.downloadId, shouldUpdateStatus = false)
return true

Check warning on line 503 in core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadManagerMonitor.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/DownloadManagerMonitor.kt#L502-L503

Added lines #L502 - L503 were not covered by tests
}

Expand All @@ -519,7 +519,10 @@ class DownloadManagerMonitor @Inject constructor(
}
}

fun resumeDownload(downloadId: Long) {
fun resumeDownload(
downloadId: Long,
shouldUpdateStatus: Boolean = true
) {
synchronized(lock) {
updater.onNext {
if (pauseResumeDownloadInDownloadManagerContentResolver(
Expand All @@ -528,8 +531,10 @@ class DownloadManagerMonitor @Inject constructor(
STATUS_RUNNING
)
) {
// pass false when user resumed the download to proceed with further checks.
updateDownloadStatus(downloadId, Status.QUEUED, Error.NONE, pausedByUser = false)
if (shouldUpdateStatus) {
// pass false when user resumed the download to proceed with further checks.
updateDownloadStatus(downloadId, Status.QUEUED, Error.NONE, pausedByUser = false)
}
}
}
}
Expand Down

0 comments on commit a1bbd1e

Please sign in to comment.