From e39d4d879c97e870451949b61146b75198fa6532 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Fri, 2 Jun 2023 14:25:56 -0600 Subject: [PATCH] ui: fix stuck sheet when playback ends Fix an issue where the playback sheet will suddenly become "stuck" when playback ends, preventing back navigation or playing new tracks. This is, once again, caused by bottom sheet insanity. It does not expose the target state of a sheet at all when it's settling, making Auxio believe that it has to repeatedly "fix" the state of a hiding playback sheet and leading to those aforementioned issues. Fix this by band-aiding it with yet a n o t h e r bottom sheet behavior extension that exposes the target state. This will be eventually be used in the whole bottom sheet flow, as it allows me to abort in-progress sheet transitions, but I'm not going to rock the boat like this in a patch release. Probably 3.2.0. Resolves #464. --- CHANGELOG.md | 2 ++ .../bottomsheet/BackportBottomSheetBehavior.java | 13 +++++++++++++ .../main/java/org/oxycblt/auxio/MainFragment.kt | 16 +++++++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8239410b2..122ed0923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ within it - Fixed incorrect songs being displayed when adding albums to the end of the queue - Fixed freezing occuring when scrolling through large music libraries - Fixed app not responding once music loading completes for large libraries +- Fixed crash when the last song of the queue gets removed while playing +- Fixed playback UI not re-appearing after playback ends #### What's Changed - Android Lollipop and Marshmallow support have been dropped diff --git a/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java b/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java index e8c26ff3b..c6560c151 100644 --- a/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java +++ b/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java @@ -1336,6 +1336,19 @@ public class BackportBottomSheetBehavior extends CoordinatorLayo return state; } + /** + * Gets the target state of the bottom sheet if currently attempting to settle, or the current + * state otherwise. + * @return One of {@link #STATE_EXPANDED}, {@link #STATE_HALF_EXPANDED}, {@link #STATE_COLLAPSED}, + * or {@link #STATE_DRAGGING} + */ + public int getTargetState() { + if (state != STATE_SETTLING) { + return state; + } + return stateSettlingTracker.targetState; + } + void setStateInternal(@State int state) { if (this.state == state) { return; diff --git a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt index 4a456100c..7c8d558ac 100644 --- a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt @@ -160,7 +160,7 @@ class MainFragment : fillColor = context.getAttrColorCompat(MR.attr.colorSurface) elevation = context.getDimen(R.dimen.elevation_normal) } - // Apply bar insets for the queue's RecyclerView to usee. + // Apply bar insets for the queue's RecyclerView to use. setOnApplyWindowInsetsListener { v, insets -> v.updatePadding(top = insets.systemBarInsetsCompat.top) insets @@ -436,7 +436,7 @@ class MainFragment : val binding = requireBinding() val playbackSheetBehavior = binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior - if (playbackSheetBehavior.state == BackportBottomSheetBehavior.STATE_HIDDEN) { + if (playbackSheetBehavior.targetState == BackportBottomSheetBehavior.STATE_HIDDEN) { logD("Unhiding and enabling playback sheet") val queueSheetBehavior = binding.queueSheet.coordinatorLayoutBehavior as QueueBottomSheetBehavior? @@ -454,7 +454,7 @@ class MainFragment : val binding = requireBinding() val playbackSheetBehavior = binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior - if (playbackSheetBehavior.state != BackportBottomSheetBehavior.STATE_HIDDEN) { + if (playbackSheetBehavior.targetState != BackportBottomSheetBehavior.STATE_HIDDEN) { val queueSheetBehavior = binding.queueSheet.coordinatorLayoutBehavior as QueueBottomSheetBehavior? @@ -473,6 +473,8 @@ class MainFragment : } } + // TODO: Use targetState more + private class SheetBackPressedCallback( private val playbackSheetBehavior: PlaybackBottomSheetBehavior<*>, private val queueSheetBehavior: QueueBottomSheetBehavior<*>? @@ -499,13 +501,13 @@ class MainFragment : } private fun playbackSheetShown() = - playbackSheetBehavior.state != BackportBottomSheetBehavior.STATE_COLLAPSED && - playbackSheetBehavior.state != BackportBottomSheetBehavior.STATE_HIDDEN + playbackSheetBehavior.targetState != BackportBottomSheetBehavior.STATE_COLLAPSED && + playbackSheetBehavior.targetState != BackportBottomSheetBehavior.STATE_HIDDEN private fun queueSheetShown() = queueSheetBehavior != null && - queueSheetBehavior.state != BackportBottomSheetBehavior.STATE_COLLAPSED && - playbackSheetBehavior.state == BackportBottomSheetBehavior.STATE_EXPANDED + playbackSheetBehavior.state == BackportBottomSheetBehavior.STATE_EXPANDED && + queueSheetBehavior.targetState != BackportBottomSheetBehavior.STATE_COLLAPSED } private class DetailBackPressedCallback(private val detailModel: DetailViewModel) :