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:
parent
b320f4b1bd
commit
4c74879cf1
3 changed files with 33 additions and 24 deletions
|
@ -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<FragmentPlaybackBarBinding>() {
|
|||
// 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
* 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
|
||||
|
|
Loading…
Reference in a new issue