feat(player): add adaptive brightness mode support

Extend the brightness slider to allow values below 0% which triggers
adaptive/auto brightness mode (screenBrightness = -1.0f). The brightness
indicator shows 'Auto' with an empty bar when in adaptive mode.

- Widen gesture range from [0,1] to [-1,1] so dragging below 0 enters auto mode
- readCurrentBrightness returns -1f instead of 0.5f when system auto is active
- applyBrightness writes -1f to LayoutParams when value < 0
- PlayerAdjustmentIndicator displays 'Auto' in tertiary color for negative values
This commit is contained in:
Purefin Dev
2026-05-22 16:41:58 +00:00
parent 1274ab25f9
commit 70a587b743
2 changed files with 8 additions and 6 deletions

View File

@@ -148,7 +148,7 @@ fun PlayerScreen(
onDoubleTapCenter = { viewModel.togglePlayPause() },
onVerticalDragLeft = { delta ->
val diff = (-delta / 800f)
brightness = (brightness + diff).coerceIn(0f, 1f)
brightness = (brightness + diff).coerceIn(-1f, 1f)
applyBrightness(activity, brightness)
},
onVerticalDragRight = { delta ->
@@ -400,12 +400,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 0.5f
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 = value
params.screenBrightness = if (value < 0f) -1f else value
activity.window.attributes = params
}

View File

@@ -31,7 +31,8 @@ fun PlayerAdjustmentIndicator(
sliderHeight: Dp = 140.dp,
) {
val scheme = MaterialTheme.colorScheme
val percent = (value.coerceIn(0f, 1f) * 100).roundToInt()
val isAuto = value < 0f
val percent = if (isAuto) 0 else (value * 100).roundToInt()
val clamped = value.coerceIn(0f, 1f)
Box(
@@ -68,9 +69,10 @@ fun PlayerAdjustmentIndicator(
)
}
Spacer(modifier = Modifier.height(16.dp))
val label = if (isAuto) "Auto" else "$percent%"
Text(
text = "$percent%",
color = scheme.onSurface,
text = label,
color = if (isAuto) scheme.tertiary else scheme.onSurface,
style = MaterialTheme.typography.titleMedium
)
}