From a0a077eaaa359145268ec8e19855c92c50a3d4fd Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 5 Feb 2020 22:58:20 -0500 Subject: [PATCH] Move library display settings out of filter sidebar --- .../tachiyomi/ui/library/LibraryController.kt | 30 +++++++++- .../ui/library/LibraryNavigationView.kt | 57 +------------------ app/src/main/res/menu/library.xml | 21 +++++++ 3 files changed, 52 insertions(+), 56 deletions(-) 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 602eccc59c..0956a80e12 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 @@ -191,8 +191,6 @@ class LibraryController( when (group) { is LibraryNavigationView.FilterGroup -> onFilterChanged() is LibraryNavigationView.SortGroup -> onSortChanged() - is LibraryNavigationView.DisplayGroup -> reattachAdapter() - is LibraryNavigationView.BadgeGroup -> onDownloadBadgeChanged() } } @@ -360,6 +358,16 @@ class LibraryController( // Tint icon if there's a filter active val filterColor = if (navView.hasActiveFilters()) Color.rgb(255, 238, 7) else Color.WHITE DrawableCompat.setTint(filterItem.icon, filterColor) + + // Display submenu + if (preferences.libraryAsList().getOrDefault()) { + menu.findItem(R.id.action_display_list).isChecked = true + } else { + menu.findItem(R.id.action_display_grid).isChecked = true + } + if (preferences.downloadBadge().getOrDefault()) { + menu.findItem(R.id.action_display_download_badge).isChecked = true + } } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -371,6 +379,24 @@ class LibraryController( R.id.action_update_library -> { activity?.let { LibraryUpdateService.start(it) } } + + // Display submenu + R.id.action_display_grid -> { + item.isChecked = true + preferences.libraryAsList().set(false) + reattachAdapter() + } + R.id.action_display_list -> { + item.isChecked = true + preferences.libraryAsList().set(true) + reattachAdapter() + } + R.id.action_display_download_badge -> { + item.isChecked = !item.isChecked + preferences.downloadBadge().set(item.isChecked) + onDownloadBadgeChanged() + } + R.id.action_source_migration -> { router.pushController(MigrationController().withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt index febbceb06b..1456a1dc62 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt @@ -25,7 +25,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A /** * List of groups shown in the view. */ - private val groups = listOf(FilterGroup(), SortGroup(), DisplayGroup(), BadgeGroup()) + private val groups = listOf(FilterGroup(), SortGroup()) /** * Adapter instance. @@ -79,7 +79,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A override val header = Item.Header(R.string.action_filter) - override val footer = Item.Separator() + override val footer = null override fun initModels() { downloaded.checked = preferences.filterDownloaded().getOrDefault() @@ -121,7 +121,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A override val header = Item.Header(R.string.action_sort) - override val footer = Item.Separator() + override val footer = null override fun initModels() { val sorting = preferences.librarySortingMode().getOrDefault() @@ -163,55 +163,4 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A } } - - inner class BadgeGroup : Group { - private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this) - override val header = null - override val footer = null - override val items = listOf(downloadBadge) - override fun initModels() { - downloadBadge.checked = preferences.downloadBadge().getOrDefault() - } - - override fun onItemClicked(item: Item) { - item as Item.CheckboxGroup - item.checked = !item.checked - preferences.downloadBadge().set((item.checked)) - adapter.notifyItemChanged(item) - } - } - - /** - * Display group, to show the library as a list or a grid. - */ - inner class DisplayGroup : Group { - - private val grid = Item.Radio(R.string.action_display_grid, this) - - private val list = Item.Radio(R.string.action_display_list, this) - - override val items = listOf(grid, list) - - override val header = Item.Header(R.string.action_display) - - override val footer = null - - override fun initModels() { - val asList = preferences.libraryAsList().getOrDefault() - grid.checked = !asList - list.checked = asList - } - - override fun onItemClicked(item: Item) { - item as Item.Radio - if (item.checked) return - - item.group.items.forEach { (it as Item.Radio).checked = false } - item.checked = true - - preferences.libraryAsList().set(item == list) - - item.group.items.forEach { adapter.notifyItemChanged(it) } - } - } } diff --git a/app/src/main/res/menu/library.xml b/app/src/main/res/menu/library.xml index 337f5feaa7..1375104e80 100644 --- a/app/src/main/res/menu/library.xml +++ b/app/src/main/res/menu/library.xml @@ -22,6 +22,27 @@ android:title="@string/action_update_library" app:showAsAction="ifRoom" /> + + + + + + + + + + +