ui: disable some options w/empty parents
Disable most playback and playlisting operations when an artist or playlist is empty.
This commit is contained in:
parent
2d0a74122f
commit
4210a8d247
5 changed files with 183 additions and 147 deletions
|
@ -237,7 +237,16 @@ class ArtistDetailFragment :
|
|||
findNavController().navigateUp()
|
||||
return
|
||||
}
|
||||
requireBinding().detailNormalToolbar.title = artist.name.resolve(requireContext())
|
||||
requireBinding().detailNormalToolbar.apply {
|
||||
title = artist.name.resolve(requireContext())
|
||||
|
||||
// Disable options that make no sense with an empty artist
|
||||
val playable = artist.songs.isNotEmpty()
|
||||
menu.findItem(R.id.action_play_next).isEnabled = playable
|
||||
menu.findItem(R.id.action_queue_add).isEnabled = playable
|
||||
menu.findItem(R.id.action_playlist_add).isEnabled = playable
|
||||
menu.findItem(R.id.action_share).isEnabled = playable
|
||||
}
|
||||
artistHeaderAdapter.setParent(artist)
|
||||
}
|
||||
|
||||
|
|
|
@ -255,8 +255,16 @@ class PlaylistDetailFragment :
|
|||
return
|
||||
}
|
||||
val binding = requireBinding()
|
||||
binding.detailNormalToolbar.title = playlist.name.resolve(requireContext())
|
||||
binding.detailEditToolbar.title = "Editing ${playlist.name.resolve(requireContext())}"
|
||||
binding.detailNormalToolbar.apply {
|
||||
title = playlist.name.resolve(requireContext())
|
||||
// Disable options that make no sense with an empty playlist
|
||||
val playable = playlist.songs.isNotEmpty()
|
||||
menu.findItem(R.id.action_play_next).isEnabled = playable
|
||||
menu.findItem(R.id.action_queue_add).isEnabled = playable
|
||||
menu.findItem(R.id.action_share).isEnabled = playable
|
||||
}
|
||||
binding.detailEditToolbar.title =
|
||||
getString(R.string.fmt_editing, playlist.name.resolve(requireContext()))
|
||||
playlistHeaderAdapter.setParent(playlist)
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.oxycblt.auxio.list
|
||||
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.annotation.MenuRes
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
|
@ -89,7 +88,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, song: Song) {
|
||||
logD("Launching new song menu: ${song.name}")
|
||||
|
||||
openMusicMenuImpl(anchor, menuRes) {
|
||||
openMenu(anchor, menuRes) {
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_play_next -> {
|
||||
playbackModel.playNext(song)
|
||||
|
@ -120,6 +120,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
error("Unexpected menu item selected")
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +136,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, album: Album) {
|
||||
logD("Launching new album menu: ${album.name}")
|
||||
|
||||
openMusicMenuImpl(anchor, menuRes) {
|
||||
openMenu(anchor, menuRes) {
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_play -> {
|
||||
playbackModel.play(album)
|
||||
|
@ -163,6 +166,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
error("Unexpected menu item selected")
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +182,16 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, artist: Artist) {
|
||||
logD("Launching new artist menu: ${artist.name}")
|
||||
|
||||
openMusicMenuImpl(anchor, menuRes) {
|
||||
openMenu(anchor, menuRes) {
|
||||
val playable = artist.songs.isNotEmpty()
|
||||
menu.findItem(R.id.action_play).isEnabled = playable
|
||||
menu.findItem(R.id.action_shuffle).isEnabled = playable
|
||||
menu.findItem(R.id.action_play_next).isEnabled = playable
|
||||
menu.findItem(R.id.action_queue_add).isEnabled = playable
|
||||
menu.findItem(R.id.action_playlist_add).isEnabled = playable
|
||||
menu.findItem(R.id.action_share).isEnabled = playable
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_play -> {
|
||||
playbackModel.play(artist)
|
||||
|
@ -203,6 +217,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
error("Unexpected menu item selected")
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,7 +233,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, genre: Genre) {
|
||||
logD("Launching new genre menu: ${genre.name}")
|
||||
|
||||
openMusicMenuImpl(anchor, menuRes) {
|
||||
openMenu(anchor, menuRes) {
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_play -> {
|
||||
playbackModel.play(genre)
|
||||
|
@ -243,6 +260,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
error("Unexpected menu item selected")
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +276,15 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, playlist: Playlist) {
|
||||
logD("Launching new playlist menu: ${playlist.name}")
|
||||
|
||||
openMusicMenuImpl(anchor, menuRes) {
|
||||
openMenu(anchor, menuRes) {
|
||||
val playable = playlist.songs.isNotEmpty()
|
||||
menu.findItem(R.id.action_play).isEnabled = playable
|
||||
menu.findItem(R.id.action_shuffle).isEnabled = playable
|
||||
menu.findItem(R.id.action_play_next).isEnabled = playable
|
||||
menu.findItem(R.id.action_queue_add).isEnabled = playable
|
||||
menu.findItem(R.id.action_share).isEnabled = playable
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_play -> {
|
||||
playbackModel.play(playlist)
|
||||
|
@ -286,17 +313,6 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
error("Unexpected menu item selected")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openMusicMenuImpl(
|
||||
anchor: View,
|
||||
@MenuRes menuRes: Int,
|
||||
onMenuItemClick: (MenuItem) -> Unit
|
||||
) {
|
||||
openMenu(anchor, menuRes) {
|
||||
setOnMenuItemClickListener { item ->
|
||||
onMenuItemClick(item)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,6 +284,7 @@ fun Context.share(parent: MusicParent) = share(parent.songs)
|
|||
|
||||
/**
|
||||
* Share an arbitrary list of [Song]s.
|
||||
*
|
||||
* @param songs The [Song]s to share.
|
||||
*/
|
||||
fun Context.share(songs: List<Song>) {
|
||||
|
|
|
@ -386,6 +386,8 @@
|
|||
|
||||
<!-- As in an amount of items that are selected -->
|
||||
<string name="fmt_selected">%d Selected</string>
|
||||
<!-- Currently editing a playlist -->
|
||||
<string name="fmt_editing">Editing %s</string>
|
||||
|
||||
<!-- As in "Disc 1", "Disc 2", etc. in a set -->
|
||||
<string name="fmt_disc_no">Disc %d</string>
|
||||
|
|
Loading…
Reference in a new issue