playback: generalize make playback panel opening

If the user clicks on the playback bar in any context, including the
queue view, open the playback panel.

This adds another means to closing the queue that does not involve
swiping.

Resolves #402.
This commit is contained in:
Alexander Capehart 2023-03-25 15:30:13 -06:00
parent 829e2a42c4
commit 67e67ca1d0
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
6 changed files with 29 additions and 10 deletions

View file

@ -1,5 +1,10 @@
# Changelog
## dev
## What's Improved
- Added ability to click on the playback bar to exit the queue view
## 3.0.4
#### What's New

View file

@ -268,8 +268,8 @@ class MainFragment :
}
when (action) {
is MainNavigationAction.Expand -> tryExpandSheets()
is MainNavigationAction.Collapse -> tryCollapseSheets()
is MainNavigationAction.OpenPlaybackPanel -> tryOpenPlaybackPanel()
is MainNavigationAction.ClosePlaybackPanel -> tryClosePlaybackPanel()
is MainNavigationAction.Directions ->
findNavController().navigateSafe(action.directions)
}
@ -279,7 +279,7 @@ class MainFragment :
private fun handleExploreNavigation(item: Music?) {
if (item != null) {
tryCollapseSheets()
tryClosePlaybackPanel()
}
}
@ -318,22 +318,33 @@ class MainFragment :
}
}
private fun tryExpandSheets() {
private fun tryOpenPlaybackPanel() {
val binding = requireBinding()
val playbackSheetBehavior =
binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior
if (playbackSheetBehavior.state == BackportBottomSheetBehavior.STATE_COLLAPSED) {
// Playback sheet is not expanded and not hidden, we can expand it.
playbackSheetBehavior.state = BackportBottomSheetBehavior.STATE_EXPANDED
return
}
val queueSheetBehavior =
(binding.queueSheet.coordinatorLayoutBehavior ?: return) as QueueBottomSheetBehavior
if (playbackSheetBehavior.state == BackportBottomSheetBehavior.STATE_EXPANDED &&
queueSheetBehavior.state == BackportBottomSheetBehavior.STATE_EXPANDED) {
// Queue sheet and playback sheet is expanded, close the queue sheet so the
// playback panel can eb shown.
queueSheetBehavior.state = BackportBottomSheetBehavior.STATE_COLLAPSED
}
}
private fun tryCollapseSheets() {
private fun tryClosePlaybackPanel() {
val binding = requireBinding()
val playbackSheetBehavior =
binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior
if (playbackSheetBehavior.state == BackportBottomSheetBehavior.STATE_EXPANDED) {
// Make sure the queue is also collapsed here.
// Playback sheet (and possibly queue) needs to be collapsed.
val queueSheetBehavior =
binding.queueSheet.coordinatorLayoutBehavior as QueueBottomSheetBehavior?
playbackSheetBehavior.state = BackportBottomSheetBehavior.STATE_COLLAPSED

View file

@ -80,6 +80,7 @@ class MusicViewModel @Inject constructor(private val musicRepository: MusicRepos
/**
* Create a new generic playlist.
*
* @param name The name of the new playlist. If null, the user will be prompted for a name.
*/
fun createPlaylist(name: String? = null) {

View file

@ -56,7 +56,7 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
// --- UI SETUP ---
binding.root.apply {
setOnClickListener { navModel.mainNavigateTo(MainNavigationAction.Expand) }
setOnClickListener { navModel.mainNavigateTo(MainNavigationAction.OpenPlaybackPanel) }
setOnLongClickListener {
playbackModel.song.value?.let(navModel::exploreNavigateTo)
true

View file

@ -84,7 +84,9 @@ class PlaybackPanelFragment :
}
binding.playbackToolbar.apply {
setNavigationOnClickListener { navModel.mainNavigateTo(MainNavigationAction.Collapse) }
setNavigationOnClickListener {
navModel.mainNavigateTo(MainNavigationAction.ClosePlaybackPanel)
}
setOnMenuItemClickListener(this@PlaybackPanelFragment)
}

View file

@ -128,10 +128,10 @@ class NavigationViewModel : ViewModel() {
*/
sealed class MainNavigationAction {
/** Expand the playback panel. */
object Expand : MainNavigationAction()
object OpenPlaybackPanel : MainNavigationAction()
/** Collapse the playback bottom sheet. */
object Collapse : MainNavigationAction()
object ClosePlaybackPanel : MainNavigationAction()
/**
* Navigate to the given [NavDirections].