make downwardmovement also allow upward movement after gesture initialization

This commit is contained in:
Christian Schabesberger 2024-08-26 12:47:07 +02:00
parent d4d29f4c5c
commit 5102e0d9e1
1 changed files with 30 additions and 8 deletions

View File

@ -28,6 +28,10 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -44,15 +48,30 @@ fun EmbeddedGestureUI(
modifier: Modifier = Modifier, viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState modifier: Modifier = Modifier, viewModel: VideoPlayerViewModel, uiState: VideoPlayerUIState
) { ) {
val handleDownwardMovement = { movement: TouchedPosition -> var downwardMovementMode by remember {
mutableStateOf(false)
}
val handleMovement = { movement: TouchedPosition ->
Log.d(TAG, "${movement.x}:${movement.y}") Log.d(TAG, "${movement.x}:${movement.y}")
if (0 < movement.y) { if (0 < movement.y) {
viewModel.embeddedDraggedDown(movement.y) viewModel.embeddedDraggedDown(movement.y)
downwardMovementMode = true
} else { } else {
viewModel.switchToFullscreen()
// this check is there to allow a temporary move up in the downward gesture
if (downwardMovementMode == false) {
viewModel.switchToFullscreen()
} else {
viewModel.embeddedDraggedDown(movement.y)
}
} }
} }
val handleUp = {
downwardMovementMode = false
}
val defaultOnRegularTap = { val defaultOnRegularTap = {
if (uiState.uiMode.controllerUiVisible) { if (uiState.uiMode.controllerUiVisible) {
viewModel.hideUi() viewModel.hideUi()
@ -69,7 +88,8 @@ fun EmbeddedGestureUI(
viewModel.fastSeek(-it) viewModel.fastSeek(-it)
}, },
onMultiTapFinished = viewModel::finishFastSeek, onMultiTapFinished = viewModel::finishFastSeek,
onMovement = handleDownwardMovement onMovement = handleMovement,
onUp = handleUp
) { ) {
FadedAnimationForSeekFeedback( FadedAnimationForSeekFeedback(
uiState.fastSeekSeconds, backwards = true uiState.fastSeekSeconds, backwards = true
@ -88,8 +108,8 @@ fun EmbeddedGestureUI(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
onRegularTap = defaultOnRegularTap, onRegularTap = defaultOnRegularTap,
onMultiTap = { count -> onMultiTap = { count ->
if(count == 1) { if (count == 1) {
if(uiState.playing) { if (uiState.playing) {
viewModel.pause() viewModel.pause()
viewModel.showUi() viewModel.showUi()
} else { } else {
@ -98,7 +118,8 @@ fun EmbeddedGestureUI(
} }
}, },
onMultiTapFinished = viewModel::finishFastSeek, onMultiTapFinished = viewModel::finishFastSeek,
onMovement = handleDownwardMovement onMovement = handleMovement,
onUp = handleUp
) { ) {
Box(modifier = Modifier.fillMaxSize()) Box(modifier = Modifier.fillMaxSize())
} }
@ -106,9 +127,10 @@ fun EmbeddedGestureUI(
GestureSurface( GestureSurface(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
onRegularTap = defaultOnRegularTap, onRegularTap = defaultOnRegularTap,
onMovement = handleDownwardMovement, onMovement = handleMovement,
onMultiTap = viewModel::fastSeek, onMultiTap = viewModel::fastSeek,
onMultiTapFinished = viewModel::finishFastSeek onMultiTapFinished = viewModel::finishFastSeek,
onUp = handleUp
) { ) {
FadedAnimationForSeekFeedback(uiState.fastSeekSeconds) { fastSeekSecondsToDisplay -> FadedAnimationForSeekFeedback(uiState.fastSeekSeconds) { fastSeekSecondsToDisplay ->
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {