Loading packages/SystemUI/src/com/android/systemui/volume/dialog/sliders/ui/viewmodel/VolumeDialogSliderViewModel.kt +15 −6 Original line number Diff line number Diff line Loading @@ -109,14 +109,19 @@ constructor( }, userVolumeUpdates, ) { isDisabledByZenMode, model, icon, currentVolumeUpdate -> val shouldIgnoreUpdates = val isInGracePeriod = currentVolumeUpdate != null && getTimestampMillis() - currentVolumeUpdate.timestampMillis < VOLUME_UPDATE_GRACE_PERIOD val isMinimumVolume = model.levelMin == currentVolumeUpdate?.level VolumeDialogSliderStateModel( value = if (currentVolumeUpdate != null && shouldIgnoreUpdates) { currentVolumeUpdate.newVolumeLevel if (currentVolumeUpdate != null && isInGracePeriod) { if (isMinimumVolume) { model.levelMin.toFloat() } else { currentVolumeUpdate.volume } } else { model.level.toFloat() }, Loading @@ -131,7 +136,7 @@ constructor( init { userVolumeUpdates .mapNotNull { it?.newVolumeLevel?.roundToInt() } .mapNotNull { it?.level } .distinctUntilChanged() .mapLatest { volume -> interactor.setStreamVolume(volume) Loading @@ -144,7 +149,7 @@ constructor( if (fromUser) { visibilityInteractor.resetDismissTimeout() userVolumeUpdates.value = VolumeUpdate(newVolumeLevel = volume, timestampMillis = getTimestampMillis()) VolumeUpdate(volume = volume, timestampMillis = getTimestampMillis()) } } Loading Loading @@ -190,5 +195,9 @@ constructor( private fun getTimestampMillis(): Long = systemClock.uptimeMillis() private data class VolumeUpdate(val newVolumeLevel: Float, val timestampMillis: Long) private data class VolumeUpdate(val volume: Float, val timestampMillis: Long) { val level: Int get() = volume.roundToInt() } } packages/SystemUI/src/com/android/systemui/volume/ui/compose/slider/Slider.kt +15 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.semantics.ProgressBarRangeInfo Loading Loading @@ -83,6 +84,7 @@ fun Slider( }, ) { require(stepDistance >= 0f) { "stepDistance must not be negative" } val coroutineScope = rememberCoroutineScope() var animationJob: Job? by remember { mutableStateOf(null) } val sliderState = remember(valueRange) { SliderState(value = value, valueRange = valueRange) } LaunchedEffect(value) { Loading Loading @@ -123,6 +125,19 @@ fun Slider( sliderState.onValueChangeFinished = { hapticsViewModel?.onValueChangeEnded() onValueChangeFinished?.invoke(sliderState.value) if (sliderState.value != value) { animationJob?.cancel() animationJob = coroutineScope.launchTraced("Slider#animateValue") { animate( initialValue = sliderState.value, targetValue = value, animationSpec = animationSpec, ) { animatedValue, _ -> sliderState.value = animatedValue } } } } sliderState.onValueChange = valueChange Loading Loading
packages/SystemUI/src/com/android/systemui/volume/dialog/sliders/ui/viewmodel/VolumeDialogSliderViewModel.kt +15 −6 Original line number Diff line number Diff line Loading @@ -109,14 +109,19 @@ constructor( }, userVolumeUpdates, ) { isDisabledByZenMode, model, icon, currentVolumeUpdate -> val shouldIgnoreUpdates = val isInGracePeriod = currentVolumeUpdate != null && getTimestampMillis() - currentVolumeUpdate.timestampMillis < VOLUME_UPDATE_GRACE_PERIOD val isMinimumVolume = model.levelMin == currentVolumeUpdate?.level VolumeDialogSliderStateModel( value = if (currentVolumeUpdate != null && shouldIgnoreUpdates) { currentVolumeUpdate.newVolumeLevel if (currentVolumeUpdate != null && isInGracePeriod) { if (isMinimumVolume) { model.levelMin.toFloat() } else { currentVolumeUpdate.volume } } else { model.level.toFloat() }, Loading @@ -131,7 +136,7 @@ constructor( init { userVolumeUpdates .mapNotNull { it?.newVolumeLevel?.roundToInt() } .mapNotNull { it?.level } .distinctUntilChanged() .mapLatest { volume -> interactor.setStreamVolume(volume) Loading @@ -144,7 +149,7 @@ constructor( if (fromUser) { visibilityInteractor.resetDismissTimeout() userVolumeUpdates.value = VolumeUpdate(newVolumeLevel = volume, timestampMillis = getTimestampMillis()) VolumeUpdate(volume = volume, timestampMillis = getTimestampMillis()) } } Loading Loading @@ -190,5 +195,9 @@ constructor( private fun getTimestampMillis(): Long = systemClock.uptimeMillis() private data class VolumeUpdate(val newVolumeLevel: Float, val timestampMillis: Long) private data class VolumeUpdate(val volume: Float, val timestampMillis: Long) { val level: Int get() = volume.roundToInt() } }
packages/SystemUI/src/com/android/systemui/volume/ui/compose/slider/Slider.kt +15 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.semantics.ProgressBarRangeInfo Loading Loading @@ -83,6 +84,7 @@ fun Slider( }, ) { require(stepDistance >= 0f) { "stepDistance must not be negative" } val coroutineScope = rememberCoroutineScope() var animationJob: Job? by remember { mutableStateOf(null) } val sliderState = remember(valueRange) { SliderState(value = value, valueRange = valueRange) } LaunchedEffect(value) { Loading Loading @@ -123,6 +125,19 @@ fun Slider( sliderState.onValueChangeFinished = { hapticsViewModel?.onValueChangeEnded() onValueChangeFinished?.invoke(sliderState.value) if (sliderState.value != value) { animationJob?.cancel() animationJob = coroutineScope.launchTraced("Slider#animateValue") { animate( initialValue = sliderState.value, targetValue = value, animationSpec = animationSpec, ) { animatedValue, _ -> sliderState.value = animatedValue } } } } sliderState.onValueChange = valueChange Loading