Move all DownloadService.stop calls to Downloader ()

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
app/src/main/java/eu/kanade/tachiyomi/data/download

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

@ -173,6 +173,11 @@ class Downloader(
} }
isPaused = false 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) completeDownload(it)
}, },
{ error -> { error ->
DownloadService.stop(context)
logcat(LogPriority.ERROR, error) logcat(LogPriority.ERROR, error)
notifier.onError(error.message) notifier.onError(error.message)
stop()
}, },
) )
} }
@ -646,7 +651,7 @@ class Downloader(
queue.remove(download) queue.remove(download)
} }
if (areAllDownloadsFinished()) { if (areAllDownloadsFinished()) {
DownloadService.stop(context) stop()
} }
} }