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

Commit 2b0b272d authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Include whether a mode is active in the subtext of dialog tiles" into main

parents 211784b7 8e0f3a7f
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ class ModesDialogViewModelTest : SysuiTestCase() {
            }
            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)!!) {
@@ -273,6 +273,62 @@ class ModesDialogViewModelTest : SysuiTestCase() {
            assertThat(tiles?.size).isEqualTo(0)
        }

    @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 {
+3 −0
Original line number Diff line number Diff line
@@ -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>

+10 −3
Original line number Diff line number Diff line
@@ -135,9 +135,16 @@ constructor(
            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 {