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

Commit 302b7e39 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix audio sharing and cast icons" into main

parents d15b4b88 94529617
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context
import android.graphics.drawable.Drawable
import android.media.AudioManager
import androidx.annotation.DrawableRes
import com.android.settingslib.R as SettingsR
import com.android.settingslib.volume.domain.interactor.AudioVolumeInteractor
import com.android.settingslib.volume.shared.model.AudioStream
import com.android.settingslib.volume.shared.model.RingerMode
@@ -30,8 +31,10 @@ import com.android.systemui.statusbar.policy.domain.model.ActiveZenModes
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf

@SuppressLint("UseCompatLoadingForDrawables")
class VolumeDialogSliderIconProvider
@Inject
constructor(
@@ -40,7 +43,30 @@ constructor(
    private val audioVolumeInteractor: AudioVolumeInteractor,
) {

    @SuppressLint("UseCompatLoadingForDrawables")
    fun getAudioSharingIcon(isMuted: Boolean): Flow<Drawable> {
        return flow {
            val iconRes =
                if (isMuted) {
                    R.drawable.ic_volume_media_bt_mute
                } else {
                    R.drawable.ic_volume_media_bt
                }
            emit(context.getDrawable(iconRes)!!)
        }
    }

    fun getCastIcon(isMuted: Boolean): Flow<Drawable> {
        return flow {
            val iconRes =
                if (isMuted) {
                    SettingsR.drawable.ic_volume_remote_mute
                } else {
                    SettingsR.drawable.ic_volume_remote
                }
            emit(context.getDrawable(iconRes)!!)
        }
    }

    fun getStreamIcon(
        stream: Int,
        level: Int,
+19 −9
Original line number Diff line number Diff line
@@ -57,12 +57,12 @@ private const val VOLUME_UPDATE_GRACE_PERIOD = 1000
class VolumeDialogSliderViewModel
@Inject
constructor(
    private val sliderType: VolumeDialogSliderType,
    private val interactor: VolumeDialogSliderInteractor,
    private val visibilityInteractor: VolumeDialogVisibilityInteractor,
    @VolumeDialog private val coroutineScope: CoroutineScope,
    private val volumeDialogSliderIconProvider: VolumeDialogSliderIconProvider,
    private val systemClock: SystemClock,
    private val sliderType: VolumeDialogSliderType,
    private val logger: VolumeDialogLogger,
) {

@@ -82,14 +82,24 @@ constructor(
        model
            .flatMapLatest { streamModel ->
                with(streamModel) {
                        val isMuted = muteSupported && muted
                        when (sliderType) {
                            is VolumeDialogSliderType.Stream ->
                                volumeDialogSliderIconProvider.getStreamIcon(
                            stream = stream,
                                    stream = sliderType.audioStream,
                                    level = level,
                                    levelMin = levelMin,
                                    levelMax = levelMax,
                            isMuted = muteSupported && muted,
                                    isMuted = isMuted,
                                    isRoutedToBluetooth = routedToBluetooth,
                                )
                            is VolumeDialogSliderType.RemoteMediaStream -> {
                                volumeDialogSliderIconProvider.getCastIcon(isMuted)
                            }
                            is VolumeDialogSliderType.AudioSharingStream -> {
                                volumeDialogSliderIconProvider.getAudioSharingIcon(isMuted)
                            }
                        }
                    }
                    .map { icon -> streamModel.toStateModel(icon) }
            }