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 240dbc2c7..d8a8368ac 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 @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.DownloadQueue +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Page @@ -24,10 +25,8 @@ import uy.kohesive.injekt.injectLazy */ class DownloadManager(private val context: Context) { - /** - * The sources manager. - */ - private val sourceManager by injectLazy() + private val sourceManager: SourceManager by injectLazy() + private val preferences: PreferencesHelper by injectLazy() /** * Downloads provider, used to retrieve the folders where the chapters are or should be stored. @@ -201,9 +200,16 @@ class DownloadManager(private val context: Context) { */ fun deleteChapters(chapters: List, manga: Manga, source: Source) { queue.remove(chapters) - val chapterDirs = provider.findChapterDirs(chapters, manga, source) + + val filteredChapters = if (!preferences.removeBookmarkedChapters()) { + chapters.filterNot { it.bookmark } + } else { + chapters + } + + val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source) chapterDirs.forEach { it.delete() } - cache.removeChapters(chapters, manga) + cache.removeChapters(filteredChapters, manga) if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty chapterDirs.firstOrNull()?.parentFile?.delete() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 818c6c718..2c7f66dcf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -97,6 +97,8 @@ object PreferenceKeys { const val removeAfterMarkedAsRead = "pref_remove_after_marked_as_read_key" + const val removeBookmarkedChapters = "pref_remove_bookmarked" + const val libraryUpdateInterval = "pref_library_update_interval_key" const val libraryUpdateRestriction = "library_update_restriction" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index f7a0ecd59..11bffb186 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -188,6 +188,8 @@ class PreferencesHelper(val context: Context) { fun removeAfterMarkedAsRead() = prefs.getBoolean(Keys.removeAfterMarkedAsRead, false) + fun removeBookmarkedChapters() = prefs.getBoolean(Keys.removeBookmarkedChapters, false) + fun libraryUpdateInterval() = flowPrefs.getInt(Keys.libraryUpdateInterval, 24) fun libraryUpdateRestriction() = prefs.getStringSet(Keys.libraryUpdateRestriction, setOf("wifi")) 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 196f26efa..a3ea29a82 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,8 +494,14 @@ class MangaPresenter( * @param chapters the chapters to delete. */ private fun deleteChaptersInternal(chapters: List) { - downloadManager.deleteChapters(chapters, manga, source) - chapters.forEach { + 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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index 3916725b3..82c055a0f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt @@ -84,6 +84,11 @@ class SettingsDownloadController : SettingsController() { defaultValue = "-1" summary = "%s" } + switchPreference { + key = Keys.removeBookmarkedChapters + titleRes = R.string.pref_remove_bookmarked_chapters + defaultValue = false + } } val dbCategories = db.getCategories().executeAsBlocking() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c6f6a9dfa..98b69261f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -314,6 +314,7 @@ Delete chapters After manually marked as read After reading + Delete bookmarked chapters Custom location Disabled Last read chapter