From 226bb18d4677bf52ff522a10064bffa45e7117ac Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 2 Jul 2021 21:37:04 -0400 Subject: [PATCH] option to add manga count to the category headers closes --- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../tachiyomi/ui/library/LibraryCategoryAdapter.kt | 13 +++++++++++++ .../tachiyomi/ui/library/LibraryController.kt | 7 +++++++ .../tachiyomi/ui/library/LibraryHeaderHolder.kt | 9 +++++++-- .../ui/library/display/LibraryCategoryView.kt | 1 + app/src/main/res/layout/library_category_layout.xml | 8 ++++++++ app/src/main/res/values/strings.xml | 1 + 8 files changed, 41 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 a792db943d..57dff5b593 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 @@ -198,6 +198,8 @@ object PreferenceKeys { const val showLibraryUpdateErrors = "show_library_update_errors" + const val categoryNumberOfItems = "display_number_of_items" + const val alwaysShowChapterTransition = "always_show_chapter_transition" const val hideBottomNavOnScroll = "hide_bottom_nav_on_scroll" 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 c503ecbf89..2bbb5f6f99 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 @@ -355,6 +355,8 @@ class PreferencesHelper(val context: Context) { fun unreadBadgeType() = flowPrefs.getInt("unread_badge_type", 2) + fun categoryNumberOfItems() = flowPrefs.getBoolean(Keys.categoryNumberOfItems, false) + fun hideStartReadingButton() = flowPrefs.getBoolean("hide_reading_button", false) fun alwaysShowChapterTransition() = flowPrefs.getBoolean(Keys.alwaysShowChapterTransition, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index d0f5b70265..a7c890194e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -27,10 +27,19 @@ class LibraryCategoryAdapter(val controller: LibraryController) : val sourceManager by injectLazy() + private val preferences: PreferencesHelper by injectLazy() + + var showNumber = preferences.categoryNumberOfItems().get() + init { setDisplayHeadersAtStartUp(true) } + /** + * The number of manga in each category. + */ + var itemsPerCategory: Map = emptyMap() + /** * The list of manga in this category. */ @@ -51,6 +60,10 @@ class LibraryCategoryAdapter(val controller: LibraryController) : mangas = list.toList() performFilter() + + itemsPerCategory = headerItems.map { header -> + (header as LibraryHeaderItem).catId to getSectionItemPositions(header).size + }.toMap() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index c3e90cbf7e..f94a16c841 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -905,6 +905,13 @@ class LibraryController( adapter.notifyDataSetChanged() } .launchIn(viewScope) + preferences.categoryNumberOfItems().asFlow() + .drop(1) + .onEach { + adapter.showNumber = it + adapter.notifyDataSetChanged() + } + .launchIn(viewScope) } override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt index 283791c8f6..413ec67719 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.library +import android.annotation.SuppressLint import android.app.Activity import android.graphics.Color import android.util.TypedValue @@ -58,6 +59,7 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd } } + @SuppressLint("SetTextI18n") fun bind(item: LibraryHeaderItem) { val index = adapter.headerItems.indexOf(item) val previousIsCollapsed = @@ -79,8 +81,11 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd } val category = item.category - if (category.isAlone && !category.isDynamic) binding.categoryTitle.text = "" - else binding.categoryTitle.text = category.name + binding.categoryTitle.text = + if (category.isAlone && !category.isDynamic) { "" } else { category.name } + + if (adapter.showNumber && !category.isHidden) { + " (${adapter.itemsPerCategory[item.catId]})" + } else { "" } if (category.sourceId != null) { val icon = adapter.sourceManager.get(category.sourceId!!)?.icon() icon?.setBounds(0, 0, 32.dpToPx, 32.dpToPx) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt index 8c51f6fd5b..ba77e8e39d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt @@ -29,6 +29,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att dynamicToBottom.bindToPreference(preferences.collapsedDynamicAtBottom()) { controller?.presenter?.getLibrary() } + showNumberOfItems.bindToPreference(preferences.categoryNumberOfItems()) val hideHopper = min( 2, preferences.hideHopper().get().toInt() * 2 + preferences.autohideHopper().get() diff --git a/app/src/main/res/layout/library_category_layout.xml b/app/src/main/res/layout/library_category_layout.xml index a0b022ea8c..6a136a3f3d 100644 --- a/app/src/main/res/layout/library_category_layout.xml +++ b/app/src/main/res/layout/library_category_layout.xml @@ -35,6 +35,14 @@ android:layout_marginEnd="12dp" android:text="@string/move_dynamic_to_bottom" /> + + No matches found for your current filters Show all categories Move collapsed dynamic categories to bottom + Show number of items When grouping library by sources, status, etc. Always show current category Category hopper long-press action