Move all DownloadService.stop calls to Downloader (#9146)

Downloader.stop is now the sole responsible for stopping the
DownloadService. This will help cleanly removing
DownloadService.stop when migrating to coroutines.

(cherry picked from commit 0505906e7a554abe6bbbc2c1cd4a6bfaa9407bf6)
This commit is contained in:
Two-Ai 2023-02-25 15:40:22 -05:00 committed by Jobobby04
parent 897d019f0b
commit f8dc4f25d1
2 changed files with 11 additions and 7 deletions

View File

@ -70,7 +70,7 @@ class DownloadManager(
*/
fun pauseDownloads() {
downloader.pause()
DownloadService.stop(context)
downloader.stop()
}
/**
@ -78,7 +78,7 @@ class DownloadManager(
*/
fun clearQueue() {
downloader.clearQueue()
DownloadService.stop(context)
downloader.stop()
}
/**
@ -118,8 +118,8 @@ class DownloadManager(
val wasRunning = downloader.isRunning
if (downloads.isEmpty()) {
DownloadService.stop(context)
queue.clear()
downloader.clearQueue()
downloader.stop()
return
}
@ -278,7 +278,6 @@ class DownloadManager(
if (wasRunning) {
if (queue.isEmpty()) {
DownloadService.stop(context)
downloader.stop()
} else if (queue.isNotEmpty()) {
downloader.start()

View File

@ -173,6 +173,11 @@ class Downloader(
}
isPaused = false
// Prevent recursion when DownloadService.onDestroy() calls downloader.stop()
if (DownloadService.isRunning.value) {
DownloadService.stop(context)
}
}
/**
@ -223,9 +228,9 @@ class Downloader(
completeDownload(it)
},
{ error ->
DownloadService.stop(context)
logcat(LogPriority.ERROR, error)
notifier.onError(error.message)
stop()
},
)
}
@ -646,7 +651,7 @@ class Downloader(
queue.remove(download)
}
if (areAllDownloadsFinished()) {
DownloadService.stop(context)
stop()
}
}