From 4c74879cf10474da54826dea2c48bfe561e1ef87 Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Tue, 24 May 2022 17:23:09 -0600 Subject: [PATCH] playback: use gesture insets on panel Also use the gesture insets on playback panel. Turns out when the panel uses normal insets, the playback panel is extremely close to the system bars. Fix this by using the bigger gesture insets. Resolves #137. --- .../auxio/playback/PlaybackBarFragment.kt | 22 ++------------- .../auxio/playback/PlaybackPanelFragment.kt | 7 ++++- .../org/oxycblt/auxio/util/FrameworkUtil.kt | 28 ++++++++++++++++--- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBarFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBarFragment.kt index 9fc40fac1..555aaa7cb 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBarFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBarFragment.kt @@ -17,10 +17,8 @@ package org.oxycblt.auxio.playback -import android.os.Build import android.os.Bundle import android.view.LayoutInflater -import android.view.WindowInsets import androidx.core.view.updatePadding import androidx.fragment.app.activityViewModels import org.oxycblt.auxio.R @@ -30,7 +28,7 @@ import org.oxycblt.auxio.ui.MainNavigationAction import org.oxycblt.auxio.ui.NavigationViewModel import org.oxycblt.auxio.ui.ViewBindingFragment import org.oxycblt.auxio.util.getColorStateListSafe -import org.oxycblt.auxio.util.systemBarInsetsCompat +import org.oxycblt.auxio.util.systemGestureInsetsCompat import org.oxycblt.auxio.util.textSafe /** @@ -61,22 +59,8 @@ class PlaybackBarFragment : ViewBindingFragment() { // Since we swipe up this view, we need to make sure it does not collide with // any gesture events. So, apply the system gesture insets if present and then // only default to the system bar insets when there are no other options. - val gesturePadding = - when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { - insets.getInsets(WindowInsets.Type.systemGestures()).bottom - } - Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> { - @Suppress("DEPRECATION") insets.systemGestureInsets.bottom - } - else -> 0 - } - - view.updatePadding( - bottom = - if (gesturePadding != 0) gesturePadding - else insets.systemBarInsetsCompat.bottom) - + val gesturePadding = insets.systemGestureInsetsCompat + view.updatePadding(bottom = gesturePadding.bottom) insets } } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt index a1c518abb..23bce6afe 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt @@ -37,6 +37,7 @@ import org.oxycblt.auxio.ui.ViewBindingFragment import org.oxycblt.auxio.util.formatDuration import org.oxycblt.auxio.util.logD import org.oxycblt.auxio.util.systemBarInsetsCompat +import org.oxycblt.auxio.util.systemGestureInsetsCompat import org.oxycblt.auxio.util.textSafe /** @@ -64,9 +65,13 @@ class PlaybackPanelFragment : savedInstanceState: Bundle? ) { // --- UI SETUP --- + + logD(binding.root.paddingBottom) + binding.root.setOnApplyWindowInsetsListener { _, insets -> val bars = insets.systemBarInsetsCompat - binding.root.updatePadding(top = bars.top, bottom = bars.bottom) + val gestures = insets.systemGestureInsetsCompat + binding.root.updatePadding(top = bars.top, bottom = gestures.bottom) insets } diff --git a/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt b/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt index 5da25bd1b..01e2a8ad3 100644 --- a/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt +++ b/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt @@ -156,11 +156,11 @@ fun SQLiteDatabase.queryAll(tableName: String, block: (Cursor) -> R) = /** * Resolve system bar insets in a version-aware manner. This can be used to apply padding to a view - * that properly follows all the frustrating changes that were made between 8-11. + * that properly follows all the frustrating changes that were made between Android 8-11. */ val WindowInsets.systemBarInsetsCompat: Rect - get() { - return when { + get() = + when { Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { getInsets(WindowInsets.Type.systemBars()).run { Rect(left, top, right, bottom) } } @@ -173,7 +173,27 @@ val WindowInsets.systemBarInsetsCompat: Rect systemWindowInsetBottom) } } - } + +/** + * Resolve gesture insets in a version-aware manner. This can be used to apply padding to a view + * that properly follows all the frustrating changes that were made between Android 8-11. + */ +val WindowInsets.systemGestureInsetsCompat: Rect + get() = + when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { + getInsets(WindowInsets.Type.systemGestures()).run { Rect(left, top, right, bottom) } + } + Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> { + @Suppress("DEPRECATION") val gestureInsets = systemGestureInsets + Rect( + gestureInsets.left, + gestureInsets.top, + gestureInsets.right, + gestureInsets.bottom) + } + else -> Rect(0, 0, 0, 0) + } /** * Replaces the system bar insets in a version-aware manner. This can be used to modify the insets