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

Commit 804db350 authored by Anton Potapov's avatar Anton Potapov
Browse files

Use currently active ZenMode icon in the Volume Dialog

Flag: com.android.systemui.volume_redesign
Fixes: 372466264
Test: manual on the phone. Open the new volume dialog with the active
zen mode blocking current stream and observe the icon

Change-Id: Ie20dc71c43f73bdad4eab3f0e88e166795accb6a
parent 84258941
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ constructor(private val viewModel: VolumeDialogSliderViewModel) {
        // coerce the current value to the new value range before animating it. This prevents
        // animating from the value that is outside of current [valueFrom, valueTo].
        value = value.coerceIn(valueFrom, valueTo)
        setTrackIconActiveStart(model.iconRes)
        trackIconActiveStart = model.icon
        if (isInitialUpdate) {
            value = model.value
        } else {
+62 −41
Original line number Diff line number Diff line
@@ -16,13 +16,16 @@

package com.android.systemui.volume.dialog.sliders.ui.viewmodel

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.media.AudioManager
import androidx.annotation.DrawableRes
import com.android.settingslib.notification.domain.interactor.NotificationsSoundPolicyInteractor
import com.android.settingslib.volume.domain.interactor.AudioVolumeInteractor
import com.android.settingslib.volume.shared.model.AudioStream
import com.android.settingslib.volume.shared.model.RingerMode
import com.android.systemui.res.R
import com.android.systemui.statusbar.policy.domain.interactor.ZenModeInteractor
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
@@ -31,11 +34,12 @@ import kotlinx.coroutines.flow.flowOf
class VolumeDialogSliderIconProvider
@Inject
constructor(
    private val notificationsSoundPolicyInteractor: NotificationsSoundPolicyInteractor,
    private val context: Context,
    private val zenModeInteractor: ZenModeInteractor,
    private val audioVolumeInteractor: AudioVolumeInteractor,
) {

    @DrawableRes
    @SuppressLint("UseCompatLoadingForDrawables")
    fun getStreamIcon(
        stream: Int,
        level: Int,
@@ -43,23 +47,46 @@ constructor(
        levelMax: Int,
        isMuted: Boolean,
        isRoutedToBluetooth: Boolean,
    ): Flow<Int> {
    ): Flow<Drawable> {
        return combine(
            notificationsSoundPolicyInteractor.isZenMuted(AudioStream(stream)),
            zenModeInteractor.activeModesBlockingStream(AudioStream(stream)),
            ringerModeForStream(stream),
        ) { isZenMuted, ringerMode ->
            val isStreamOffline = level == 0 || isMuted
            if (isZenMuted) {
                // TODO(b/372466264) use icon for the corresponding zenmode
                return@combine com.android.internal.R.drawable.ic_qs_dnd
        ) { activeModesBlockingStream, ringerMode ->
            if (activeModesBlockingStream.mainMode?.icon != null) {
                return@combine activeModesBlockingStream.mainMode.icon.drawable
            } else {
                context.getDrawable(
                    getIconRes(
                        stream,
                        level,
                        levelMin,
                        levelMax,
                        isMuted,
                        isRoutedToBluetooth,
                        ringerMode,
                    )
                )!!
            }
        }
    }

    @DrawableRes
    private fun getIconRes(
        stream: Int,
        level: Int,
        levelMin: Int,
        levelMax: Int,
        isMuted: Boolean,
        isRoutedToBluetooth: Boolean,
        ringerMode: RingerMode?,
    ): Int {
        val isStreamOffline = level == 0 || isMuted
        when (ringerMode?.value) {
                AudioManager.RINGER_MODE_VIBRATE ->
                    return@combine R.drawable.ic_volume_ringer_vibrate
                AudioManager.RINGER_MODE_SILENT -> return@combine R.drawable.ic_ring_volume_off
            AudioManager.RINGER_MODE_VIBRATE -> return R.drawable.ic_volume_ringer_vibrate
            AudioManager.RINGER_MODE_SILENT -> return R.drawable.ic_ring_volume_off
        }
        if (isRoutedToBluetooth) {
                return@combine if (stream == AudioManager.STREAM_VOICE_CALL) {
            return if (stream == AudioManager.STREAM_VOICE_CALL) {
                R.drawable.ic_volume_bt_sco
            } else {
                if (isStreamOffline) {
@@ -70,8 +97,14 @@ constructor(
            }
        }

            return@combine if (isStreamOffline) {
                getMutedIconForStream(stream) ?: getIconForStream(stream)
        return if (isStreamOffline) {
            when (stream) {
                AudioManager.STREAM_MUSIC -> R.drawable.ic_volume_media_mute
                AudioManager.STREAM_NOTIFICATION -> R.drawable.ic_volume_ringer_mute
                AudioManager.STREAM_ALARM -> R.drawable.ic_volume_alarm_mute
                AudioManager.STREAM_SYSTEM -> R.drawable.ic_volume_system_mute
                else -> null
            } ?: getIconForStream(stream)
        } else {
            if (level < (levelMax + levelMin) / 2) {
                // This icon is different on TV
@@ -81,18 +114,6 @@ constructor(
            }
        }
    }
    }

    @DrawableRes
    private fun getMutedIconForStream(stream: Int): Int? {
        return when (stream) {
            AudioManager.STREAM_MUSIC -> R.drawable.ic_volume_media_mute
            AudioManager.STREAM_NOTIFICATION -> R.drawable.ic_volume_ringer_mute
            AudioManager.STREAM_ALARM -> R.drawable.ic_volume_alarm_mute
            AudioManager.STREAM_SYSTEM -> R.drawable.ic_volume_system_mute
            else -> null
        }
    }

    @DrawableRes
    private fun getIconForStream(stream: Int): Int {
+4 −4
Original line number Diff line number Diff line
@@ -16,21 +16,21 @@

package com.android.systemui.volume.dialog.sliders.ui.viewmodel

import androidx.annotation.DrawableRes
import android.graphics.drawable.Drawable
import com.android.systemui.volume.dialog.shared.model.VolumeDialogStreamModel

data class VolumeDialogSliderStateModel(
    val minValue: Float,
    val maxValue: Float,
    val value: Float,
    @DrawableRes val iconRes: Int,
    val icon: Drawable,
)

fun VolumeDialogStreamModel.toStateModel(@DrawableRes iconRes: Int): VolumeDialogSliderStateModel {
fun VolumeDialogStreamModel.toStateModel(icon: Drawable): VolumeDialogSliderStateModel {
    return VolumeDialogSliderStateModel(
        minValue = levelMin.toFloat(),
        value = level.toFloat(),
        maxValue = levelMax.toFloat(),
        iconRes = iconRes,
        icon = icon,
    )
}