From 4c8665c9f015cc87c0280fa9495f0748c5490fba Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 18 Aug 2020 17:47:07 -0400 Subject: [PATCH] Don't enqueue bookmarked chapters for deletion (fixes #3691) --- .../data/download/DownloadManager.kt | 22 ++++++++++++------- .../tachiyomi/ui/manga/MangaPresenter.kt | 15 +++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) 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 d8a8368ac0..400fe56482 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 @@ -198,14 +198,10 @@ class DownloadManager(private val context: Context) { * @param manga the manga of the chapters. * @param source the source of the chapters. */ - fun deleteChapters(chapters: List, manga: Manga, source: Source) { - queue.remove(chapters) + fun deleteChapters(chapters: List, manga: Manga, source: Source): List { + val filteredChapters = getChaptersToDelete(chapters) - val filteredChapters = if (!preferences.removeBookmarkedChapters()) { - chapters.filterNot { it.bookmark } - } else { - chapters - } + queue.remove(filteredChapters) val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source) chapterDirs.forEach { it.delete() } @@ -213,6 +209,8 @@ class DownloadManager(private val context: Context) { if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty chapterDirs.firstOrNull()?.parentFile?.delete() } + + return filteredChapters } /** @@ -234,7 +232,7 @@ class DownloadManager(private val context: Context) { * @param manga the manga of the chapters. */ fun enqueueDeleteChapters(chapters: List, manga: Manga) { - pendingDeleter.addChapters(chapters, manga) + pendingDeleter.addChapters(getChaptersToDelete(chapters), manga) } /** @@ -273,4 +271,12 @@ class DownloadManager(private val context: Context) { Timber.e("Could not rename downloaded chapter: %s.", oldNames.joinToString()) } } + + private fun getChaptersToDelete(chapters: List): List { + return if (!preferences.removeBookmarkedChapters()) { + chapters.filterNot { it.bookmark } + } else { + chapters + } + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index a3ea29a820..95ee65ce35 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -494,16 +494,11 @@ class MangaPresenter( * @param chapters the chapters to delete. */ private fun deleteChaptersInternal(chapters: List) { - val filteredChapters = if (!preferences.removeBookmarkedChapters()) { - chapters.filterNot { it.bookmark } - } else { - chapters - } - - downloadManager.deleteChapters(filteredChapters, manga, source) - filteredChapters.forEach { - it.status = Download.NOT_DOWNLOADED - it.download = null + downloadManager.deleteChapters(chapters, manga, source).forEach { + if (it is ChapterItem) { + it.status = Download.NOT_DOWNLOADED + it.download = null + } } }