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

Commit 092cb7e6 authored by Josh's avatar Josh
Browse files

Backspace to clear selected shortcut key combination

After selecting a key combination, user can now press backspace to clear
the selected key combo.

Fix: 387995731
Flag: com.android.systemui.keyboard_shortcut_helper_shortcut_customizer
Test: ShortcutCustomizationViewModelTest
Change-Id: Idcec42d9f2094ffb75915d75d6aa9f49033dc115
parent 5a0147f0
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -297,6 +297,19 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
        }
    }

    @Test
    fun uiState_pressedKeys_resetsToEmpty_onClearSelectedShortcutKeyCombination() {
        testScope.runTest {
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest)
            viewModel.onShortcutKeyCombinationSelected(keyDownEventWithActionKeyPressed)
            viewModel.onShortcutKeyCombinationSelected(keyUpEventWithActionKeyPressed)
            viewModel.clearSelectedKeyCombination()
            
            assertThat((uiState as AddShortcutDialog).pressedKeys).isEmpty()
        }
    }

    private suspend fun openAddShortcutDialogAndSetShortcut() {
        viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest)

+1 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ constructor(
                onConfirmResetShortcut = {
                    coroutineScope.launch { viewModel.resetAllCustomShortcuts() }
                },
                onClearSelectedKeyCombination = { viewModel.clearSelectedKeyCombination() },
            )
            setDialogProperties(dialog, uiState)
        }
+10 −2
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ fun ShortcutCustomizationDialog(
    onConfirmSetShortcut: () -> Unit,
    onConfirmDeleteShortcut: () -> Unit,
    onConfirmResetShortcut: () -> Unit,
    onClearSelectedKeyCombination: () -> Unit,
) {
    when (uiState) {
        is ShortcutCustomizationUiState.AddShortcutDialog -> {
@@ -87,6 +88,7 @@ fun ShortcutCustomizationDialog(
                onShortcutKeyCombinationSelected,
                onCancel,
                onConfirmSetShortcut,
                onClearSelectedKeyCombination,
            )
        }
        is ShortcutCustomizationUiState.DeleteShortcutDialog -> {
@@ -108,6 +110,7 @@ private fun AddShortcutDialog(
    onShortcutKeyCombinationSelected: (KeyEvent) -> Boolean,
    onCancel: () -> Unit,
    onConfirmSetShortcut: () -> Unit,
    onClearSelectedKeyCombination: () -> Unit,
) {
    Column(modifier = modifier) {
        Title(uiState.shortcutLabel)
@@ -126,6 +129,7 @@ private fun AddShortcutDialog(
            onShortcutKeyCombinationSelected = onShortcutKeyCombinationSelected,
            pressedKeys = uiState.pressedKeys,
            onConfirmSetShortcut = onConfirmSetShortcut,
            onClearSelectedKeyCombination = onClearSelectedKeyCombination,
        )
        ErrorMessageContainer(uiState.errorMessage)
        DialogButtons(
@@ -262,6 +266,7 @@ private fun SelectedKeyCombinationContainer(
    onShortcutKeyCombinationSelected: (KeyEvent) -> Boolean,
    pressedKeys: List<ShortcutKey>,
    onConfirmSetShortcut: () -> Unit,
    onClearSelectedKeyCombination: () -> Unit,
) {
    val focusRequester = remember { FocusRequester() }
    val focusManager = LocalFocusManager.current
@@ -284,6 +289,10 @@ private fun SelectedKeyCombinationContainer(
                                    onConfirmSetShortcut()
                                    return@onPreviewKeyEvent true
                                }
                                Key.Backspace -> {
                                    onClearSelectedKeyCombination()
                                    return@onPreviewKeyEvent true
                                }
                                Key.DirectionDown -> {
                                    focusManager.moveFocus(FocusDirection.Down)
                                    return@onPreviewKeyEvent true
@@ -357,8 +366,7 @@ private fun ShortcutIconKey(key: ShortcutKey.Icon) {
                is ShortcutKey.Icon.DrawableIcon -> rememberDrawablePainter(drawable = key.drawable)
            },
        contentDescription = null,
        modifier =
        Modifier.height(24.dp),
        modifier = Modifier.height(24.dp),
        tint = MaterialTheme.colorScheme.onSurfaceVariant,
    )
}
+5 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ constructor(
    fun onDialogDismissed() {
        _shortcutCustomizationUiState.value = ShortcutCustomizationUiState.Inactive
        shortcutCustomizationInteractor.onCustomizationRequested(null)
        shortcutCustomizationInteractor.updateUserSelectedKeyCombination(null)
        clearSelectedKeyCombination()
    }

    fun onShortcutKeyCombinationSelected(keyEvent: KeyEvent): Boolean {
@@ -158,6 +158,10 @@ constructor(
        }
    }

    fun clearSelectedKeyCombination() {
        shortcutCustomizationInteractor.updateUserSelectedKeyCombination(null)
    }

    private fun getUiStateWithErrorMessage(
        uiState: ShortcutCustomizationUiState,
        errorMessage: String,