make only one of the volume indicators vissible

This commit is contained in:
Christian Schabesberger 2024-08-09 12:49:11 +02:00
parent 1fde8569ce
commit 601dbf2e7f
4 changed files with 63 additions and 46 deletions

View File

@ -29,8 +29,8 @@ private const val TAG = "TouchUi"
const val DELAY_UNTIL_SHOWING_UI_AFTER_TOUCH_IN_MS: Long = 200
const val SEEK_ANIMATION_DURATION_IN_MS = 400
const val FAST_SEEKMODE_DURATION = 500L
const val SEEK_ANIMATION_DURATION_IN_MS = 300
const val FAST_SEEK_MODE_DURATION = 500L
const val SEEK_ANIMATION_FADE_IN = 200
const val SEEK_ANIMATION_FADE_OUT = 500

View File

@ -33,7 +33,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.FAST_SEEKMODE_DURATION
import net.newpipe.newplayer.ui.videoplayer.FAST_SEEK_MODE_DURATION
private const val TAG = "EmbeddedGestureUI"
@ -68,10 +68,10 @@ fun EmbeddedGestureUI(
}
Row(modifier = modifier) {
TouchSurface(
GestureSurface(
modifier = Modifier
.weight(1f),
multitapDurationInMs = FAST_SEEKMODE_DURATION,
multiTapTimeoutInMs = FAST_SEEK_MODE_DURATION,
onRegularTap = defaultOnRegularTap,
onMultiTap = {
fastSeek(-it)
@ -92,10 +92,10 @@ fun EmbeddedGestureUI(
}
}
}
TouchSurface(
GestureSurface(
modifier = Modifier
.weight(1f),
multitapDurationInMs = FAST_SEEKMODE_DURATION,
multiTapTimeoutInMs = FAST_SEEK_MODE_DURATION,
onRegularTap = defaultOnRegularTap,
onMovement = handleDownwardMovement,
onMultiTap = fastSeek,

View File

@ -41,7 +41,13 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.tooling.preview.Preview
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.FAST_SEEKMODE_DURATION
import net.newpipe.newplayer.ui.videoplayer.FAST_SEEK_MODE_DURATION
private enum class IndicatorMode {
NONE,
VOLUME_INDICATOR_VISSIBLE,
BRIGHTNESS_INDICATOR_VISSIBLE
}
@Composable
fun FullscreenGestureUI(
@ -58,7 +64,17 @@ fun FullscreenGestureUI(
volumeChange: (Float) -> Unit,
brightnesChange: (Float) -> Unit
) {
var heightPx by remember {
mutableStateOf(0f)
}
var indicatorMode by remember {
mutableStateOf(IndicatorMode.NONE)
}
val defaultOnRegularTap = {
if (uiVissible) {
hideUi()
} else {
@ -66,26 +82,14 @@ fun FullscreenGestureUI(
}
}
var heightPx by remember {
mutableStateOf(0f)
}
var volumeIndicatorVissible by remember {
mutableStateOf(false)
}
var brightnesIndicatorVissible by remember {
mutableStateOf(false)
}
Box(modifier = modifier.onGloballyPositioned { coordinates ->
heightPx = coordinates.size.height.toFloat()
}) {
Row {
TouchSurface(
GestureSurface(
modifier = Modifier
.weight(1f),
multitapDurationInMs = FAST_SEEKMODE_DURATION,
multiTapTimeoutInMs = FAST_SEEK_MODE_DURATION,
onRegularTap = defaultOnRegularTap,
onMultiTap = {
println("multitap ${-it}")
@ -93,12 +97,17 @@ fun FullscreenGestureUI(
},
onMultiTapFinished = fastSeekFinished,
onUp = {
brightnesIndicatorVissible = false
indicatorMode = IndicatorMode.NONE
},
onMovement = {change ->
brightnesIndicatorVissible = true
if (heightPx != 0f) {
brightnesChange(-change.y / heightPx)
onMovement = { change ->
if (indicatorMode == IndicatorMode.NONE
|| indicatorMode == IndicatorMode.BRIGHTNESS_INDICATOR_VISSIBLE
) {
indicatorMode = IndicatorMode.BRIGHTNESS_INDICATOR_VISSIBLE
if (heightPx != 0f) {
brightnesChange(-change.y / heightPx)
}
}
}
) {
@ -115,31 +124,35 @@ fun FullscreenGestureUI(
}
}
}
TouchSurface(
GestureSurface(
modifier = Modifier
.weight(1f),
onRegularTap = defaultOnRegularTap,
multitapDurationInMs = FAST_SEEKMODE_DURATION,
multiTapTimeoutInMs = FAST_SEEK_MODE_DURATION,
onMovement = { movement ->
if (0 < movement.y) {
switchToEmbeddedView()
}
}
)
TouchSurface(
GestureSurface(
modifier = Modifier
.weight(1f),
onRegularTap = defaultOnRegularTap,
multitapDurationInMs = FAST_SEEKMODE_DURATION,
multiTapTimeoutInMs = FAST_SEEK_MODE_DURATION,
onMultiTap = fastSeek,
onMultiTapFinished = fastSeekFinished,
onUp = {
volumeIndicatorVissible = false
indicatorMode = IndicatorMode.NONE
},
onMovement = { change ->
volumeIndicatorVissible = true
if (heightPx != 0f) {
volumeChange(-change.y / heightPx)
if (indicatorMode == IndicatorMode.NONE
|| indicatorMode == IndicatorMode.VOLUME_INDICATOR_VISSIBLE
) {
indicatorMode = IndicatorMode.VOLUME_INDICATOR_VISSIBLE
if (heightPx != 0f) {
volumeChange(-change.y / heightPx)
}
}
}
) {
@ -154,17 +167,21 @@ fun FullscreenGestureUI(
}
}
}
AnimatedVisibility(modifier = Modifier.align(Alignment.Center),
visible = volumeIndicatorVissible,
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = indicatorMode == IndicatorMode.VOLUME_INDICATOR_VISSIBLE,
enter = scaleIn(initialScale = 0.95f, animationSpec = tween(100)),
exit = scaleOut(targetScale = 0.95f, animationSpec = tween(100))) {
exit = scaleOut(targetScale = 0.95f, animationSpec = tween(100))
) {
VolumeCircle(volumeFraction = volume)
}
AnimatedVisibility(modifier = Modifier.align(Alignment.Center),
visible = brightnesIndicatorVissible,
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = indicatorMode == IndicatorMode.BRIGHTNESS_INDICATOR_VISSIBLE,
enter = scaleIn(initialScale = 0.95f, animationSpec = tween(100)),
exit = scaleOut(targetScale = 0.95f, animationSpec = tween(100))) {
exit = scaleOut(targetScale = 0.95f, animationSpec = tween(100))
) {
VolumeCircle(
volumeFraction = brightnes,
modifier = Modifier.align(Alignment.Center),

View File

@ -40,10 +40,10 @@ import kotlinx.coroutines.launch
@Composable
@OptIn(ExperimentalComposeUiApi::class)
fun TouchSurface(
fun GestureSurface(
modifier: Modifier,
color: Color = Color.Transparent,
multitapDurationInMs: Long,
multiTapTimeoutInMs: Long,
onMultiTap: (Int) -> Unit = {},
onMultiTapFinished: () -> Unit = {},
onRegularTap: () -> Unit = {},
@ -87,19 +87,19 @@ fun TouchSurface(
val currentTime = System.currentTimeMillis()
if (!moveOccured) {
val timeSinceLastTouch = currentTime - lastTouchTime
if (timeSinceLastTouch <= multitapDurationInMs) {
if (timeSinceLastTouch <= multiTapTimeoutInMs) {
regularTabJob?.cancel()
cancelMultitapJob?.cancel()
multitapAmount++
onMultiTap(multitapAmount)
cancelMultitapJob = composableScope.launch {
delay(multitapDurationInMs)
delay(multiTapTimeoutInMs)
multitapAmount = 0
onMultiTapFinished()
}
} else {
regularTabJob = composableScope.launch {
delay(multitapDurationInMs)
delay(multiTapTimeoutInMs)
onRegularTap()
}
}