make touch surface hide behind regular buttons

This commit is contained in:
Christian Schabesberger 2024-07-23 14:39:45 +02:00
parent 5a2f62b55e
commit 8551a36a0c
2 changed files with 77 additions and 23 deletions

View File

@ -193,6 +193,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
Log.d(TAG, "viewmodel cleared") Log.d(TAG, "viewmodel cleared")
} }
@ -213,18 +214,25 @@ class VideoPlayerViewModelImpl @Inject constructor(
} }
override fun play() { override fun play() {
uiVisibilityJob?.cancel()
mutableUiState.update {
it.copy(uiVissible = false)
}
newPlayer?.play() newPlayer?.play()
} }
override fun pause() { override fun pause() {
resetHideUiDelayed()
newPlayer?.pause() newPlayer?.pause()
} }
override fun prevStream() { override fun prevStream() {
resetHideUiDelayed()
Log.e(TAG, "imeplement prev stream") Log.e(TAG, "imeplement prev stream")
} }
override fun nextStream() { override fun nextStream() {
resetHideUiDelayed()
Log.e(TAG, "implement next stream") Log.e(TAG, "implement next stream")
} }
@ -232,6 +240,10 @@ class VideoPlayerViewModelImpl @Inject constructor(
mutableUiState.update { mutableUiState.update {
it.copy(uiVissible = true) it.copy(uiVissible = true)
} }
resetHideUiDelayed()
}
private fun resetHideUiDelayed() {
uiVisibilityJob?.cancel() uiVisibilityJob?.cancel()
uiVisibilityJob = viewModelScope.launch { uiVisibilityJob = viewModelScope.launch {
delay(2000) delay(2000)
@ -250,15 +262,18 @@ class VideoPlayerViewModelImpl @Inject constructor(
override fun switchToEmbeddedView() { override fun switchToEmbeddedView() {
fullscreenListener?.onFullscreenToggle(false) fullscreenListener?.onFullscreenToggle(false)
uiVisibilityJob?.cancel()
mutableUiState.update { mutableUiState.update {
it.copy(fullscreen = false) it.copy(fullscreen = false, uiVissible = false)
} }
} }
override fun switchToFullscreen() { override fun switchToFullscreen() {
fullscreenListener?.onFullscreenToggle(true) fullscreenListener?.onFullscreenToggle(true)
uiVisibilityJob?.cancel()
mutableUiState.update { mutableUiState.update {
it.copy(fullscreen = true) it.copy(fullscreen = true, uiVissible = false)
} }
} }

View File

@ -20,6 +20,7 @@
package net.newpipe.newplayer.ui package net.newpipe.newplayer.ui
import android.view.MotionEvent
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@ -67,9 +68,11 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.layout.onPlaced import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -96,11 +99,27 @@ fun VideoPlayerControllerUI(
showUi: () -> Unit, showUi: () -> Unit,
hideUi: () -> Unit hideUi: () -> Unit
) { ) {
TouchControll(modifier = Modifier, hideUi = hideUi, showUi = showUi, uiVissible = uiVissible) {
if (uiVissible) { Box(modifier = Modifier) {
if (!uiVissible) {
TouchUi(
modifier = Modifier.fillMaxSize(),
hideUi = hideUi,
showUi = showUi,
uiVissible = uiVissible,
fullscreen = fullscreen
)
} else {
Surface( Surface(
modifier = Modifier.fillMaxSize(), color = Color(0x75000000) modifier = Modifier.fillMaxSize(), color = Color(0x75000000)
) { ) {
TouchUi(
modifier = Modifier.fillMaxSize(),
hideUi = hideUi,
showUi = showUi,
uiVissible = uiVissible,
fullscreen = fullscreen
)
Box( Box(
modifier = if (fullscreen) { modifier = if (fullscreen) {
Modifier Modifier
@ -147,6 +166,45 @@ fun VideoPlayerControllerUI(
} }
} }
@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun TouchUi(
modifier: Modifier,
hideUi: () -> Unit,
showUi: () -> Unit,
uiVissible: Boolean,
fullscreen: Boolean,
) {
Box(modifier = Modifier
.pointerInteropFilter {
when (it.action) {
MotionEvent.ACTION_DOWN -> {
true
}
MotionEvent.ACTION_UP -> {
if (uiVissible) {
hideUi()
} else {
showUi()
}
true
}
MotionEvent.ACTION_MOVE -> {
true
}
else -> false
}
}) {
Surface(color = Color.Transparent, modifier = Modifier.fillMaxSize()) {
}
}
}
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// TopUI // TopUI
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
@ -204,25 +262,6 @@ private fun TopUI(modifier: Modifier) {
} }
} }
@Composable
private fun TouchControll(
modifier: Modifier,
hideUi: () -> Unit,
showUi: () -> kotlin.Unit,
uiVissible: Boolean,
content: @Composable () -> Unit
) {
Box(modifier = Modifier
.fillMaxSize()
.clickable {
if (uiVissible)
hideUi()
else
showUi()
}) {
content()
}
}
@Composable @Composable
private fun MainMenu() { private fun MainMenu() {