From a3a4edbde072ca4b8a14b412040adc8b3da76436 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 3 Jul 2021 19:53:28 -0400 Subject: [PATCH] Allow excluding categories from auto-download Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com> --- .../eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt | 1 + .../eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt | 1 + .../tachiyomi/ui/setting/SettingsDownloadController.kt | 5 +++-- .../main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt | 3 +++ 4 files changed, 8 insertions(+), 2 deletions(-) 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 1c897a11f9..3610e46783 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 @@ -154,6 +154,7 @@ object PreferenceKeys { const val downloadNew = "download_new" const val downloadNewCategories = "download_new_categories" + const val downloadNewCategoriesExclude = "download_new_categories_exclude" const val libraryLayout = "pref_display_library_layout" 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 4a7a77afe6..d8cbc8c1a4 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 @@ -298,6 +298,7 @@ class PreferencesHelper(val context: Context) { fun downloadNew() = flowPrefs.getBoolean(Keys.downloadNew, false) fun downloadNewCategories() = flowPrefs.getStringSet(Keys.downloadNewCategories, emptySet()) + fun downloadNewCategoriesExclude() = flowPrefs.getStringSet(Keys.downloadNewCategoriesExclude, emptySet()) fun lang() = flowPrefs.getString(Keys.lang, "") 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 b59dfc0ed7..b9d73ff8f8 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 @@ -89,9 +89,10 @@ class SettingsDownloadController : SettingsController() { titleRes = R.string.download_new_chapters defaultValue = false } - multiSelectListPreferenceMat(activity) { + triStateListPreference(activity) { key = Keys.downloadNewCategories - titleRes = R.string.categories_to_include_in_download + excludeKey = Keys.downloadNewCategoriesExclude + titleRes = R.string.categories entries = categories.map { it.name } entryValues = categories.map { it.id.toString() } allSelectionRes = R.string.all diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt index f7ceea3533..33e985344c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt @@ -43,6 +43,9 @@ fun Manga.shouldDownloadNewChapters(db: DatabaseHelper, prefs: PreferencesHelper .mapNotNull { it.id } .takeUnless { it.isEmpty() } ?: listOf(0) + val categoriesToExclude = prefs.downloadNewCategoriesExclude().get().map(String::toInt) + if (categoriesForManga.intersect(categoriesToExclude).isNotEmpty()) return false + return categoriesForManga.intersect(categoriesToDownload).isNotEmpty() }