Merge "Spatial audio button should be toggled off when it's turned off" into main
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ButtonComponent.kt b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ButtonComponent.kt
index e15d315..0893b9d 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ButtonComponent.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ButtonComponent.kt
@@ -69,9 +69,19 @@
role = Role.Button
contentDescription = label
},
- color = MaterialTheme.colorScheme.tertiaryContainer,
+ color =
+ if (viewModel.isActive) {
+ MaterialTheme.colorScheme.tertiaryContainer
+ } else {
+ MaterialTheme.colorScheme.surface
+ },
shape = RoundedCornerShape(28.dp),
- contentColor = MaterialTheme.colorScheme.onTertiaryContainer,
+ contentColor =
+ if (viewModel.isActive) {
+ MaterialTheme.colorScheme.onTertiaryContainer
+ } else {
+ MaterialTheme.colorScheme.onSurface
+ },
onClick = onClick,
) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ToggleButtonComponent.kt b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ToggleButtonComponent.kt
index b2351c4..4f3a6c8 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ToggleButtonComponent.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/button/ui/composable/ToggleButtonComponent.kt
@@ -40,14 +40,14 @@
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.android.systemui.common.ui.compose.Icon
-import com.android.systemui.volume.panel.component.button.ui.viewmodel.ToggleButtonViewModel
+import com.android.systemui.volume.panel.component.button.ui.viewmodel.ButtonViewModel
import com.android.systemui.volume.panel.ui.composable.ComposeVolumePanelUiComponent
import com.android.systemui.volume.panel.ui.composable.VolumePanelComposeScope
import kotlinx.coroutines.flow.StateFlow
/** [ComposeVolumePanelUiComponent] implementing a toggleable button from a bottom row. */
class ToggleButtonComponent(
- private val viewModelFlow: StateFlow<ToggleButtonViewModel?>,
+ private val viewModelFlow: StateFlow<ButtonViewModel?>,
private val onCheckedChange: (isChecked: Boolean) -> Unit
) : ComposeVolumePanelUiComponent {
@@ -64,7 +64,7 @@
) {
BottomComponentButtonSurface {
val colors =
- if (viewModel.isChecked) {
+ if (viewModel.isActive) {
ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
contentColor = MaterialTheme.colorScheme.onTertiaryContainer,
@@ -81,7 +81,7 @@
role = Role.Switch
contentDescription = label
},
- onClick = { onCheckedChange(!viewModel.isChecked) },
+ onClick = { onCheckedChange(!viewModel.isActive) },
shape = RoundedCornerShape(28.dp),
colors = colors
) {
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/spatialaudio/ui/composable/SpatialAudioPopup.kt b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/spatialaudio/ui/composable/SpatialAudioPopup.kt
index f377fa6..12d2bc2 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/spatialaudio/ui/composable/SpatialAudioPopup.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/spatialaudio/ui/composable/SpatialAudioPopup.kt
@@ -52,7 +52,7 @@
VolumePanelUiEvent.VOLUME_PANEL_SPATIAL_AUDIO_POP_UP_SHOWN,
0,
null,
- viewModel.spatialAudioButtons.value.indexOfFirst { it.button.isChecked }
+ viewModel.spatialAudioButtons.value.indexOfFirst { it.button.isActive }
)
volumePanelPopup.show(expandable, { Title() }, { Content(it) })
}
@@ -85,7 +85,7 @@
for (buttonViewModel in enabledModelStates) {
val label = buttonViewModel.button.label.toString()
item(
- isSelected = buttonViewModel.button.isChecked,
+ isSelected = buttonViewModel.button.isActive,
onItemSelected = { viewModel.setEnabled(buttonViewModel.model) },
contentDescription = label,
icon = { Icon(icon = buttonViewModel.button.icon) },
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModelTest.kt
index fdeded8..4cf924a 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModelTest.kt
@@ -64,7 +64,7 @@
val buttonViewModel by collectLastValue(underTest.buttonViewModel)
runCurrent()
- assertThat(buttonViewModel!!.isChecked).isFalse()
+ assertThat(buttonViewModel!!.isActive).isFalse()
}
}
}
@@ -78,7 +78,7 @@
val buttonViewModel by collectLastValue(underTest.buttonViewModel)
runCurrent()
- assertThat(buttonViewModel!!.isChecked).isTrue()
+ assertThat(buttonViewModel!!.isActive).isTrue()
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ButtonViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ButtonViewModel.kt
index 754d258..4d11f44 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ButtonViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ButtonViewModel.kt
@@ -1,17 +1,17 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.android.systemui.volume.panel.component.button.ui.viewmodel
@@ -22,4 +22,5 @@
data class ButtonViewModel(
val icon: Icon,
val label: CharSequence,
+ val isActive: Boolean = true,
)
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ToggleButtonViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ToggleButtonViewModel.kt
deleted file mode 100644
index 6c47aec..0000000
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/button/ui/viewmodel/ToggleButtonViewModel.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.volume.panel.component.button.ui.viewmodel
-
-import com.android.systemui.common.shared.model.Icon
-
-data class ToggleButtonViewModel(
- val isChecked: Boolean,
- val icon: Icon,
- val label: CharSequence,
-)
-
-fun ToggleButtonViewModel.toButtonViewModel(): ButtonViewModel =
- ButtonViewModel(icon = icon, label = label)
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModel.kt
index 01421f8..ca5aef8 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/captioning/ui/viewmodel/CaptioningViewModel.kt
@@ -21,7 +21,7 @@
import com.android.settingslib.view.accessibility.domain.interactor.CaptioningInteractor
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.res.R
-import com.android.systemui.volume.panel.component.button.ui.viewmodel.ToggleButtonViewModel
+import com.android.systemui.volume.panel.component.button.ui.viewmodel.ButtonViewModel
import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope
import com.android.systemui.volume.panel.ui.VolumePanelUiEvent
import javax.inject.Inject
@@ -43,11 +43,11 @@
private val uiEventLogger: UiEventLogger,
) {
- val buttonViewModel: StateFlow<ToggleButtonViewModel?> =
+ val buttonViewModel: StateFlow<ButtonViewModel?> =
captioningInteractor.isSystemAudioCaptioningEnabled
.map { isEnabled ->
- ToggleButtonViewModel(
- isChecked = isEnabled,
+ ButtonViewModel(
+ isActive = isEnabled,
icon =
Icon.Resource(
if (isEnabled) R.drawable.ic_volume_odi_captions
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioButtonViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioButtonViewModel.kt
index e5c5a65..f7a602e 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioButtonViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioButtonViewModel.kt
@@ -16,10 +16,10 @@
package com.android.systemui.volume.panel.component.spatial.ui.viewmodel
-import com.android.systemui.volume.panel.component.button.ui.viewmodel.ToggleButtonViewModel
+import com.android.systemui.volume.panel.component.button.ui.viewmodel.ButtonViewModel
import com.android.systemui.volume.panel.component.spatial.domain.model.SpatialAudioEnabledModel
data class SpatialAudioButtonViewModel(
val model: SpatialAudioEnabledModel,
- val button: ToggleButtonViewModel,
+ val button: ButtonViewModel,
)
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioViewModel.kt
index b5e9ed2..4b2d26a 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/spatial/ui/viewmodel/SpatialAudioViewModel.kt
@@ -22,8 +22,6 @@
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.res.R
import com.android.systemui.volume.panel.component.button.ui.viewmodel.ButtonViewModel
-import com.android.systemui.volume.panel.component.button.ui.viewmodel.ToggleButtonViewModel
-import com.android.systemui.volume.panel.component.button.ui.viewmodel.toButtonViewModel
import com.android.systemui.volume.panel.component.spatial.domain.SpatialAudioAvailabilityCriteria
import com.android.systemui.volume.panel.component.spatial.domain.interactor.SpatialAudioComponentInteractor
import com.android.systemui.volume.panel.component.spatial.domain.model.SpatialAudioAvailabilityModel
@@ -53,8 +51,8 @@
val spatialAudioButton: StateFlow<ButtonViewModel?> =
interactor.isEnabled
.map {
- it.toViewModel(true)
- .toButtonViewModel()
+ val isChecked = it is SpatialAudioEnabledModel.SpatialAudioEnabled
+ it.toViewModel(isChecked)
.copy(label = context.getString(R.string.volume_panel_spatial_audio_title))
}
.stateIn(scope, SharingStarted.Eagerly, null)
@@ -76,8 +74,7 @@
}
.map { isEnabled ->
val isChecked = isEnabled == currentIsEnabled
- val buttonViewModel: ToggleButtonViewModel =
- isEnabled.toViewModel(isChecked)
+ val buttonViewModel: ButtonViewModel = isEnabled.toViewModel(isChecked)
SpatialAudioButtonViewModel(button = buttonViewModel, model = isEnabled)
}
}
@@ -100,26 +97,26 @@
scope.launch { interactor.setEnabled(model) }
}
- private fun SpatialAudioEnabledModel.toViewModel(isChecked: Boolean): ToggleButtonViewModel {
+ private fun SpatialAudioEnabledModel.toViewModel(isChecked: Boolean): ButtonViewModel {
if (this is SpatialAudioEnabledModel.HeadTrackingEnabled) {
- return ToggleButtonViewModel(
- isChecked = isChecked,
+ return ButtonViewModel(
+ isActive = isChecked,
icon = Icon.Resource(R.drawable.ic_head_tracking, contentDescription = null),
label = context.getString(R.string.volume_panel_spatial_audio_tracking)
)
}
if (this is SpatialAudioEnabledModel.SpatialAudioEnabled) {
- return ToggleButtonViewModel(
- isChecked = isChecked,
+ return ButtonViewModel(
+ isActive = isChecked,
icon = Icon.Resource(R.drawable.ic_spatial_audio, contentDescription = null),
label = context.getString(R.string.volume_panel_spatial_audio_fixed)
)
}
if (this is SpatialAudioEnabledModel.Disabled) {
- return ToggleButtonViewModel(
- isChecked = isChecked,
+ return ButtonViewModel(
+ isActive = isChecked,
icon = Icon.Resource(R.drawable.ic_spatial_audio_off, contentDescription = null),
label = context.getString(R.string.volume_panel_spatial_audio_off)
)