Improved the resuming of downloads.

This commit is contained in:
MohitMaliFtechiz 2024-12-16 16:24:35 +05:30 committed by Kelson
parent 5050e4a92e
commit 9b8abe5ab2

View File

@ -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
}
@ -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
}
@ -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(
@ -528,12 +531,14 @@ class DownloadManagerMonitor @Inject constructor(
STATUS_RUNNING
)
) {
if (shouldUpdateStatus) {
// pass false when user resumed the download to proceed with further checks.
updateDownloadStatus(downloadId, Status.QUEUED, Error.NONE, pausedByUser = false)
}
}
}
}
}
fun cancelDownload(downloadId: Long) {
synchronized(lock) {