From e57a55a76926392fb718357d0fa08e56c754a2c1 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 1 May 2024 14:42:20 +0200 Subject: [PATCH] fix: missing horizontal player spacing with display cutout --- .../java/com/github/libretube/ui/base/BaseActivity.kt | 10 +++++++--- .../github/libretube/ui/views/CustomExoPlayerView.kt | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt b/app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt index 37e091d6a..907d5775a 100644 --- a/app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt @@ -31,9 +31,7 @@ open class BaseActivity : AppCompatActivity() { /** * Whether the phone of the user has a cutout like a notch or not */ - val hasCutout by lazy { - WindowHelper.hasCutout(window.decorView.rootView) - } + var hasCutout: Boolean = false override fun onCreate(savedInstanceState: Bundle?) { // set the app theme (e.g. Material You) @@ -49,6 +47,12 @@ open class BaseActivity : AppCompatActivity() { requestOrientationChange() + // wait for the window decor view to be drawn before detecting display cutouts + window.decorView.setOnApplyWindowInsetsListener { view, insets -> + hasCutout = WindowHelper.hasCutout(view) + insets + } + super.onCreate(savedInstanceState) } diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index b3cf2ba53..90b4df5ff 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -637,7 +637,7 @@ abstract class CustomExoPlayerView( updateTopBarMargin() // don't add extra padding if there's no cutout and no margin set that would need to be undone - if (!(context as BaseActivity).hasCutout && binding.topBar.marginStart == LANDSCAPE_MARGIN_HORIZONTAL_NONE) return + if (!activity.hasCutout && binding.topBar.marginStart == LANDSCAPE_MARGIN_HORIZONTAL_NONE) return // add a margin to the top and the bottom bar in landscape mode for notches val isForcedPortrait = activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT