mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-23 19:26:50 +00:00
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 [-0.1,1] so a small flick below 0 enters auto mode - readCurrentBrightness returns -0.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:
@@ -64,6 +64,8 @@ import kotlin.math.roundToInt
|
|||||||
|
|
||||||
private const val CONTROLS_VISIBLE_SUBTITLE_BOTTOM_PADDING_FRACTION = 0.32f
|
private const val CONTROLS_VISIBLE_SUBTITLE_BOTTOM_PADDING_FRACTION = 0.32f
|
||||||
private const val WIDE_VIDEO_ASPECT_RATIO = 16f / 9f
|
private const val WIDE_VIDEO_ASPECT_RATIO = 16f / 9f
|
||||||
|
/** Small negative band below zero that represents adaptive/auto brightness mode. */
|
||||||
|
private const val AUTO_BRIGHTNESS_SENTINEL = -0.1f
|
||||||
|
|
||||||
@OptIn(UnstableApi::class)
|
@OptIn(UnstableApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -148,7 +150,7 @@ fun PlayerScreen(
|
|||||||
onDoubleTapCenter = { viewModel.togglePlayPause() },
|
onDoubleTapCenter = { viewModel.togglePlayPause() },
|
||||||
onVerticalDragLeft = { delta ->
|
onVerticalDragLeft = { delta ->
|
||||||
val diff = (-delta / 800f)
|
val diff = (-delta / 800f)
|
||||||
brightness = (brightness + diff).coerceIn(0f, 1f)
|
brightness = (brightness + diff).coerceIn(AUTO_BRIGHTNESS_SENTINEL, 1f)
|
||||||
applyBrightness(activity, brightness)
|
applyBrightness(activity, brightness)
|
||||||
},
|
},
|
||||||
onVerticalDragRight = { delta ->
|
onVerticalDragRight = { delta ->
|
||||||
@@ -400,12 +402,12 @@ private fun formatSeekDelta(deltaMs: Long): String {
|
|||||||
|
|
||||||
private fun readCurrentBrightness(activity: Activity?): Float {
|
private fun readCurrentBrightness(activity: Activity?): Float {
|
||||||
val current = activity?.window?.attributes?.screenBrightness
|
val current = activity?.window?.attributes?.screenBrightness
|
||||||
return if (current != null && current >= 0) current else 0.5f
|
return if (current != null && current >= 0) current else AUTO_BRIGHTNESS_SENTINEL
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyBrightness(activity: Activity?, value: Float) {
|
private fun applyBrightness(activity: Activity?, value: Float) {
|
||||||
activity ?: return
|
activity ?: return
|
||||||
val params = activity.window.attributes
|
val params = activity.window.attributes
|
||||||
params.screenBrightness = value
|
params.screenBrightness = if (value < 0f) -1f else value
|
||||||
activity.window.attributes = params
|
activity.window.attributes = params
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ fun PlayerAdjustmentIndicator(
|
|||||||
sliderHeight: Dp = 140.dp,
|
sliderHeight: Dp = 140.dp,
|
||||||
) {
|
) {
|
||||||
val scheme = MaterialTheme.colorScheme
|
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)
|
val clamped = value.coerceIn(0f, 1f)
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
@@ -68,9 +69,10 @@ fun PlayerAdjustmentIndicator(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
val label = if (isAuto) "Auto" else "$percent%"
|
||||||
Text(
|
Text(
|
||||||
text = "$percent%",
|
text = label,
|
||||||
color = scheme.onSurface,
|
color = if (isAuto) scheme.tertiary else scheme.onSurface,
|
||||||
style = MaterialTheme.typography.titleMedium
|
style = MaterialTheme.typography.titleMedium
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user