Don't stop downloader after deleting downloads if it wasn't running (fixes #4309)

This commit is contained in:
arkon 2021-01-22 17:52:10 -05:00
parent 496a476c13
commit 7c7ff8165e

View File

@ -212,18 +212,7 @@ class DownloadManager(private val context: Context) {
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source): List<Chapter> {
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<Chapter>) {
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)
}