detail: extend smart queue disabling to detail

Add the queue disabling functionality from 47fca78 to the album detail
fragment as well.
This commit is contained in:
OxygenCobalt 2022-01-21 19:59:00 -07:00
parent 6e6252b033
commit eadf4cc86d
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
6 changed files with 50 additions and 21 deletions

View file

@ -21,7 +21,7 @@ Auxio is a local music player with a fast, reliable UI/UX without the many usele
I primarily built Auxio for myself, but you can use it too, I guess. I primarily built Auxio for myself, but you can use it too, I guess.
**This branch is the development version of the repository. For a stable version, see the master branch.** **The default branch is the development version of the repository. For a stable version, see the master branch.**
## Screenshots ## Screenshots

View file

@ -23,10 +23,12 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.children
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearSmoothScroller import androidx.recyclerview.widget.LinearSmoothScroller
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentDetailBinding
import org.oxycblt.auxio.detail.recycler.AlbumDetailAdapter import org.oxycblt.auxio.detail.recycler.AlbumDetailAdapter
import org.oxycblt.auxio.music.ActionHeader import org.oxycblt.auxio.music.ActionHeader
import org.oxycblt.auxio.music.Album import org.oxycblt.auxio.music.Album
@ -43,6 +45,8 @@ import org.oxycblt.auxio.util.showToast
/** /**
* The [DetailFragment] for an album. * The [DetailFragment] for an album.
* @author OxygenCobalt * @author OxygenCobalt
* TODO: Disable queue adding when there is no playback here too, however make it so that
* it updates when the song changes.
*/ */
class AlbumDetailFragment : DetailFragment() { class AlbumDetailFragment : DetailFragment() {
private val args: AlbumDetailFragmentArgs by navArgs() private val args: AlbumDetailFragmentArgs by navArgs()
@ -65,12 +69,20 @@ class AlbumDetailFragment : DetailFragment() {
binding.lifecycleOwner = viewLifecycleOwner binding.lifecycleOwner = viewLifecycleOwner
setupToolbar(detailModel.curAlbum.value!!, R.menu.menu_album_detail) { itemId -> setupToolbar(detailModel.curAlbum.value!!, R.menu.menu_album_detail) { itemId ->
if (itemId == R.id.action_queue_add) { when (itemId) {
R.id.action_play_next -> {
playbackModel.playNext(detailModel.curAlbum.value!!) playbackModel.playNext(detailModel.curAlbum.value!!)
requireContext().showToast(R.string.lbl_queue_added) requireContext().showToast(R.string.lbl_queue_added)
true true
} else { }
false
R.id.action_queue_add -> {
playbackModel.addToQueue(detailModel.curAlbum.value!!)
requireContext().showToast(R.string.lbl_queue_added)
true
}
else -> false
} }
} }
@ -79,6 +91,8 @@ class AlbumDetailFragment : DetailFragment() {
item is Header || item is ActionHeader || item is Album item is Header || item is ActionHeader || item is Album
} }
updateQueueActions(playbackModel.song.value, binding)
// -- DETAILVIEWMODEL SETUP --- // -- DETAILVIEWMODEL SETUP ---
detailModel.albumData.observe(viewLifecycleOwner) { data -> detailModel.albumData.observe(viewLifecycleOwner) { data ->
@ -137,6 +151,8 @@ class AlbumDetailFragment : DetailFragment() {
// --- PLAYBACKVIEWMODEL SETUP --- // --- PLAYBACKVIEWMODEL SETUP ---
playbackModel.song.observe(viewLifecycleOwner) { song -> playbackModel.song.observe(viewLifecycleOwner) { song ->
updateQueueActions(song, binding)
if (playbackModel.playbackMode.value == PlaybackMode.IN_ALBUM && if (playbackModel.playbackMode.value == PlaybackMode.IN_ALBUM &&
playbackModel.parent.value?.id == detailModel.curAlbum.value!!.id playbackModel.parent.value?.id == detailModel.curAlbum.value!!.id
) { ) {
@ -152,6 +168,17 @@ class AlbumDetailFragment : DetailFragment() {
return binding.root return binding.root
} }
/**
* Updates the queue actions when
*/
private fun updateQueueActions(song: Song?, binding: FragmentDetailBinding) {
for (item in binding.detailToolbar.menu.children) {
if (item.itemId == R.id.action_play_next || item.itemId == R.id.action_queue_add) {
item.isEnabled = song != null
}
}
}
/** /**
* Scroll to an song using its [id]. * Scroll to an song using its [id].
*/ */

View file

@ -57,19 +57,19 @@ abstract class DetailFragment : Fragment() {
/** /**
* Shortcut method for doing setup of the detail toolbar. * Shortcut method for doing setup of the detail toolbar.
* @param data Parent data to use as the toolbar title * @param data Parent data to use as the toolbar title
* @param menu Menu resource to use * @param menuId Menu resource to use
* @param onMenuClick (Optional) a click listener for that menu * @param onMenuClick (Optional) a click listener for that menu
*/ */
protected fun setupToolbar( protected fun setupToolbar(
data: MusicParent, data: MusicParent,
@MenuRes menu: Int = -1, @MenuRes menuId: Int = -1,
onMenuClick: ((itemId: Int) -> Boolean)? = null onMenuClick: ((itemId: Int) -> Boolean)? = null
) { ) {
binding.detailToolbar.apply { binding.detailToolbar.apply {
title = data.resolvedName title = data.resolvedName
if (menu != -1) { if (menuId != -1) {
inflateMenu(menu) inflateMenu(menuId)
} }
setNavigationOnClickListener { setNavigationOnClickListener {

View file

@ -214,8 +214,9 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
*/ */
fun removeQueueDataItem(adapterIndex: Int, apply: () -> Unit) { fun removeQueueDataItem(adapterIndex: Int, apply: () -> Unit) {
val adjusted = adapterIndex + (playbackManager.queue.size - mNextUp.value!!.size) val adjusted = adapterIndex + (playbackManager.queue.size - mNextUp.value!!.size)
logD("$adjusted")
if (adjusted in mNextUp.value!!.indices) { if (adjusted in playbackManager.queue.indices) {
apply() apply()
playbackManager.removeQueueItem(adjusted) playbackManager.removeQueueItem(adjusted)
} }
@ -230,7 +231,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
val from = adapterFrom + delta val from = adapterFrom + delta
val to = adapterTo + delta val to = adapterTo + delta
if (from in mNextUp.value!!.indices && to in mNextUp.value!!.indices) { if (from in playbackManager.queue.indices && to in playbackManager.queue.indices) {
apply() apply()
playbackManager.moveQueueItems(from, to) playbackManager.moveQueueItems(from, to)
return true return true

View file

@ -23,6 +23,7 @@ import androidx.annotation.IdRes
import androidx.annotation.MenuRes import androidx.annotation.MenuRes
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.core.view.children
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
@ -82,9 +83,11 @@ class ActionMenu(
inflate(menuRes) inflate(menuRes)
// Disable any queue options if we don't have anything playing. // Disable any queue options if we don't have anything playing.
val queueEnabled = playbackModel.song.value != null for (item in menu.children) {
menu.findItem(R.id.action_play_next)?.isEnabled = queueEnabled if (item.itemId == R.id.action_play_next || item.itemId == R.id.action_queue_add) {
menu.findItem(R.id.action_queue_add)?.isEnabled = queueEnabled item.isEnabled = playbackModel.song.value != null
}
}
setOnMenuItemClickListener { item -> setOnMenuItemClickListener { item ->
onMenuClick(item.itemId) onMenuClick(item.itemId)

View file

@ -23,7 +23,7 @@
<string name="lbl_sort">排序方式</string> <string name="lbl_sort">排序方式</string>
<string name="lbl_sort_name">名称</string> <string name="lbl_sort_name">名称</string>
<string name="lbl_sort_artist">艺术家</string> <string name="lbl_sort_artist">艺术家</string>
<string name="lbl_sort_album">专辑/string> <string name="lbl_sort_album">专辑</string>
<string name="lbl_sort_year">年份</string> <string name="lbl_sort_year">年份</string>
<string name="lbl_sort_asc">首字符(正序)</string> <string name="lbl_sort_asc">首字符(正序)</string>
@ -169,12 +169,10 @@
<string name="fmt_songs_loaded">已加载 %d 首曲目</string> <string name="fmt_songs_loaded">已加载 %d 首曲目</string>
<plurals name="fmt_song_count"> <plurals name="fmt_song_count">
<item quantity="one">%d 首歌曲</item> <item quantity="other">"%d 首歌曲"</item>
<item quantity="other">%d 首歌曲</item>
</plurals> </plurals>
<plurals name="fmt_album_count"> <plurals name="fmt_album_count">
<item quantity="one">%d 张专辑</item> <item quantity="other">"%d 张专辑"</item>
<item quantity="other">%d 张专辑</item>
</plurals> </plurals>
</resources> </resources>