From 717bf3c8e10cb041a1fc4453db3ea4d8dd1a03de Mon Sep 17 00:00:00 2001 From: Barnabas Balogh Date: Wed, 3 Jun 2026 20:59:47 +0200 Subject: [PATCH] fix(playback): Add clamp effect to brightness sliders --- .../purefin/ui/screen/player/PlayerScreen.kt | 23 ++++++++++++------- .../components/PlayerAdjustmentIndicator.kt | 15 +++++++----- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/hu/bbara/purefin/ui/screen/player/PlayerScreen.kt b/app/src/main/java/hu/bbara/purefin/ui/screen/player/PlayerScreen.kt index d53404fe..bfe4ecaf 100644 --- a/app/src/main/java/hu/bbara/purefin/ui/screen/player/PlayerScreen.kt +++ b/app/src/main/java/hu/bbara/purefin/ui/screen/player/PlayerScreen.kt @@ -62,7 +62,7 @@ import kotlin.math.roundToInt private const val CONTROLS_VISIBLE_SUBTITLE_BOTTOM_PADDING_FRACTION = 0.32f /** Small negative band below zero that represents adaptive/auto brightness mode. */ -private const val AUTO_BRIGHTNESS_SENTINEL = -0.1f +private const val AUTO_BRIGHTNESS_THRESHOLD = -0.15f @OptIn(UnstableApi::class) @Composable @@ -129,7 +129,7 @@ fun PlayerScreen( onDoubleTapCenter = { viewModel.togglePlayPause() }, onVerticalDragLeft = { delta -> val diff = (-delta / 800f) - brightness = (brightness + diff).coerceIn(AUTO_BRIGHTNESS_SENTINEL, 1f) + brightness = (brightness + diff).coerceIn(AUTO_BRIGHTNESS_THRESHOLD, 1f) applyBrightness(activity, brightness) }, onVerticalDragRight = { delta -> @@ -195,11 +195,17 @@ fun PlayerScreen( .padding(start = 20.dp) ) { currentBrightness -> PlayerAdjustmentIndicator( - modifier = Modifier - .align(Alignment.Center), + modifier = Modifier.align(Alignment.Center), icon = Icons.Outlined.BrightnessMedium, contentDescription = "Brightness", - value = currentBrightness + value = currentBrightness, + bottomText = if (currentBrightness <= AUTO_BRIGHTNESS_THRESHOLD) { + "Auto" + } else if (currentBrightness >= 0f) { + "${(currentBrightness * 100).roundToInt()}%" + } else { + null + } ) } @@ -215,7 +221,8 @@ fun PlayerScreen( .align(Alignment.Center), icon = Icons.Outlined.VolumeUp, contentDescription = "Volume", - value = currentVolume + value = currentVolume, + bottomText = "${(currentVolume.coerceIn(0f, 1f) * 100).roundToInt()}%" ) } @@ -366,12 +373,12 @@ private fun formatSeekDelta(deltaMs: Long): String { private fun readCurrentBrightness(activity: Activity?): Float { val current = activity?.window?.attributes?.screenBrightness - return if (current != null && current >= 0) current else AUTO_BRIGHTNESS_SENTINEL + return if (current != null && current >= 0) current else -1f } private fun applyBrightness(activity: Activity?, value: Float) { activity ?: return val params = activity.window.attributes - params.screenBrightness = if (value < 0f) -1f else value + params.screenBrightness = if (value <= AUTO_BRIGHTNESS_THRESHOLD) -1f else value activity.window.attributes = params } diff --git a/app/src/main/java/hu/bbara/purefin/ui/screen/player/components/PlayerAdjustmentIndicator.kt b/app/src/main/java/hu/bbara/purefin/ui/screen/player/components/PlayerAdjustmentIndicator.kt index b54ea1e8..a5b3f58d 100644 --- a/app/src/main/java/hu/bbara/purefin/ui/screen/player/components/PlayerAdjustmentIndicator.kt +++ b/app/src/main/java/hu/bbara/purefin/ui/screen/player/components/PlayerAdjustmentIndicator.kt @@ -13,6 +13,8 @@ import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -20,7 +22,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import kotlin.math.roundToInt @Composable fun PlayerAdjustmentIndicator( @@ -28,12 +29,15 @@ fun PlayerAdjustmentIndicator( icon: ImageVector, contentDescription: String?, value: Float, + bottomText: String? = null, sliderHeight: Dp = 140.dp, ) { val scheme = MaterialTheme.colorScheme - val isAuto = value < 0f - val percent = if (isAuto) 0 else (value * 100).roundToInt() val clamped = value.coerceIn(0f, 1f) + val previousBottomText = remember { mutableStateOf("-") } + if (bottomText != null) { + previousBottomText.value = bottomText + } Box( modifier = modifier @@ -69,10 +73,9 @@ fun PlayerAdjustmentIndicator( ) } Spacer(modifier = Modifier.height(16.dp)) - val label = if (isAuto) "Auto" else "$percent%" Text( - text = label, - color = if (isAuto) scheme.tertiary else scheme.onSurface, + text = previousBottomText.value, + color = scheme.onSurface, style = MaterialTheme.typography.titleMedium ) }