From 40c934c544aeed18b6a3c89b30b247f544385869 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 28 Mar 2020 16:12:42 -0400 Subject: [PATCH] Revert "Move library display settings out of filter sidebar" This reverts commit a0a077eaaa359145268ec8e19855c92c50a3d4fd --- .../tachiyomi/ui/library/LibraryController.kt | 29 +--------- .../ui/library/LibraryNavigationView.kt | 57 ++++++++++++++++++- app/src/main/res/menu/library.xml | 20 ------- 3 files changed, 56 insertions(+), 50 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 566e3fb9c7..ce38368317 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 @@ -198,6 +198,8 @@ class LibraryController( when (group) { is LibraryNavigationView.FilterGroup -> onFilterChanged() is LibraryNavigationView.SortGroup -> onSortChanged() + is LibraryNavigationView.DisplayGroup -> reattachAdapter() + is LibraryNavigationView.BadgeGroup -> onDownloadBadgeChanged() } } @@ -371,16 +373,6 @@ class LibraryController( val filterColor = activity!!.getResourceColor(R.attr.colorFilterActive) 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 { @@ -392,23 +384,6 @@ 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() - } } return super.onOptionsItemSelected(item) 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 3a118fc1dd..a7eb801dd8 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()) + private val groups = listOf(FilterGroup(), SortGroup(), DisplayGroup(), BadgeGroup()) /** * 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 = null + override val footer = Item.Separator() 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 = null + override val footer = Item.Separator() override fun initModels() { val sorting = preferences.librarySortingMode().getOrDefault() @@ -162,4 +162,55 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A item.group.items.forEach { adapter.notifyItemChanged(it) } } } + + 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 de1430740f..a34649976e 100644 --- a/app/src/main/res/menu/library.xml +++ b/app/src/main/res/menu/library.xml @@ -25,24 +25,4 @@ app:iconTint="?attr/colorOnPrimary" app:showAsAction="ifRoom" /> - - - - - - - - - - -