From 709de81814c672aaf5042d1ff6c84c8360563681 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 30 Oct 2021 12:42:59 -0400 Subject: [PATCH] Move unread chapters badge setting to General section --- .../eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt | 4 ++-- .../eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt | 2 +- .../eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt | 4 ++-- .../main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 4 ++-- .../kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt | 4 ++-- .../kanade/tachiyomi/ui/setting/SettingsGeneralController.kt | 5 +++++ .../kanade/tachiyomi/ui/setting/SettingsLibraryController.kt | 5 ----- .../widget/preference/ButtonToggleGroupPreference.kt | 4 ++++ app/src/main/res/values/strings.xml | 2 +- 9 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/ButtonToggleGroupPreference.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 03a9c15a59..19b7a40b1b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -291,7 +291,7 @@ class LibraryUpdateService( val failedUpdates = CopyOnWriteArrayList>() val hasDownloads = AtomicBoolean(false) val loggedServices by lazy { trackManager.services.filter { it.isLogged } } - val currentUnreadUpdatesCount = preferences.libraryUnreadUpdatesCount().get() + val currentUnreadUpdatesCount = preferences.unreadUpdatesCount().get() withIOContext { mangaToUpdate.groupBy { it.source } @@ -356,7 +356,7 @@ class LibraryUpdateService( if (newUpdates.isNotEmpty()) { notifier.showUpdateNotifications(newUpdates) val newChapterCount = newUpdates.sumOf { it.second.size } - preferences.libraryUnreadUpdatesCount().set(currentUnreadUpdatesCount + newChapterCount) + preferences.unreadUpdatesCount().set(currentUnreadUpdatesCount + newChapterCount) if (hasDownloads.get()) { DownloadService.start(this) } 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 f013d73dee..bb85ce045f 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 @@ -133,7 +133,7 @@ object PreferenceKeys { const val libraryUpdateRestriction = "library_update_restriction" - const val libraryUpdateShowTabBadge = "library_update_show_tab_badge" + const val showUpdatesNavBadge = "library_update_show_tab_badge" const val libraryUpdateCategories = "library_update_categories" const val libraryUpdateCategoriesExclude = "library_update_categories_exclude" 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 79a13eb826..d029974c26 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 @@ -238,8 +238,8 @@ class PreferencesHelper(val context: Context) { fun libraryUpdateRestriction() = flowPrefs.getStringSet(Keys.libraryUpdateRestriction, setOf(ONLY_ON_WIFI)) - fun libraryUpdateShowTabBadge() = flowPrefs.getBoolean(Keys.libraryUpdateShowTabBadge, true) - fun libraryUnreadUpdatesCount() = flowPrefs.getInt("library_unread_updates_count", 0) + fun showUpdatesNavBadge() = flowPrefs.getBoolean(Keys.showUpdatesNavBadge, true) + fun unreadUpdatesCount() = flowPrefs.getInt("library_unread_updates_count", 0) fun libraryUpdateCategories() = flowPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet()) fun libraryUpdateCategoriesExclude() = flowPrefs.getStringSet(Keys.libraryUpdateCategoriesExclude, emptySet()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index ec87d83570..400c916ffc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -228,7 +228,7 @@ class MainActivity : BaseViewBindingActivity() { } } - merge(preferences.libraryUpdateShowTabBadge().asFlow(), preferences.libraryUnreadUpdatesCount().asFlow()) + merge(preferences.showUpdatesNavBadge().asFlow(), preferences.unreadUpdatesCount().asFlow()) .onEach { setUnreadUpdatesBadge() } .launchIn(lifecycleScope) @@ -355,7 +355,7 @@ class MainActivity : BaseViewBindingActivity() { } private fun setUnreadUpdatesBadge() { - val updates = if (preferences.libraryUpdateShowTabBadge().get()) preferences.libraryUnreadUpdatesCount().get() else 0 + val updates = if (preferences.showUpdatesNavBadge().get()) preferences.unreadUpdatesCount().get() else 0 if (updates > 0) { nav.getOrCreateBadge(R.id.nav_updates).number = updates } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index 96efe3db84..f0c9b5369a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -106,8 +106,8 @@ class UpdatesPresenter : BasePresenter() { setDownloadedChapters(list) chapters = list - //Set unread chapter count for bottom bar badge - preferences.libraryUnreadUpdatesCount().set(list.count { !it.read }) + // Set unread chapter count for bottom bar badge + preferences.unreadUpdatesCount().set(list.count { !it.read }) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index f80829c5ac..667a0a8f86 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -32,6 +32,11 @@ class SettingsGeneralController : SettingsController() { defaultValue = "1" summary = "%s" } + switchPreference { + key = Keys.showUpdatesNavBadge + titleRes = R.string.pref_library_update_show_tab_badge + defaultValue = true + } switchPreference { key = Keys.confirmExit titleRes = R.string.pref_confirm_exit diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 83b1d8a0a7..a8e98b3236 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -199,11 +199,6 @@ class SettingsLibraryController : SettingsController() { titleRes = R.string.pref_update_only_non_completed defaultValue = false } - switchPreference { - key = Keys.libraryUpdateShowTabBadge - titleRes = R.string.pref_library_update_show_tab_badge - defaultValue = true - } preference { key = Keys.libraryUpdateCategories titleRes = R.string.categories diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ButtonToggleGroupPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ButtonToggleGroupPreference.kt new file mode 100644 index 0000000000..08518579dd --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ButtonToggleGroupPreference.kt @@ -0,0 +1,4 @@ +package eu.kanade.tachiyomi.widget.preference + +class ButtonToggleGroupPreference { +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba1009b285..d18ca02f74 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -223,7 +223,7 @@ Charging Restrictions: %s Only update ongoing manga - Show update count on bottom bar + Show unread count on Updates icon Automatically refresh metadata Check for new cover and details when updating library Automatically refresh trackers