diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index be0487003..8a5bad025 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -212,18 +212,7 @@ class DownloadManager(private val context: Context) { fun deleteChapters(chapters: List, manga: Manga, source: Source): List { val filteredChapters = getChaptersToDelete(chapters) - val wasRunning = downloader.isRunning - downloader.pause() - - downloader.queue.remove(filteredChapters) - queue.remove(filteredChapters) - - if (downloader.queue.isEmpty()) { - DownloadService.stop(context) - downloader.stop() - } else if (wasRunning && downloader.queue.isNotEmpty()) { - downloader.start() - } + removeFromDownloadQueue(filteredChapters) val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source) chapterDirs.forEach { it.delete() } @@ -235,6 +224,24 @@ class DownloadManager(private val context: Context) { return filteredChapters } + private fun removeFromDownloadQueue(chapters: List) { + val wasRunning = downloader.isRunning + if (wasRunning) { + downloader.pause() + } + + downloader.queue.remove(chapters) + + if (wasRunning) { + if (downloader.queue.isEmpty()) { + DownloadService.stop(context) + downloader.stop() + } else if (downloader.queue.isNotEmpty()) { + downloader.start() + } + } + } + /** * Deletes the directory of a downloaded manga. * @@ -242,7 +249,7 @@ class DownloadManager(private val context: Context) { * @param source the source of the manga. */ fun deleteManga(manga: Manga, source: Source) { - queue.remove(manga) + downloader.queue.remove(manga) provider.findMangaDir(manga, source)?.delete() cache.removeManga(manga) }