Revert "Move library display settings out of filter sidebar"

This reverts commit a0a077eaaa
This commit is contained in:
arkon 2020-03-28 16:12:42 -04:00
parent bb43e2aa03
commit 40c934c544
3 changed files with 56 additions and 50 deletions

View File

@ -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)

View File

@ -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) }
}
}
}

View File

@ -25,24 +25,4 @@
app:iconTint="?attr/colorOnPrimary"
app:showAsAction="ifRoom" />
<item
android:title="@string/action_display"
app:showAsAction="never">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/action_display_grid"
android:title="@string/action_display_grid" />
<item
android:id="@+id/action_display_list"
android:title="@string/action_display_list" />
</group>
<item
android:id="@+id/action_display_download_badge"
android:checkable="true"
android:title="@string/action_display_download_badge" />
</menu>
</item>
</menu>