make insets work more correct
This commit is contained in:
parent
d4a7c68e5f
commit
6da8b12ec2
|
@ -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 {
|
||||||
|
CenterUI(
|
||||||
|
modifier = Modifier.align(Alignment.Center),
|
||||||
|
isPlaying = isPlaying,
|
||||||
|
play = play,
|
||||||
|
pause = pause,
|
||||||
|
prevStream = prevStream,
|
||||||
|
nextStream = nextStream
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = if (fullscreen) {
|
modifier = if (fullscreen) Modifier.windowInsetsPadding(insets) else Modifier
|
||||||
Modifier
|
|
||||||
.background(Color.Transparent)
|
|
||||||
.windowInsetsPadding(insets)
|
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
.background(Color.Transparent)
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
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)
|
||||||
|
|
|
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue