fix(playback): Add clamp effect to brightness sliders

This commit is contained in:
2026-06-03 20:59:47 +02:00
parent 0011f3842a
commit 717bf3c8e1
2 changed files with 24 additions and 14 deletions

View File

@@ -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
}

View File

@@ -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
)
}