From 8dcd919ff0c4df78343e501400294cfb079dc901 Mon Sep 17 00:00:00 2001 From: Hunter Nickel Date: Wed, 26 May 2021 16:10:20 -0600 Subject: [PATCH] Implement feature to hide "Local" badge from library manga (#5202) --- .../eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../kanade/tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../tachiyomi/ui/library/LibraryComfortableGridHolder.kt | 2 +- .../tachiyomi/ui/library/LibraryCompactGridHolder.kt | 2 +- .../java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt | 1 + .../eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt | 2 +- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 8 ++++++++ .../kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt | 5 ++++- app/src/main/res/values/strings.xml | 1 + 9 files changed, 21 insertions(+), 4 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 bdbc57e48..f8b419bb6 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 @@ -193,6 +193,8 @@ object PreferenceKeys { const val unreadBadge = "display_unread_badge" + const val localBadge = "display_local_badge" + const val categoryTabs = "display_category_tabs" const val categoryNumberOfItems = "display_number_of_items" 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 63a0bd506..479597cec 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,6 +238,8 @@ class PreferencesHelper(val context: Context) { fun downloadBadge() = flowPrefs.getBoolean(Keys.downloadBadge, false) + fun localBadge() = flowPrefs.getBoolean(Keys.localBadge, true) + fun downloadedOnly() = flowPrefs.getBoolean(Keys.downloadedOnly, false) fun unreadBadge() = flowPrefs.getBoolean(Keys.unreadBadge, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt index bb7684554..c994ea99f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt @@ -50,7 +50,7 @@ class LibraryComfortableGridHolder( text = item.downloadCount.toString() } // set local visibility if its local manga - binding.localText.isVisible = item.manga.isLocal() + binding.localText.isVisible = item.isLocal // For rounded corners binding.card.clipToOutline = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt index bcf0c254e..c9d2fcb53 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt @@ -48,7 +48,7 @@ open class LibraryCompactGridHolder( text = item.downloadCount.toString() } // set local visibility if its local manga - binding.localText.isVisible = item.manga.isLocal() + binding.localText.isVisible = item.isLocal // For rounded corners binding.card.clipToOutline = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 78f7ce485..daa683400 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -28,6 +28,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryDisplayMode: Prefe var downloadCount = -1 var unreadCount = -1 + var isLocal = false override fun getLayoutRes(): Int { return when (libraryDisplayMode.get()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 3e67016ac..d80a4d8af 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -50,7 +50,7 @@ class LibraryListHolder( text = "${item.downloadCount}" } // show local text badge if local manga - binding.localText.isVisible = item.manga.isLocal() + binding.localText.isVisible = item.isLocal // Create thumbnail onclick to simulate long click binding.thumbnail.setOnClickListener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index d7d280445..a528ffba9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -195,6 +195,7 @@ class LibraryPresenter( private fun setBadges(map: LibraryMap) { val showDownloadBadges = preferences.downloadBadge().get() val showUnreadBadges = preferences.unreadBadge().get() + val showLocalBadges = preferences.localBadge().get() for ((_, itemList) in map) { for (item in itemList) { @@ -211,6 +212,13 @@ class LibraryPresenter( // Unset unread count if not enabled -1 } + + item.isLocal = if (showLocalBadges) { + item.manga.isLocal() + } else { + // Hide / Unset local badge if not enabled + false + } } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 44ec85ae2..7f268532e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -276,14 +276,16 @@ class LibrarySettingsSheet( inner class BadgeGroup : Group { private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this) private val unreadBadge = Item.CheckboxGroup(R.string.action_display_unread_badge, this) + private val localBadge = Item.CheckboxGroup(R.string.action_display_local_badge, this) override val header = Item.Header(R.string.badges_header) - override val items = listOf(downloadBadge, unreadBadge) + override val items = listOf(downloadBadge, unreadBadge, localBadge) override val footer = null override fun initModels() { downloadBadge.checked = preferences.downloadBadge().get() unreadBadge.checked = preferences.unreadBadge().get() + localBadge.checked = preferences.localBadge().get() } override fun onItemClicked(item: Item) { @@ -292,6 +294,7 @@ class LibrarySettingsSheet( when (item) { downloadBadge -> preferences.downloadBadge().set((item.checked)) unreadBadge -> preferences.unreadBadge().set((item.checked)) + localBadge -> preferences.localBadge().set((item.checked)) } adapter.notifyItemChanged(item) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5c94985d..70a65fc31 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -95,6 +95,7 @@ Comfortable grid Download badges Unread badges + Local badges Show category tabs Show number of items Disable