mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-24 03:36:51 +00:00
fix(playback): Add clamp effect to brightness sliders
This commit is contained in:
@@ -62,7 +62,7 @@ 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
|
||||||
/** Small negative band below zero that represents adaptive/auto brightness mode. */
|
/** 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)
|
@OptIn(UnstableApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -129,7 +129,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(AUTO_BRIGHTNESS_SENTINEL, 1f)
|
brightness = (brightness + diff).coerceIn(AUTO_BRIGHTNESS_THRESHOLD, 1f)
|
||||||
applyBrightness(activity, brightness)
|
applyBrightness(activity, brightness)
|
||||||
},
|
},
|
||||||
onVerticalDragRight = { delta ->
|
onVerticalDragRight = { delta ->
|
||||||
@@ -195,11 +195,17 @@ fun PlayerScreen(
|
|||||||
.padding(start = 20.dp)
|
.padding(start = 20.dp)
|
||||||
) { currentBrightness ->
|
) { currentBrightness ->
|
||||||
PlayerAdjustmentIndicator(
|
PlayerAdjustmentIndicator(
|
||||||
modifier = Modifier
|
modifier = Modifier.align(Alignment.Center),
|
||||||
.align(Alignment.Center),
|
|
||||||
icon = Icons.Outlined.BrightnessMedium,
|
icon = Icons.Outlined.BrightnessMedium,
|
||||||
contentDescription = "Brightness",
|
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),
|
.align(Alignment.Center),
|
||||||
icon = Icons.Outlined.VolumeUp,
|
icon = Icons.Outlined.VolumeUp,
|
||||||
contentDescription = "Volume",
|
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 {
|
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 AUTO_BRIGHTNESS_SENTINEL
|
return if (current != null && current >= 0) current else -1f
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = if (value < 0f) -1f else value
|
params.screenBrightness = if (value <= AUTO_BRIGHTNESS_THRESHOLD) -1f else value
|
||||||
activity.window.attributes = params
|
activity.window.attributes = params
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
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.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PlayerAdjustmentIndicator(
|
fun PlayerAdjustmentIndicator(
|
||||||
@@ -28,12 +29,15 @@ fun PlayerAdjustmentIndicator(
|
|||||||
icon: ImageVector,
|
icon: ImageVector,
|
||||||
contentDescription: String?,
|
contentDescription: String?,
|
||||||
value: Float,
|
value: Float,
|
||||||
|
bottomText: String? = null,
|
||||||
sliderHeight: Dp = 140.dp,
|
sliderHeight: Dp = 140.dp,
|
||||||
) {
|
) {
|
||||||
val scheme = MaterialTheme.colorScheme
|
val scheme = MaterialTheme.colorScheme
|
||||||
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)
|
||||||
|
val previousBottomText = remember { mutableStateOf("-") }
|
||||||
|
if (bottomText != null) {
|
||||||
|
previousBottomText.value = bottomText
|
||||||
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
@@ -69,10 +73,9 @@ fun PlayerAdjustmentIndicator(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
val label = if (isAuto) "Auto" else "$percent%"
|
|
||||||
Text(
|
Text(
|
||||||
text = label,
|
text = previousBottomText.value,
|
||||||
color = if (isAuto) scheme.tertiary else scheme.onSurface,
|
color = scheme.onSurface,
|
||||||
style = MaterialTheme.typography.titleMedium
|
style = MaterialTheme.typography.titleMedium
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user