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.
This commit is contained in:
OxygenCobalt 2022-05-24 17:23:09 -06:00
parent b320f4b1bd
commit 4c74879cf1
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 33 additions and 24 deletions

View file

@ -17,10 +17,8 @@
package org.oxycblt.auxio.playback package org.oxycblt.auxio.playback
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.WindowInsets
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import org.oxycblt.auxio.R 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.NavigationViewModel
import org.oxycblt.auxio.ui.ViewBindingFragment import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.getColorStateListSafe import org.oxycblt.auxio.util.getColorStateListSafe
import org.oxycblt.auxio.util.systemBarInsetsCompat import org.oxycblt.auxio.util.systemGestureInsetsCompat
import org.oxycblt.auxio.util.textSafe import org.oxycblt.auxio.util.textSafe
/** /**
@ -61,22 +59,8 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
// Since we swipe up this view, we need to make sure it does not collide with // 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 // 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. // only default to the system bar insets when there are no other options.
val gesturePadding = val gesturePadding = insets.systemGestureInsetsCompat
when { view.updatePadding(bottom = gesturePadding.bottom)
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)
insets insets
} }
} }

View file

@ -37,6 +37,7 @@ import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.formatDuration import org.oxycblt.auxio.util.formatDuration
import org.oxycblt.auxio.util.logD import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.systemBarInsetsCompat import org.oxycblt.auxio.util.systemBarInsetsCompat
import org.oxycblt.auxio.util.systemGestureInsetsCompat
import org.oxycblt.auxio.util.textSafe import org.oxycblt.auxio.util.textSafe
/** /**
@ -64,9 +65,13 @@ class PlaybackPanelFragment :
savedInstanceState: Bundle? savedInstanceState: Bundle?
) { ) {
// --- UI SETUP --- // --- UI SETUP ---
logD(binding.root.paddingBottom)
binding.root.setOnApplyWindowInsetsListener { _, insets -> binding.root.setOnApplyWindowInsetsListener { _, insets ->
val bars = insets.systemBarInsetsCompat 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 insets
} }

View file

@ -156,11 +156,11 @@ fun <R> 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 * 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 val WindowInsets.systemBarInsetsCompat: Rect
get() { get() =
return when { when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
getInsets(WindowInsets.Type.systemBars()).run { Rect(left, top, right, bottom) } getInsets(WindowInsets.Type.systemBars()).run { Rect(left, top, right, bottom) }
} }
@ -173,7 +173,27 @@ val WindowInsets.systemBarInsetsCompat: Rect
systemWindowInsetBottom) 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 * Replaces the system bar insets in a version-aware manner. This can be used to modify the insets