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

Commit 4633ede4 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Support the case when the playing device is unknown in the MediaOutputComponent." into main

parents 933832f0 862b1083
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -92,7 +92,12 @@ constructor(
                        true
                    }
                },
            color = MaterialTheme.colorScheme.surface,
            color =
                if (enabled) {
                    MaterialTheme.colorScheme.surface
                } else {
                    MaterialTheme.colorScheme.surfaceContainerHighest
                },
            shape = RoundedCornerShape(28.dp),
            onClick =
                if (enabled) {
@@ -119,7 +124,7 @@ constructor(
                modifier = Modifier.basicMarquee(),
                text = connectedDeviceViewModel.label.toString(),
                style = MaterialTheme.typography.labelMedium,
                color = MaterialTheme.colorScheme.onSurfaceVariant,
                color = connectedDeviceViewModel.labelColor.toColor(),
                maxLines = 1,
            )
            connectedDeviceViewModel.deviceName?.let {
@@ -127,7 +132,7 @@ constructor(
                    modifier = Modifier.basicMarquee(),
                    text = it.toString(),
                    style = MaterialTheme.typography.titleMedium,
                    color = MaterialTheme.colorScheme.onSurface,
                    color = connectedDeviceViewModel.deviceNameColor.toColor(),
                    maxLines = 1,
                )
            }
+15 −14
Original line number Diff line number Diff line
@@ -25,13 +25,13 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.paneTitle
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.theme.PlatformTheme
import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.res.R
import com.android.systemui.volume.panel.ui.layout.ComponentsLayout
@@ -43,7 +43,6 @@ private const val VolumePanelTestTag = "VolumePanel"
private val padding = 24.dp

@Composable
@OptIn(ExperimentalComposeUiApi::class)
fun VolumePanelRoot(
    viewModel: VolumePanelViewModel,
    modifier: Modifier = Modifier,
@@ -54,6 +53,7 @@ fun VolumePanelRoot(

    with(VolumePanelComposeScope(state)) {
        components?.let { componentsState ->
            PlatformTheme {
                Components(
                    componentsState,
                    modifier
@@ -69,6 +69,7 @@ fun VolumePanelRoot(
            }
        }
    }
}

@Composable
private fun VolumePanelComposeScope.Components(
+10 −4
Original line number Diff line number Diff line
@@ -90,8 +90,9 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() {
                assertThat(model)
                    .isEqualTo(
                        MediaOutputComponentModel.Calling(
                            AudioOutputDevice.BuiltIn(builtInDeviceName, testIcon),
                            false,
                            device = AudioOutputDevice.BuiltIn(builtInDeviceName, testIcon),
                            isInAudioSharing = false,
                            canOpenAudioSwitcher = false,
                        )
                    )
            }
@@ -101,6 +102,9 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() {
    fun hasSession_stateIs_MediaSession() =
        with(kosmos) {
            testScope.runTest {
                localMediaRepository.updateCurrentConnectedDevice(
                    TestMediaDevicesFactory.builtInMediaDevice()
                )
                mediaControllerRepository.setActiveSessions(listOf(localMediaController))

                val model by collectLastValue(underTest.mediaOutputModel.filterData())
@@ -113,6 +117,7 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() {
                    assertThat(device)
                        .isEqualTo(AudioOutputDevice.BuiltIn("built_in_media", testIcon))
                    assertThat(isInAudioSharing).isFalse()
                    assertThat(canOpenAudioSwitcher).isTrue()
                }
            }
        }
@@ -129,8 +134,9 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() {
                assertThat(model)
                    .isEqualTo(
                        MediaOutputComponentModel.Idle(
                            AudioOutputDevice.BuiltIn("built_in_media", testIcon),
                            true,
                            device = AudioOutputDevice.BuiltIn("built_in_media", testIcon),
                            isInAudioSharing = true,
                            canOpenAudioSwitcher = false,
                        )
                    )
            }
+6 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ constructor(
            }
            .map { it ?: AudioOutputDevice.Unknown }
            .flowOn(backgroundCoroutineContext)
            .stateIn(scope, SharingStarted.Eagerly, AudioOutputDevice.Unknown)
            .stateIn(scope, SharingStarted.Eagerly, AudioOutputDevice.Unavailable)

    private fun AudioDeviceInfo.toAudioOutputDevice(): AudioOutputDevice {
        if (
@@ -120,6 +120,11 @@ constructor(
                    name = name,
                    icon = icon,
                )
            deviceType == MediaDeviceType.TYPE_CAST_DEVICE ->
                AudioOutputDevice.Remote(
                    name = name,
                    icon = icon,
                )
            else ->
                AudioOutputDevice.BuiltIn(
                    name = name,
+18 −0
Original line number Diff line number Diff line
@@ -31,6 +31,12 @@ sealed interface AudioOutputDevice {
        override val icon: Drawable?,
    ) : AudioOutputDevice

    /** Models a cast audio output device. */
    data class Remote(
        override val name: String,
        override val icon: Drawable?,
    ) : AudioOutputDevice

    /** Models a wired audio output device. */
    data class Wired(
        override val name: String,
@@ -52,4 +58,16 @@ sealed interface AudioOutputDevice {
        override val icon: Drawable
            get() = error("Unsupported for unknown device")
    }

    /**
     * Models a state when current audio output device is not loaded yet or the system failed to
     * load it.
     */
    data object Unavailable : AudioOutputDevice {
        override val name: String
            get() = error("Unsupported for unavailable device")

        override val icon: Drawable
            get() = error("Unsupported for unavailable device")
    }
}
Loading