From 0a7c56cfb69b8334f8cd3899e8a9f7859a7fbdf5 Mon Sep 17 00:00:00 2001 From: AbdallahMehiz Date: Sun, 14 Jul 2024 02:57:16 +0100 Subject: [PATCH] refactor: Adjust brightness and volume gestures' sensitivity remove seek gesture's seek amount that gets displayed, for now. --- .../mehiz/mpvkt/ui/player/PlayerViewModel.kt | 1 - .../ui/player/controls/GestureHandler.kt | 29 ++++++++++------- .../ui/player/controls/PlayerControls.kt | 32 ++----------------- app/src/main/res/values/strings.xml | 1 - 4 files changed, 19 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt index dc6d825..f52ff8d 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt @@ -321,7 +321,6 @@ class PlayerViewModel( newVolume, 0, ) - println(activity.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)) currentVolume.update { newVolume } } diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/GestureHandler.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/GestureHandler.kt index 19a254e..4e0bfea 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/GestureHandler.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/GestureHandler.kt @@ -94,7 +94,6 @@ fun GestureHandler( } else { 0 } - println(seekAmount) viewModel.seekBy(if (isSeekingForwards) doubleTapToSeekDuration else -doubleTapToSeekDuration) viewModel.showSeekBar() } @@ -158,18 +157,14 @@ fun GestureHandler( }, onDragEnd = { viewModel.gestureSeekAmount.update { 0 } + viewModel.hideSeekBar() viewModel.unpause() }, ) { change, dragAmount -> if (position >= duration && dragAmount > 0) return@detectHorizontalDragGestures if (position <= 0f && dragAmount < 0) return@detectHorizontalDragGestures viewModel.showSeekBar() - val seekBy = ( - (dragAmount * 150f / size.width).coerceIn( - 0f - position, - duration - position, - ) - ).toInt() + val seekBy = ((dragAmount * 150f / size.width).coerceIn(0f - position, duration - position)).toInt() viewModel.seekBy(seekBy) viewModel.gestureSeekAmount.update { (position - startingPosition).toInt() } } @@ -179,29 +174,39 @@ fun GestureHandler( var startingY = 0f var originalVolume = currentVolume var originalBrightness = currentBrightness + val brightnessGestureSens = 0.001f + val volumeGestureSens = 0.03f detectVerticalDragGestures( onDragEnd = { startingY = 0f }, onDragStart = { startingY = it.y originalVolume = currentVolume originalBrightness = currentBrightness - } + }, ) { change, amount -> when { volumeGesture && brightnessGesture -> { if (change.position.x < size.width / 2) { - viewModel.changeBrightnessTo(originalBrightness + ((startingY - change.position.y) * 0.005f)) + viewModel.changeBrightnessTo( + originalBrightness + ((startingY - change.position.y) * brightnessGestureSens), + ) } else { - viewModel.changeVolumeTo(originalVolume + ((startingY - change.position.y) * 0.1f).toInt()) + viewModel.changeVolumeTo( + originalVolume + ((startingY - change.position.y) * volumeGestureSens).toInt(), + ) } } brightnessGesture -> { - viewModel.changeBrightnessTo(originalBrightness + ((startingY - change.position.y) * 0.005f)) + viewModel.changeBrightnessTo( + originalBrightness + ((startingY - change.position.y) * brightnessGestureSens), + ) } // it's not always true, AS is drunk volumeGesture -> { - viewModel.changeVolumeTo(originalVolume + ((startingY - change.position.y) * 0.1f).toInt()) + viewModel.changeVolumeTo( + originalVolume + ((startingY - change.position.y) * volumeGestureSens).toInt(), + ) } else -> {} diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt index 2137782..3a23c28 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt @@ -27,7 +27,6 @@ import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect @@ -40,14 +39,10 @@ import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.Shadow import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout import androidx.constraintlayout.compose.Dimension -import `is`.xyz.mpv.Utils import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.delay import kotlinx.coroutines.flow.update @@ -81,14 +76,8 @@ class PlayerControls(private val viewModel: PlayerViewModel) { val controlsShown by viewModel.controlsShown.collectAsState() val areControlsLocked by viewModel.areControlsLocked.collectAsState() val seekBarShown by viewModel.seekBarShown.collectAsState() - val gestureSeekAmount by viewModel.gestureSeekAmount.collectAsState() val isLoading by viewModel.isLoading.collectAsState() val duration by viewModel.duration.collectAsState() - LaunchedEffect(gestureSeekAmount) { - if (gestureSeekAmount != 0) return@LaunchedEffect - delay(3000) - viewModel.hideSeekBar() - } val position by viewModel.pos.collectAsState() val paused by viewModel.paused.collectAsState() var isSeeking by remember { mutableStateOf(false) } @@ -126,12 +115,13 @@ class PlayerControls(private val viewModel: PlayerViewModel) { val (bottomRightControls, bottomLeftControls) = createRefs() val playerPauseButton = createRef() val seekbar = createRef() - val (seekValue, playerUpdates) = createRefs() + val (playerUpdates) = createRefs() val isBrightnessSliderShown by viewModel.isBrightnessSliderShown.collectAsState() val isVolumeSliderShown by viewModel.isVolumeSliderShown.collectAsState() val brightness by viewModel.currentBrightness.collectAsState() val volume by viewModel.currentVolume.collectAsState() + LaunchedEffect(volume, brightness) { delay(1000) if (isVolumeSliderShown) viewModel.isVolumeSliderShown.update { false } @@ -203,24 +193,6 @@ class PlayerControls(private val viewModel: PlayerViewModel) { onClick = { viewModel.unlockControls() }, ) } - AnimatedVisibility( - visible = gestureSeekAmount != 0 && !areControlsLocked, - enter = fadeIn(), - exit = fadeOut(), - modifier = Modifier.constrainAs(seekValue) { - start.linkTo(parent.absoluteLeft) - end.linkTo(parent.absoluteRight) - bottom.linkTo(seekbar.top) - }, - ) { - Text( - stringResource(R.string.player_gesture_seek_text, gestureSeekAmount, Utils.prettyTime(position.toInt())), - style = MaterialTheme.typography.headlineMedium.copy(shadow = Shadow(blurRadius = 5f)), - color = Color.White, - fontWeight = FontWeight.Bold, - textAlign = TextAlign.Center, - ) - } AnimatedVisibility( visible = (controlsShown && !areControlsLocked) || isLoading, enter = fadeIn(), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 34f921f..0b2d825 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,7 +66,6 @@ Page %d %d seconds x%.2f - [%d]\n%s Fit Screen Crop