fix: Handle display cutouts in landscape mode

EdgeToEdgeHelper now considers both systemBars() and displayCutout()
insets when applying padding. This prevents camera cutouts from
obscuring UI content when the device is in landscape orientation.
This commit is contained in:
darken
2026-01-17 14:20:21 +01:00
committed by Matthias Urhahn
parent 10d5a823fc
commit 9ff8d9e04e
@@ -2,7 +2,6 @@ package eu.darken.capod.common
import android.app.Activity
import android.view.View
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import eu.darken.capod.common.debug.logging.logTag
@@ -20,12 +19,14 @@ class EdgeToEdgeHelper(activity: Activity) {
bottom: Boolean = false,
) {
ViewCompat.setOnApplyWindowInsetsListener(view) { v: View, insets: WindowInsetsCompat ->
val systemBars: Insets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
val displayCutout = insets.getInsets(WindowInsetsCompat.Type.displayCutout())
v.setPadding(
if (left) systemBars.left else v.paddingLeft,
if (top) systemBars.top else v.paddingTop,
if (right) systemBars.right else v.paddingRight,
if (bottom) systemBars.bottom else v.paddingBottom,
if (left) maxOf(systemBars.left, displayCutout.left) else v.paddingLeft,
if (top) maxOf(systemBars.top, displayCutout.top) else v.paddingTop,
if (right) maxOf(systemBars.right, displayCutout.right) else v.paddingRight,
if (bottom) maxOf(systemBars.bottom, displayCutout.bottom) else v.paddingBottom,
)
insets
}