mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-03 23:58:55 +01:00 
			
		
		
		
	Move library display settings out of filter sidebar
This commit is contained in:
		@@ -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())
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -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) }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user