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 f452045c9..0e16ed980 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 @@ -147,6 +147,8 @@ object PreferenceKeys { const val unreadBadge = "display_unread_badge" + const val categoryTabs = "display_category_tabs" + const val alwaysShowChapterTransition = "always_show_chapter_transition" const val searchPinnedSourcesOnly = "search_pinned_sources_only" 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 3e53a9e9d..4bf893c70 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 @@ -193,6 +193,8 @@ class PreferencesHelper(val context: Context) { fun unreadBadge() = flowPrefs.getBoolean(Keys.unreadBadge, true) + fun categoryTabs() = flowPrefs.getBoolean(Keys.categoryTabs, true) + fun filterDownloaded() = flowPrefs.getBoolean(Keys.filterDownloaded, false) fun filterUnread() = flowPrefs.getBoolean(Keys.filterUnread, false) 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 e533648ec..32864d6ad 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 @@ -135,8 +135,26 @@ class LibraryController( retainViewMode = RetainViewMode.RETAIN_DETACH } + private var title: String? = null + set(value) { + if (field != value) { + field = value + setTitle() + } + } + override fun getTitle(): String? { - return resources?.getString(R.string.label_library) + return title ?: resources?.getString(R.string.label_library) + } + + private fun updateTitle() { + if (preferences.categoryTabs().get()) { + title = resources?.getString(R.string.label_library) + } else { + adapter?.categories?.get(binding.libraryPager.currentItem)?.let { + title = it.name + } + } } override fun createPresenter(): LibraryPresenter { @@ -157,6 +175,7 @@ class LibraryController( .onEach { preferences.lastUsedCategory().set(it) activeCategory = it + updateTitle() } .launchIn(scope) @@ -175,7 +194,8 @@ class LibraryController( is LibrarySettingsSheet.Filter.FilterGroup -> onFilterChanged() is LibrarySettingsSheet.Sort.SortGroup -> onSortChanged() is LibrarySettingsSheet.Display.DisplayGroup -> reattachAdapter() - is LibrarySettingsSheet.Display.BadgeGroup -> onBadgeChanged() + is LibrarySettingsSheet.Display.BadgeGroup -> onBadgeSettingChanged() + is LibrarySettingsSheet.Display.TabsGroup -> onTabsSettingsChanged() } } @@ -254,7 +274,8 @@ class LibraryController( // Restore active category. binding.libraryPager.setCurrentItem(activeCat, false) - tabsVisibilityRelay.call(categories.size > 1) + // Trigger display of tabs + onTabsSettingsChanged() // Delay the scroll position to allow the view to be properly measured. view.post { @@ -280,18 +301,20 @@ class LibraryController( } } - /** - * Called when a filter is changed. - */ private fun onFilterChanged() { presenter.requestFilterUpdate() activity?.invalidateOptionsMenu() } - private fun onBadgeChanged() { + private fun onBadgeSettingChanged() { presenter.requestBadgesUpdate() } + private fun onTabsSettingsChanged() { + tabsVisibilityRelay.call(preferences.categoryTabs().get() && adapter?.categories?.size ?: 0 > 1) + updateTitle() + } + /** * Called when the sorting mode is changed. */ 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 437c07f44..ae4182004 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 @@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog import uy.kohesive.injekt.injectLazy class LibrarySettingsSheet( - private val activity: Activity, + activity: Activity, onGroupClickListener: (ExtendedNavigationView.Group) -> Unit ) : TabbedBottomSheetDialog(activity) { @@ -178,7 +178,7 @@ class LibrarySettingsSheet( Settings(context, attrs) { init { - setGroups(listOf(DisplayGroup(), BadgeGroup())) + setGroups(listOf(DisplayGroup(), BadgeGroup(), TabsGroup())) } inner class DisplayGroup : Group { @@ -187,7 +187,7 @@ class LibrarySettingsSheet( private val comfortableGrid = Item.Radio(R.string.action_display_comfortable_grid, this) private val list = Item.Radio(R.string.action_display_list, this) - override val header = null + override val header = Item.Header(R.string.action_display_mode) override val items = listOf(compactGrid, comfortableGrid, list) override val footer = null @@ -222,7 +222,7 @@ class LibrarySettingsSheet( private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this) private val unreadBadge = Item.CheckboxGroup(R.string.action_display_unread_badge, this) - override val header = null + override val header = Item.Header(R.string.badges_header) override val items = listOf(downloadBadge, unreadBadge) override val footer = null @@ -241,6 +241,27 @@ class LibrarySettingsSheet( adapter.notifyItemChanged(item) } } + + inner class TabsGroup : Group { + private val showTabs = Item.CheckboxGroup(R.string.action_display_show_tabs, this) + + override val header = Item.Header(R.string.tabs_header) + override val items = listOf(showTabs) + override val footer = null + + override fun initModels() { + showTabs.checked = preferences.categoryTabs().get() + } + + override fun onItemClicked(item: Item) { + item as Item.CheckboxGroup + item.checked = !item.checked + when (item) { + showTabs -> preferences.categoryTabs().set((item.checked)) + } + adapter.notifyItemChanged(item) + } + } } open inner class Settings(context: Context, attrs: AttributeSet?) : diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheetDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheetDialog.kt index cc65172c7..80b196f3e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheetDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TabbedBottomSheetDialog.kt @@ -12,6 +12,7 @@ abstract class TabbedBottomSheetDialog(private val activity: Activity) : BottomS val binding: CommonTabbedSheetBinding = CommonTabbedSheetBinding.inflate(activity.layoutInflater) val adapter = LibrarySettingsSheetAdapter() + binding.pager.offscreenPageLimit = 2 binding.pager.adapter = adapter binding.tabs.setupWithViewPager(binding.pager) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 522303ed1..24214458c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,6 +86,7 @@ Comfortable grid Download badges Unread badges + Show category tabs Hide Pin Unpin @@ -418,6 +419,8 @@ Local Are you sure you want to remove selected manga? Also delete downloaded chapters + Badges + Tabs This source requires you to log in