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

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

Merge "Announce new state of modes when toggled in Modes Dialog" into main

parents d376ad97 008cfe42
Loading
Loading
Loading
Loading
+61 −0
Original line number Diff line number Diff line
@@ -329,6 +329,67 @@ class ModesDialogViewModelTest : SysuiTestCase() {
            assertThat(tiles!![5].subtext).isEqualTo("Set up")
        }

    @Test
    fun tiles_calculatesContentDescription() =
        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].contentDescription)
                .isEqualTo("With description, inactive\nOff\nWhen the going gets tough")
            assertThat(tiles!![1].contentDescription)
                .isEqualTo("With description, active\nOn\nWhen in Rome")
            assertThat(tiles!![2].contentDescription)
                .isEqualTo("With description, needs setup\nSet up")
            assertThat(tiles!![3].contentDescription)
                .isEqualTo("Without description, inactive\nOff")
            assertThat(tiles!![4].contentDescription).isEqualTo("Without description, active\nOn")
            assertThat(tiles!![5].contentDescription)
                .isEqualTo("Without description, needs setup\nSet up")
        }

    @Test
    fun onClick_togglesTileState() =
        testScope.runTest {
+6 −1
Original line number Diff line number Diff line
@@ -33,6 +33,9 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.android.systemui.common.ui.compose.Icon
@@ -58,7 +61,9 @@ fun ModeTile(viewModel: ModeTileViewModel) {
                            onClick = viewModel.onClick,
                            onLongClick = viewModel.onLongClick
                        )
                        .padding(20.dp),
                        .padding(20.dp)
                        .semantics(mergeDescendants = true) {}
                        .clearAndSetSemantics { contentDescription = viewModel.contentDescription },
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement =
                    Arrangement.spacedBy(
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ data class ModeTileViewModel(
    val icon: Icon,
    val text: String,
    val subtext: String,
    val contentDescription: String,
    val enabled: Boolean,
    val onClick: () -> Unit,
    val onLongClick: () -> Unit,
+21 −1
Original line number Diff line number Diff line
@@ -89,8 +89,9 @@ constructor(
                    ModeTileViewModel(
                        id = mode.id,
                        icon = zenModeInteractor.getModeIcon(mode, context),
                        text = mode.rule.name,
                        text = mode.name,
                        subtext = getTileSubtext(mode),
                        contentDescription = getTileContentDescription(mode),
                        enabled = mode.isActive,
                        onClick = {
                            if (!mode.rule.isEnabled) {
@@ -147,6 +148,25 @@ constructor(
        }
    }

    private fun getTileContentDescription(mode: ZenMode): String {
        return buildList {
                add(mode.name)
                if (!mode.rule.isEnabled) {
                    add(context.getString(R.string.zen_mode_set_up))
                } else if (!mode.rule.isManualInvocationAllowed && !mode.isActive) {
                    add(context.getString(R.string.zen_mode_no_manual_invocation))
                } else {
                    add(
                        context.getString(
                            if (mode.isActive) R.string.zen_mode_on else R.string.zen_mode_off
                        )
                    )
                    mode.getDynamicDescription(context)?.let { add(it) }
                }
            }
            .joinToString(separator = "\n")
    }

    private fun makeZenModeDialog(): Dialog {
        val dialog =
            EnableZenModeDialog(