Include whether a mode is active in the subtext of dialog tiles
Active modes with trigger descriptions now show "On * <Trigger Desc>", similarly as Settings does. This way not only the color is different between an active and inactive mode tile.
(This doesn't fix the non-annoucement in Talkback, but gets us closer).
Bug: 359845144
Test: atest ModesDialogViewModelTest
Flag: android.app.modes_ui
Change-Id: I34f22ab824f7e230f07e8623f44b796fd8219e23
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt
index 54b7d25..d2bc54e0 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt
@@ -152,7 +152,7 @@
}
with(tiles?.elementAt(1)!!) {
assertThat(this.text).isEqualTo("Active with manual")
- assertThat(this.subtext).isEqualTo("trigger description")
+ assertThat(this.subtext).isEqualTo("On • trigger description")
assertThat(this.enabled).isEqualTo(true)
}
with(tiles?.elementAt(2)!!) {
@@ -274,6 +274,62 @@
}
@Test
+ fun tiles_calculatesSubtext() =
+ testScope.runTest {
+ val tiles by collectLastValue(underTest.tiles)
+
+ repository.addModes(
+ listOf(
+ TestModeBuilder()
+ .setName("With description, inactive")
+ .setManualInvocationAllowed(true)
+ .setTriggerDescription("When the going gets tough")
+ .setActive(false)
+ .build(),
+ TestModeBuilder()
+ .setName("With description, active")
+ .setManualInvocationAllowed(true)
+ .setTriggerDescription("When in Rome")
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("With description, needs setup")
+ .setManualInvocationAllowed(true)
+ .setTriggerDescription("When you find yourself in a hole")
+ .setEnabled(false, /* byUser= */ false)
+ .build(),
+ TestModeBuilder()
+ .setName("Without description, inactive")
+ .setManualInvocationAllowed(true)
+ .setTriggerDescription(null)
+ .setActive(false)
+ .build(),
+ TestModeBuilder()
+ .setName("Without description, active")
+ .setManualInvocationAllowed(true)
+ .setTriggerDescription(null)
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("Without description, needs setup")
+ .setManualInvocationAllowed(true)
+ .setTriggerDescription(null)
+ .setEnabled(false, /* byUser= */ false)
+ .build(),
+ )
+ )
+ runCurrent()
+
+ assertThat(tiles!!).hasSize(6)
+ assertThat(tiles!![0].subtext).isEqualTo("When the going gets tough")
+ assertThat(tiles!![1].subtext).isEqualTo("On • When in Rome")
+ assertThat(tiles!![2].subtext).isEqualTo("Set up")
+ assertThat(tiles!![3].subtext).isEqualTo("Off")
+ assertThat(tiles!![4].subtext).isEqualTo("On")
+ assertThat(tiles!![5].subtext).isEqualTo("Set up")
+ }
+
+ @Test
fun onClick_togglesTileState() =
testScope.runTest {
val tiles by collectLastValue(underTest.tiles)
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 8a2e767..18b7073 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1106,6 +1106,9 @@
<!-- Priority modes: label for an active mode [CHAR LIMIT=35] -->
<string name="zen_mode_on">On</string>
+ <!-- Priority modes: label for an active mode, with details [CHAR LIMIT=10] -->
+ <string name="zen_mode_on_with_details">On • <xliff:g id="trigger_description" example="Mon-Fri, 23:00-7:00">%1$s</xliff:g></string>
+
<!-- Priority modes: label for an inactive mode [CHAR LIMIT=35] -->
<string name="zen_mode_off">Off</string>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModel.kt
index 5772099..16c18dd8c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModel.kt
@@ -135,9 +135,16 @@
return context.resources.getString(R.string.zen_mode_no_manual_invocation)
}
- val on = context.resources.getString(R.string.zen_mode_on)
- val off = context.resources.getString(R.string.zen_mode_off)
- return mode.getDynamicDescription(context) ?: if (mode.isActive) on else off
+ val modeSubtext = mode.getDynamicDescription(context)
+ return if (mode.isActive) {
+ if (modeSubtext != null) {
+ context.getString(R.string.zen_mode_on_with_details, modeSubtext)
+ } else {
+ context.getString(R.string.zen_mode_on)
+ }
+ } else {
+ modeSubtext ?: context.getString(R.string.zen_mode_off)
+ }
}
private fun makeZenModeDialog(): Dialog {