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

(cherry picked from commit 7c7ff8165eeab862363d0be41dbeb9f86c0bd386)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt
This commit is contained in:
arkon 2021-01-22 17:52:10 -05:00 committed by Jobobby04
parent 41607ab259
commit fc481e4fd4

View File

@ -212,18 +212,7 @@ class DownloadManager(/* SY private */ val context: Context) {
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source): List<Chapter> { fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source): List<Chapter> {
val filteredChapters = getChaptersToDelete(chapters) val filteredChapters = getChaptersToDelete(chapters)
val wasRunning = downloader.isRunning removeFromDownloadQueue(filteredChapters)
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()
}
val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source) val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source)
chapterDirs.forEach { it.delete() } chapterDirs.forEach { it.delete() }
@ -235,6 +224,24 @@ class DownloadManager(/* SY private */ val context: Context) {
return filteredChapters 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()
}
}
}
// SY --> // SY -->
/** /**
* return the list of all manga folders * return the list of all manga folders
@ -295,7 +302,7 @@ class DownloadManager(/* SY private */ val context: Context) {
* @param source the source of the manga. * @param source the source of the manga.
*/ */
fun deleteManga(manga: Manga, source: Source) { fun deleteManga(manga: Manga, source: Source) {
queue.remove(manga) downloader.queue.remove(manga)
provider.findMangaDir(manga, source)?.delete() provider.findMangaDir(manga, source)?.delete()
cache.removeManga(manga) cache.removeManga(manga)
} }