From e035d81ee03cb85ab98b8e32be71a83a31bfae3d Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Thu, 4 Jul 2024 11:42:45 -0600 Subject: [PATCH] ui: try band-aiding bottom sheet flickering Use an assumed peekHeight close to the real one and reduce the jumpiness that appears in some cases. Resolves #631. --- CHANGELOG.md | 1 + .../auxio/playback/PlaybackBottomSheetBehavior.kt | 5 +++++ .../playback/queue/QueueBottomSheetBehavior.kt | 3 +++ .../oxycblt/auxio/ui/BaseBottomSheetBehavior.kt | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4645cab..66ccedd7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ #### What's Fixed - Music loader no longer spawns thousands of threads when scanning - Excessive CPU no longer spent showing music loading process +- Fixed playback sheet flickering on warm start ## 3.5.1 diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt index 3adfe27c6..b6731e3ce 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt @@ -28,8 +28,10 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout import com.google.android.material.R as MR import com.google.android.material.shape.MaterialShapeDrawable import com.google.android.material.shape.ShapeAppearanceModel +import org.oxycblt.auxio.R import org.oxycblt.auxio.ui.BaseBottomSheetBehavior import org.oxycblt.auxio.util.getAttrColorCompat +import org.oxycblt.auxio.util.getDimenPixels import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat import org.oxycblt.auxio.util.systemBarInsetsCompat @@ -55,6 +57,9 @@ class PlaybackBottomSheetBehavior(context: Context, attributeSet: Attr isHideable = true } + override fun getIdealBarHeight(context: Context) = + context.getDimenPixels(R.dimen.size_touchable_large) + // Hack around issue where the playback sheet will try to intercept nested scrolling events // before the queue sheet. override fun onInterceptTouchEvent(parent: CoordinatorLayout, child: V, event: MotionEvent) = diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt index c09462906..35eead292 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt @@ -49,6 +49,9 @@ class QueueBottomSheetBehavior(context: Context, attributeSet: Attribu isHideable = false } + override fun getIdealBarHeight(context: Context) = + context.getDimenPixels(R.dimen.size_touchable_large) + override fun layoutDependsOn(parent: CoordinatorLayout, child: V, dependency: View) = dependency.id == R.id.playback_bar_fragment diff --git a/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt index a36c20302..4df169899 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt @@ -27,7 +27,9 @@ import android.view.WindowInsets import androidx.coordinatorlayout.widget.CoordinatorLayout import com.google.android.material.R as MR import com.google.android.material.bottomsheet.BackportBottomSheetBehavior +import org.oxycblt.auxio.R import org.oxycblt.auxio.util.getDimen +import org.oxycblt.auxio.util.getDimenPixels import org.oxycblt.auxio.util.logD import org.oxycblt.auxio.util.systemGestureInsetsCompat @@ -42,6 +44,7 @@ import org.oxycblt.auxio.util.systemGestureInsetsCompat abstract class BaseBottomSheetBehavior(context: Context, attributeSet: AttributeSet?) : BackportBottomSheetBehavior(context, attributeSet) { private var initalized = false + private val idealBottomGestureInsets = context.getDimenPixels(R.dimen.spacing_medium) init { // Disable isFitToContents to make the bottom sheet expand to the top of the screen and @@ -57,6 +60,9 @@ abstract class BaseBottomSheetBehavior(context: Context, attributeSet: */ abstract fun createBackground(context: Context): Drawable + /** Get the ideal bar height to use before the bar is properly measured. */ + abstract fun getIdealBarHeight(context: Context): Int + /** * Called when window insets are being applied to the [View] this [BaseBottomSheetBehavior] is * linked to. @@ -70,7 +76,13 @@ abstract class BaseBottomSheetBehavior(context: Context, attributeSet: // All sheet behaviors derive their peek height from the size of the "bar" (i.e the // first child) plus the gesture insets. val gestures = insets.systemGestureInsetsCompat - peekHeight = (child as ViewGroup).getChildAt(0).height + gestures.bottom + val bar = (child as ViewGroup).getChildAt(0) + peekHeight = + if (bar.measuredHeight > 0) { + bar.measuredHeight + gestures.bottom + } else { + getIdealBarHeight(child.context) + gestures.bottom + } return insets } @@ -93,6 +105,7 @@ abstract class BaseBottomSheetBehavior(context: Context, attributeSet: setOnApplyWindowInsetsListener(::applyWindowInsets) } initalized = true + peekHeight = getIdealBarHeight(child.context) + idealBottomGestureInsets } // Sometimes CoordinatorLayout doesn't dispatch window insets to us, likely due to how // much we overload it. Ensure that we get them.