diff options
| author | 2024-03-12 09:30:25 +0000 | |
|---|---|---|
| committer | 2024-03-12 09:30:25 +0000 | |
| commit | 74dd2d317fd0ba2b985e9450f4d456d0b476547f (patch) | |
| tree | fed45848649a1032ec5ec04818fa4c4b115a6ecc | |
| parent | 5af3282cdac7ccde608dbe94837a8167061d289c (diff) | |
| parent | 45001c1b29e22c7a4ba4e06e3048fa1c9d5bebe5 (diff) | |
Merge "Add vibrate icon to the ringer and notification sliders" into main
3 files changed, 39 insertions, 18 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt b/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt index 56b0bf74574f..91fa8c3c7587 100644 --- a/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt +++ b/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt @@ -23,6 +23,7 @@ import com.android.settingslib.volume.shared.model.AudioStream import com.android.settingslib.volume.shared.model.AudioStreamModel import com.android.settingslib.volume.shared.model.RingerMode import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map @@ -43,6 +44,9 @@ class AudioVolumeInteractor( streamModel.copy(volume = processVolume(streamModel, ringerMode, isZenMuted)) } + val ringerMode: StateFlow<RingerMode> + get() = audioRepository.ringerMode + suspend fun setVolume(audioStream: AudioStream, volume: Int) = audioRepository.setVolume(audioStream, volume) diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt index 18a62dca3769..3e0aee54ea34 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/volume/ui/composable/VolumeSlider.kt @@ -22,6 +22,7 @@ import androidx.compose.animation.expandVertically import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.size import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -30,6 +31,7 @@ import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp import com.android.compose.PlatformSlider import com.android.compose.PlatformSliderColors import com.android.systemui.common.ui.compose.Icon @@ -54,7 +56,7 @@ fun VolumeSlider( if (isDragging) { Text(text = value.toInt().toString()) } else { - state.icon?.let { Icon(icon = it) } + state.icon?.let { Icon(modifier = Modifier.size(24.dp), icon = it) } } }, colors = sliderColors, diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt index faf743475579..e8b1ee459384 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt @@ -21,6 +21,7 @@ import android.media.AudioManager import com.android.settingslib.volume.domain.interactor.AudioVolumeInteractor import com.android.settingslib.volume.shared.model.AudioStream import com.android.settingslib.volume.shared.model.AudioStreamModel +import com.android.settingslib.volume.shared.model.RingerMode import com.android.systemui.common.shared.model.Icon import com.android.systemui.res.R import com.android.systemui.volume.panel.component.volume.domain.interactor.VolumeSliderInteractor @@ -54,14 +55,6 @@ constructor( AudioStream(AudioManager.STREAM_NOTIFICATION) to R.drawable.ic_volume_ringer, AudioStream(AudioManager.STREAM_ALARM) to R.drawable.ic_volume_alarm, ) - private val mutedIconsByStream = - mapOf( - AudioStream(AudioManager.STREAM_MUSIC) to R.drawable.ic_volume_off, - AudioStream(AudioManager.STREAM_VOICE_CALL) to R.drawable.ic_volume_off, - AudioStream(AudioManager.STREAM_RING) to R.drawable.ic_volume_off, - AudioStream(AudioManager.STREAM_NOTIFICATION) to R.drawable.ic_volume_off, - AudioStream(AudioManager.STREAM_ALARM) to R.drawable.ic_volume_off, - ) private val labelsByStream = mapOf( AudioStream(AudioManager.STREAM_MUSIC) to R.string.stream_music, @@ -81,8 +74,9 @@ constructor( combine( audioVolumeInteractor.getAudioStream(audioStream), audioVolumeInteractor.canChangeVolume(audioStream), - ) { model, isEnabled -> - model.toState(value, isEnabled) + audioVolumeInteractor.ringerMode, + ) { model, isEnabled, ringerMode -> + model.toState(value, isEnabled, ringerMode) } .stateIn(coroutineScope, SharingStarted.Eagerly, EmptyState) @@ -100,7 +94,11 @@ constructor( } } - private fun AudioStreamModel.toState(value: Float, isEnabled: Boolean): State { + private fun AudioStreamModel.toState( + value: Float, + isEnabled: Boolean, + ringerMode: RingerMode, + ): State { return State( value = volumeSliderInteractor.processVolumeToValue( @@ -110,7 +108,7 @@ constructor( isMuted, ), valueRange = volumeSliderInteractor.displayValueRange, - icon = getIcon(this), + icon = getIcon(ringerMode), label = labelsByStream[audioStream]?.let(context::getString) ?: error("No label for the stream: $audioStream"), disabledMessage = disabledTextByStream[audioStream]?.let(context::getString), @@ -119,14 +117,31 @@ constructor( ) } - private fun getIcon(model: AudioStreamModel): Icon { - val isMutedOrNoVolume = model.isMuted || model.volume == model.minVolume + private fun AudioStreamModel.getIcon(ringerMode: RingerMode): Icon { + val isMutedOrNoVolume = isMuted || volume == minVolume val iconRes = if (isMutedOrNoVolume) { - mutedIconsByStream + when (audioStream.value) { + AudioManager.STREAM_MUSIC -> R.drawable.ic_volume_off + AudioManager.STREAM_VOICE_CALL -> R.drawable.ic_volume_off + AudioManager.STREAM_RING -> + if (ringerMode.value == AudioManager.RINGER_MODE_VIBRATE) { + R.drawable.ic_volume_ringer_vibrate + } else { + R.drawable.ic_volume_off + } + AudioManager.STREAM_NOTIFICATION -> + if (ringerMode.value == AudioManager.RINGER_MODE_VIBRATE) { + R.drawable.ic_volume_ringer_vibrate + } else { + R.drawable.ic_volume_off + } + AudioManager.STREAM_ALARM -> R.drawable.ic_volume_off + else -> null + } } else { - iconsByStream - }[audioStream] + iconsByStream[audioStream] + } ?: error("No icon for the stream: $audioStream") return Icon.Resource(iconRes, null) } |