diff options
| author | 2024-04-23 15:11:32 +0000 | |
|---|---|---|
| committer | 2024-04-23 15:11:32 +0000 | |
| commit | e735e89e2ece44a5d2d65b7d24c2828bb411bdef (patch) | |
| tree | 8e9fafa7a09d00ff62f42873423bbae50aa72590 | |
| parent | 794e76db30250dd8b861038c9d11c7e66b0a1cd4 (diff) | |
| parent | 9697dc6e2560eb14b73ba3517c537c8daeeed3a9 (diff) | |
Merge "Make device icon always show the connected device." into main
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputActionsInteractor.kt | 8 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractor.kt | 2 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/shared/model/SessionWithPlaybackState.kt (renamed from packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/shared/model/SessionWithPlayback.kt) | 6 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/ui/viewmodel/MediaOutputViewModel.kt | 43 |
4 files changed, 26 insertions, 33 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputActionsInteractor.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputActionsInteractor.kt index eebb6fb42488..22c053099ac5 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputActionsInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputActionsInteractor.kt @@ -21,7 +21,7 @@ import com.android.systemui.animation.DialogCuj import com.android.systemui.animation.DialogTransitionAnimator import com.android.systemui.animation.Expandable import com.android.systemui.media.dialog.MediaOutputDialogManager -import com.android.systemui.volume.panel.component.mediaoutput.shared.model.SessionWithPlayback +import com.android.systemui.volume.panel.component.mediaoutput.shared.model.SessionWithPlaybackState import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope import javax.inject.Inject @@ -33,10 +33,10 @@ constructor( private val mediaOutputDialogManager: MediaOutputDialogManager, ) { - fun onBarClick(sessionWithPlayback: SessionWithPlayback?, expandable: Expandable) { - if (sessionWithPlayback?.playback?.isActive == true) { + fun onBarClick(sessionWithPlaybackState: SessionWithPlaybackState?, expandable: Expandable) { + if (sessionWithPlaybackState?.isPlaybackActive == true) { mediaOutputDialogManager.createAndShowWithController( - sessionWithPlayback.session.packageName, + sessionWithPlaybackState.session.packageName, false, expandable.dialogController() ) diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractor.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractor.kt index 41ad0358eae2..83b80294cfb6 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractor.kt @@ -94,7 +94,7 @@ constructor( /** Currently connected [MediaDevice]. */ val currentConnectedDevice: Flow<MediaDevice?> = - localMediaRepository.flatMapLatest { it.currentConnectedDevice } + localMediaRepository.flatMapLatest { it.currentConnectedDevice }.distinctUntilChanged() private suspend fun getApplicationLabel(packageName: String): CharSequence? { return try { diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/shared/model/SessionWithPlayback.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/shared/model/SessionWithPlaybackState.kt index c4476fc26113..bac969d040e2 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/shared/model/SessionWithPlayback.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/shared/model/SessionWithPlaybackState.kt @@ -16,9 +16,7 @@ package com.android.systemui.volume.panel.component.mediaoutput.shared.model -import android.media.session.PlaybackState - -data class SessionWithPlayback( +data class SessionWithPlaybackState( val session: MediaDeviceSession, - val playback: PlaybackState, + val isPlaybackActive: Boolean, ) diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/ui/viewmodel/MediaOutputViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/ui/viewmodel/MediaOutputViewModel.kt index f19fa20bd999..d60d981a3be1 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/ui/viewmodel/MediaOutputViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/ui/viewmodel/MediaOutputViewModel.kt @@ -25,7 +25,7 @@ import com.android.systemui.res.R import com.android.systemui.volume.panel.component.mediaoutput.domain.interactor.MediaDeviceSessionInteractor import com.android.systemui.volume.panel.component.mediaoutput.domain.interactor.MediaOutputActionsInteractor import com.android.systemui.volume.panel.component.mediaoutput.domain.interactor.MediaOutputInteractor -import com.android.systemui.volume.panel.component.mediaoutput.shared.model.SessionWithPlayback +import com.android.systemui.volume.panel.component.mediaoutput.shared.model.SessionWithPlaybackState import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope import com.android.systemui.volume.panel.shared.model.Result import com.android.systemui.volume.panel.ui.VolumePanelUiEvent @@ -35,10 +35,9 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.stateIn /** Models the UI of the Media Output Volume Panel component. */ @@ -55,20 +54,19 @@ constructor( private val uiEventLogger: UiEventLogger, ) { - private val sessionWithPlayback: StateFlow<Result<SessionWithPlayback?>> = + private val sessionWithPlaybackState: StateFlow<Result<SessionWithPlaybackState?>> = interactor.defaultActiveMediaSession .flatMapLatest { session -> if (session == null) { - flowOf(Result.Data<SessionWithPlayback?>(null)) + flowOf(Result.Data<SessionWithPlaybackState?>(null)) } else { - mediaDeviceSessionInteractor - .playbackState(session) - .map { playback -> - playback?.let { - Result.Data<SessionWithPlayback?>(SessionWithPlayback(session, it)) - } + mediaDeviceSessionInteractor.playbackState(session).mapNotNull { playback -> + playback?.let { + Result.Data<SessionWithPlaybackState?>( + SessionWithPlaybackState(session, playback.isActive()) + ) } - .filterNotNull() + } } } .stateIn( @@ -78,14 +76,14 @@ constructor( ) val connectedDeviceViewModel: StateFlow<ConnectedDeviceViewModel?> = - combine(sessionWithPlayback, interactor.currentConnectedDevice) { + combine(sessionWithPlaybackState, interactor.currentConnectedDevice) { mediaDeviceSession, currentConnectedDevice -> if (mediaDeviceSession !is Result.Data) { return@combine null } ConnectedDeviceViewModel( - if (mediaDeviceSession.data?.playback?.isActive == true) { + if (mediaDeviceSession.data?.isPlaybackActive == true) { context.getString( R.string.media_output_label_title, mediaDeviceSession.data.session.appLabel @@ -103,19 +101,16 @@ constructor( ) val deviceIconViewModel: StateFlow<DeviceIconViewModel?> = - combine(sessionWithPlayback, interactor.currentConnectedDevice) { + combine(sessionWithPlaybackState, interactor.currentConnectedDevice) { mediaDeviceSession, currentConnectedDevice -> if (mediaDeviceSession !is Result.Data) { return@combine null } - if (mediaDeviceSession.data?.playback?.isActive == true) { - val icon = - currentConnectedDevice?.icon?.let { Icon.Loaded(it, null) } - ?: Icon.Resource( - com.android.internal.R.drawable.ic_bt_headphones_a2dp, - null - ) + val icon: Icon = + currentConnectedDevice?.icon?.let { Icon.Loaded(it, null) } + ?: Icon.Resource(R.drawable.ic_media_home_devices, null) + if (mediaDeviceSession.data?.isPlaybackActive == true) { DeviceIconViewModel.IsPlaying( icon = icon, iconColor = @@ -125,7 +120,7 @@ constructor( ) } else { DeviceIconViewModel.IsNotPlaying( - icon = Icon.Resource(R.drawable.ic_media_home_devices, null), + icon = icon, iconColor = Color.Attribute( com.android.internal.R.attr.materialColorOnSurfaceVariant @@ -143,7 +138,7 @@ constructor( fun onBarClick(expandable: Expandable) { uiEventLogger.log(VolumePanelUiEvent.VOLUME_PANEL_MEDIA_OUTPUT_CLICKED) - val result = sessionWithPlayback.value + val result = sessionWithPlaybackState.value actionsInteractor.onBarClick((result as? Result.Data)?.data, expandable) } } |