make insets work more correct

This commit is contained in:
Christian Schabesberger 2024-07-23 18:02:21 +02:00
parent d4a7c68e5f
commit 6da8b12ec2
2 changed files with 35 additions and 28 deletions

View File

@ -32,13 +32,16 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.ime import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.systemGestures
import androidx.compose.foundation.layout.union import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.waterfall
import androidx.compose.foundation.layout.windowInsetsBottomHeight import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.windowInsetsTopHeight import androidx.compose.foundation.layout.windowInsetsTopHeight
@ -105,10 +108,15 @@ fun VideoPlayerControllerUI(
hideUi: () -> Unit hideUi: () -> Unit
) { ) {
val insets = WindowInsets.systemBars val insets =
WindowInsets.systemBars
.union(WindowInsets.displayCutout)
.union(WindowInsets.waterfall)
if (!uiVissible) { if (!uiVissible) {
TouchUi( TouchUi(
modifier = Modifier.fillMaxSize(), modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(WindowInsets.systemGestures),
hideUi = hideUi, hideUi = hideUi,
showUi = showUi, showUi = showUi,
uiVissible = uiVissible, uiVissible = uiVissible,
@ -119,22 +127,28 @@ fun VideoPlayerControllerUI(
modifier = Modifier.fillMaxSize(), color = Color(0x75000000) modifier = Modifier.fillMaxSize(), color = Color(0x75000000)
) { ) {
TouchUi( TouchUi(
modifier = Modifier.fillMaxSize(), modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(WindowInsets.systemGestures),
hideUi = hideUi, hideUi = hideUi,
showUi = showUi, showUi = showUi,
uiVissible = uiVissible, uiVissible = uiVissible,
fullscreen = fullscreen fullscreen = fullscreen
) )
Box( Box {
modifier = if (fullscreen) { CenterUI(
Modifier modifier = Modifier.align(Alignment.Center),
.background(Color.Transparent) isPlaying = isPlaying,
.windowInsetsPadding(insets) play = play,
} else { pause = pause,
Modifier prevStream = prevStream,
.background(Color.Transparent) nextStream = nextStream
)
} }
Box(
modifier = if (fullscreen) Modifier.windowInsetsPadding(insets) else Modifier
) { ) {
TopUI( TopUI(
modifier = Modifier modifier = Modifier
@ -143,14 +157,7 @@ fun VideoPlayerControllerUI(
.defaultMinSize(minHeight = 45.dp) .defaultMinSize(minHeight = 45.dp)
.padding(top = 4.dp, start = 16.dp, end = 16.dp) .padding(top = 4.dp, start = 16.dp, end = 16.dp)
) )
CenterUI(
modifier = Modifier.align(Alignment.Center),
isPlaying,
play = play,
pause = pause,
prevStream = prevStream,
nextStream = nextStream
)
BottomUI( BottomUI(
modifier = Modifier modifier = Modifier
.align(Alignment.BottomStart) .align(Alignment.BottomStart)

View File

@ -66,7 +66,7 @@ class MainActivity : AppCompatActivity() {
videoPlayerViewModel.newPlayer = newPlayer videoPlayerViewModel.newPlayer = newPlayer
videoPlayerViewModel.maxContentRatio = 4F/3F //videoPlayerViewModel.maxContentRatio = 4F/3F
videoPlayerViewModel.contentFitMode = ContentScale.FIT_INSIDE videoPlayerViewModel.contentFitMode = ContentScale.FIT_INSIDE
@ -76,16 +76,16 @@ class MainActivity : AppCompatActivity() {
val setupFullscreen = { val setupFullscreen = {
//ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
// v.setPadding(0, 0, 0, 0) v.setPadding(0, 0, 0, 0)
// insets insets
//} }
buttons_layout.visibility = View.GONE buttons_layout.visibility = View.GONE
embedded_player_layout.visibility = View.GONE embedded_player_layout.visibility = View.GONE
fullscreen_player.visibility = View.VISIBLE fullscreen_player.visibility = View.VISIBLE
fullscreen_player.viewModel = videoPlayerViewModel fullscreen_player.viewModel = videoPlayerViewModel
//windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
} }
val setupEmbeddedView = { val setupEmbeddedView = {
@ -108,7 +108,7 @@ class MainActivity : AppCompatActivity() {
video_view.viewModel = videoPlayerViewModel video_view.viewModel = videoPlayerViewModel
//windowInsetsController.show(WindowInsetsCompat.Type.systemBars()) windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
} }
if (videoPlayerViewModel.uiState.value.fullscreen) { if (videoPlayerViewModel.uiState.value.fullscreen) {
@ -127,9 +127,9 @@ class MainActivity : AppCompatActivity() {
override fun onUiVissibleToggle(isVissible: Boolean) { override fun onUiVissibleToggle(isVissible: Boolean) {
if (isVissible) { if (isVissible) {
// windowInsetsController.show(WindowInsetsCompat.Type.systemBars()) windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
} else { } else {
// windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
} }
} }
} }