Merge pull request #5948 from Bnyro/master

fix: missing horizontal player spacing with display cutout
This commit is contained in:
Bnyro 2024-05-01 14:42:47 +02:00 committed by GitHub
commit 8fe9d5c6ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -31,9 +31,7 @@ open class BaseActivity : AppCompatActivity() {
/** /**
* Whether the phone of the user has a cutout like a notch or not * Whether the phone of the user has a cutout like a notch or not
*/ */
val hasCutout by lazy { var hasCutout: Boolean = false
WindowHelper.hasCutout(window.decorView.rootView)
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
// set the app theme (e.g. Material You) // set the app theme (e.g. Material You)
@ -49,6 +47,12 @@ open class BaseActivity : AppCompatActivity() {
requestOrientationChange() 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) super.onCreate(savedInstanceState)
} }

View File

@ -637,7 +637,7 @@ abstract class CustomExoPlayerView(
updateTopBarMargin() updateTopBarMargin()
// don't add extra padding if there's no cutout and no margin set that would need to be undone // 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 // add a margin to the top and the bottom bar in landscape mode for notches
val isForcedPortrait = activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT val isForcedPortrait = activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT