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()
|
findNavController().navigateUp()
|
||||||
return
|
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)
|
artistHeaderAdapter.setParent(artist)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,8 +255,16 @@ class PlaylistDetailFragment :
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val binding = requireBinding()
|
val binding = requireBinding()
|
||||||
binding.detailNormalToolbar.title = playlist.name.resolve(requireContext())
|
binding.detailNormalToolbar.apply {
|
||||||
binding.detailEditToolbar.title = "Editing ${playlist.name.resolve(requireContext())}"
|
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)
|
playlistHeaderAdapter.setParent(playlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
package org.oxycblt.auxio.list
|
package org.oxycblt.auxio.list
|
||||||
|
|
||||||
import android.view.MenuItem
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.MenuRes
|
import androidx.annotation.MenuRes
|
||||||
import androidx.appcompat.widget.PopupMenu
|
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) {
|
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, song: Song) {
|
||||||
logD("Launching new song menu: ${song.name}")
|
logD("Launching new song menu: ${song.name}")
|
||||||
|
|
||||||
openMusicMenuImpl(anchor, menuRes) {
|
openMenu(anchor, menuRes) {
|
||||||
|
setOnMenuItemClickListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.action_play_next -> {
|
R.id.action_play_next -> {
|
||||||
playbackModel.playNext(song)
|
playbackModel.playNext(song)
|
||||||
|
@ -120,6 +120,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
||||||
error("Unexpected menu item selected")
|
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) {
|
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, album: Album) {
|
||||||
logD("Launching new album menu: ${album.name}")
|
logD("Launching new album menu: ${album.name}")
|
||||||
|
|
||||||
openMusicMenuImpl(anchor, menuRes) {
|
openMenu(anchor, menuRes) {
|
||||||
|
setOnMenuItemClickListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.action_play -> {
|
R.id.action_play -> {
|
||||||
playbackModel.play(album)
|
playbackModel.play(album)
|
||||||
|
@ -163,6 +166,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
||||||
error("Unexpected menu item selected")
|
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) {
|
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, artist: Artist) {
|
||||||
logD("Launching new artist menu: ${artist.name}")
|
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) {
|
when (it.itemId) {
|
||||||
R.id.action_play -> {
|
R.id.action_play -> {
|
||||||
playbackModel.play(artist)
|
playbackModel.play(artist)
|
||||||
|
@ -203,6 +217,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
||||||
error("Unexpected menu item selected")
|
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) {
|
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, genre: Genre) {
|
||||||
logD("Launching new genre menu: ${genre.name}")
|
logD("Launching new genre menu: ${genre.name}")
|
||||||
|
|
||||||
openMusicMenuImpl(anchor, menuRes) {
|
openMenu(anchor, menuRes) {
|
||||||
|
setOnMenuItemClickListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.action_play -> {
|
R.id.action_play -> {
|
||||||
playbackModel.play(genre)
|
playbackModel.play(genre)
|
||||||
|
@ -243,6 +260,8 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
||||||
error("Unexpected menu item selected")
|
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) {
|
protected fun openMusicMenu(anchor: View, @MenuRes menuRes: Int, playlist: Playlist) {
|
||||||
logD("Launching new playlist menu: ${playlist.name}")
|
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) {
|
when (it.itemId) {
|
||||||
R.id.action_play -> {
|
R.id.action_play -> {
|
||||||
playbackModel.play(playlist)
|
playbackModel.play(playlist)
|
||||||
|
@ -286,17 +313,6 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
||||||
error("Unexpected menu item selected")
|
error("Unexpected menu item selected")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun openMusicMenuImpl(
|
|
||||||
anchor: View,
|
|
||||||
@MenuRes menuRes: Int,
|
|
||||||
onMenuItemClick: (MenuItem) -> Unit
|
|
||||||
) {
|
|
||||||
openMenu(anchor, menuRes) {
|
|
||||||
setOnMenuItemClickListener { item ->
|
|
||||||
onMenuItemClick(item)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,6 +284,7 @@ fun Context.share(parent: MusicParent) = share(parent.songs)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share an arbitrary list of [Song]s.
|
* Share an arbitrary list of [Song]s.
|
||||||
|
*
|
||||||
* @param songs The [Song]s to share.
|
* @param songs The [Song]s to share.
|
||||||
*/
|
*/
|
||||||
fun Context.share(songs: List<Song>) {
|
fun Context.share(songs: List<Song>) {
|
||||||
|
|
|
@ -386,6 +386,8 @@
|
||||||
|
|
||||||
<!-- As in an amount of items that are selected -->
|
<!-- As in an amount of items that are selected -->
|
||||||
<string name="fmt_selected">%d Selected</string>
|
<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 -->
|
<!-- As in "Disc 1", "Disc 2", etc. in a set -->
|
||||||
<string name="fmt_disc_no">Disc %d</string>
|
<string name="fmt_disc_no">Disc %d</string>
|
||||||
|
|
Loading…
Reference in a new issue