Change sorting menu to dedicated action
Make the sorting menu on LibraryFragment an action instead of just some things in the overflow menu to improve consistency and accesibility.
This commit is contained in:
parent
260e7f71cf
commit
ee1d05d347
5 changed files with 70 additions and 52 deletions
|
@ -7,7 +7,6 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.forEach
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
|
@ -29,6 +28,7 @@ import org.oxycblt.auxio.music.Header
|
|||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.applyColor
|
||||
import org.oxycblt.auxio.ui.getLandscapeSpans
|
||||
import org.oxycblt.auxio.ui.isLandscape
|
||||
|
@ -37,6 +37,7 @@ import org.oxycblt.auxio.ui.setupAlbumActions
|
|||
import org.oxycblt.auxio.ui.setupArtistActions
|
||||
import org.oxycblt.auxio.ui.setupGenreActions
|
||||
import org.oxycblt.auxio.ui.setupSongActions
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
||||
/**
|
||||
* A [Fragment] that shows a custom list of [Genre], [Artist], or [Album] data. Also allows for
|
||||
|
@ -57,51 +58,45 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
|||
): View {
|
||||
val binding = FragmentLibraryBinding.inflate(inflater)
|
||||
|
||||
val libraryAdapter = LibraryAdapter(
|
||||
doOnClick = this::onItemSelection,
|
||||
doOnLongClick = this::showActionsForItem
|
||||
)
|
||||
val libraryAdapter = LibraryAdapter(::onItemSelection, ::showActionsForItem)
|
||||
val searchAdapter = SearchAdapter(::onItemSelection, ::showActionsForItem)
|
||||
|
||||
val searchAdapter = SearchAdapter(
|
||||
doOnClick = this::onItemSelection,
|
||||
doOnLongClick = this::showActionsForItem
|
||||
)
|
||||
val sortAction = binding.libraryToolbar.menu.findItem(R.id.submenu_sorting)
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
binding.libraryToolbar.apply {
|
||||
overflowIcon = ContextCompat.getDrawable(
|
||||
requireContext(), R.drawable.ic_sort_none
|
||||
)
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
if (it.itemId != R.id.action_search) {
|
||||
libraryModel.updateSortMode(it.itemId)
|
||||
} else {
|
||||
// Then also do a basic animation on the enter transition. Not done on exit
|
||||
// because that causes issues with the SearchView.
|
||||
TransitionManager.beginDelayedTransition(
|
||||
binding.libraryToolbar, Fade()
|
||||
)
|
||||
it.expandActionView()
|
||||
when (it.itemId) {
|
||||
R.id.action_search -> {
|
||||
TransitionManager.beginDelayedTransition(
|
||||
binding.libraryToolbar, Fade()
|
||||
)
|
||||
it.expandActionView()
|
||||
}
|
||||
|
||||
R.id.submenu_sorting -> {
|
||||
}
|
||||
|
||||
else -> libraryModel.updateSortMode(it.itemId)
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
menu.apply {
|
||||
val item = findItem(R.id.action_search)
|
||||
val searchView = item.actionView as SearchView
|
||||
val searchAction = findItem(R.id.action_search)
|
||||
val searchView = searchAction.actionView as SearchView
|
||||
|
||||
searchView.queryHint = getString(R.string.hint_search_library)
|
||||
searchView.maxWidth = Int.MAX_VALUE
|
||||
searchView.setOnQueryTextListener(this@LibraryFragment)
|
||||
|
||||
item.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||
searchAction.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||
binding.libraryRecycler.adapter = searchAdapter
|
||||
setGroupVisible(R.id.group_sorting, false)
|
||||
item.isVisible = false
|
||||
sortAction.isVisible = false
|
||||
|
||||
libraryModel.resetQuery()
|
||||
|
||||
|
@ -110,8 +105,8 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
|||
|
||||
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||
binding.libraryRecycler.adapter = libraryAdapter
|
||||
setGroupVisible(R.id.group_sorting, true)
|
||||
item.isVisible = true
|
||||
sortAction.isVisible = true
|
||||
|
||||
libraryModel.resetQuery()
|
||||
|
||||
|
@ -157,10 +152,13 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
|||
libraryModel.sortMode.observe(viewLifecycleOwner) { mode ->
|
||||
logD("Updating sort mode to $mode")
|
||||
|
||||
// Then update the menu item in the toolbar to reflect the new mode
|
||||
binding.libraryToolbar.menu.forEach {
|
||||
if (it.itemId == libraryModel.sortMode.value!!.toMenuId()) {
|
||||
it.applyColor(resolveAttr(requireContext(), R.attr.colorPrimary))
|
||||
val modeId = mode.toMenuId()
|
||||
|
||||
// Highlight the item instead of using a checkable since the checkables just...wont
|
||||
// respond to any attempts to make them checked or not.
|
||||
sortAction.subMenu.forEach {
|
||||
if (it.itemId == modeId) {
|
||||
it.applyColor(accent.first.toColor(requireContext()))
|
||||
} else {
|
||||
it.applyColor(resolveAttr(requireContext(), android.R.attr.textColorPrimary))
|
||||
}
|
||||
|
|
|
@ -235,6 +235,11 @@ fun PopupMenu.setupArtistActions(artist: Artist, playbackModel: PlaybackViewMode
|
|||
fun PopupMenu.setupGenreActions(genre: Genre, playbackModel: PlaybackViewModel) {
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_play -> {
|
||||
playbackModel.playGenre(genre, true)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_shuffle -> {
|
||||
playbackModel.playGenre(genre, true)
|
||||
true
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_play"
|
||||
android:icon="@drawable/ic_play"
|
||||
android:title="@string/label_play" />
|
||||
<item
|
||||
android:id="@+id/action_shuffle"
|
||||
android:icon="@drawable/ic_shuffle"
|
||||
android:title="@string/label_shuffle"
|
||||
app:showAsAction="ifRoom" />
|
||||
android:title="@string/label_shuffle" />
|
||||
</menu>
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<menu xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
|
@ -7,23 +8,33 @@
|
|||
android:icon="@drawable/ic_search"
|
||||
android:title="@string/label_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView|always" />
|
||||
app:showAsAction="collapseActionView|always"
|
||||
tools:ignore="AlwaysShowAction" />
|
||||
|
||||
<group android:id="@+id/group_sorting">
|
||||
<item
|
||||
android:id="@+id/option_sort_none"
|
||||
android:contentDescription="@string/description_sort_none"
|
||||
android:icon="@drawable/ic_sort_none"
|
||||
android:title="@string/label_sort_none" />
|
||||
<item
|
||||
android:id="@+id/option_sort_alpha_down"
|
||||
android:contentDescription="@string/description_sort_alpha_down"
|
||||
android:icon="@drawable/ic_sort_alpha_down"
|
||||
android:title="@string/label_sort_alpha_down" />
|
||||
<item
|
||||
android:id="@+id/option_sort_alpha_up"
|
||||
android:contentDescription="@string/description_sort_alpha_up"
|
||||
android:icon="@drawable/ic_sort_alpha_up"
|
||||
android:title="@string/label_sort_alpha_up" />
|
||||
</group>
|
||||
<!--
|
||||
Has to be always since android mangles this action when I make it invisible and then visible again
|
||||
I hate this platform so much
|
||||
-->
|
||||
<item
|
||||
android:id="@+id/submenu_sorting"
|
||||
android:title="@string/label_sort"
|
||||
android:icon="@drawable/ic_sort_none"
|
||||
app:showAsAction="always">
|
||||
<menu>
|
||||
<group android:id="@+id/group_sorting">
|
||||
<item
|
||||
android:id="@+id/option_sort_none"
|
||||
android:contentDescription="@string/description_sort_none"
|
||||
android:title="@string/label_sort_none" />
|
||||
<item
|
||||
android:id="@+id/option_sort_alpha_down"
|
||||
android:contentDescription="@string/description_sort_alpha_down"
|
||||
android:title="@string/label_sort_alpha_down" />
|
||||
<item
|
||||
android:id="@+id/option_sort_alpha_up"
|
||||
android:contentDescription="@string/description_sort_alpha_up"
|
||||
android:title="@string/label_sort_alpha_up" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
</menu>
|
|
@ -13,6 +13,7 @@
|
|||
<string name="label_albums">Albums</string>
|
||||
<string name="label_search">Search</string>
|
||||
|
||||
<string name="label_sort">Sort</string>
|
||||
<string name="label_sort_none">Default</string>
|
||||
<string name="label_sort_alpha_down">A-Z</string>
|
||||
<string name="label_sort_alpha_up">Z-A</string>
|
||||
|
|
Loading…
Reference in a new issue