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:
parent
829e2a42c4
commit
67e67ca1d0
6 changed files with 29 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -84,7 +84,9 @@ class PlaybackPanelFragment :
|
|||
}
|
||||
|
||||
binding.playbackToolbar.apply {
|
||||
setNavigationOnClickListener { navModel.mainNavigateTo(MainNavigationAction.Collapse) }
|
||||
setNavigationOnClickListener {
|
||||
navModel.mainNavigateTo(MainNavigationAction.ClosePlaybackPanel)
|
||||
}
|
||||
setOnMenuItemClickListener(this@PlaybackPanelFragment)
|
||||
}
|
||||
|
||||
|
|
|
@ -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].
|
||||
|
|
Loading…
Reference in a new issue