Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45001c1b authored by Anton Potapov's avatar Anton Potapov
Browse files

Add vibrate icon to the ringer and notification sliders

Flag: aconfig new_volume_panel TEAMFOOD
Test: manual on the phone
Fixes: 327599191
Change-Id: I51485beae08cd127df08ef51f4325be1e58137e1
parent 80b15219
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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)

+3 −1
Original line number Diff line number Diff line
@@ -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,
+32 −17
Original line number Diff line number Diff line
@@ -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 {
                iconsByStream
            }[audioStream]
                            R.drawable.ic_volume_off
                        }
                    AudioManager.STREAM_ALARM -> R.drawable.ic_volume_off
                    else -> null
                }
            } else {
                iconsByStream[audioStream]
            }
                ?: error("No icon for the stream: $audioStream")
        return Icon.Resource(iconRes, null)
    }