summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/values/strings.xml17
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCustomizationRequestInfo.kt12
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/ShortcutCustomizationDialogStarter.kt20
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt113
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt51
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt27
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt42
8 files changed, 209 insertions, 75 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 3dd49bfed385..713aa47970ee 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -3760,11 +3760,20 @@
is a component that shows the user which keyboard shortcuts they can use.
[CHAR LIMIT=NONE] -->
<string name="shortcut_helper_customize_mode_title">Customize keyboard shortcuts</string>
+ <!-- Title at the top of the keyboard shortcut helper remove shortcut dialog.
+ The helper is a component that shows the user which keyboard shortcuts they can use. Also
+ allows the user to add/remove custom shortcuts.[CHAR LIMIT=NONE] -->
+ <string name="shortcut_customize_mode_remove_shortcut_dialog_title">Remove shortcut?</string>
<!-- Sub title at the top of the keyboard shortcut helper customization dialog. Explains to the
user what action they need to take in the customization dialog to assign a new custom shortcut.
- The helper is a component that shows the user which keyboard shortcuts they can use.
+ The shortcut customize dialog allows users to add/remove custom shortcuts
+ [CHAR LIMIT=NONE] -->
+ <string name="shortcut_customize_mode_add_shortcut_description">Press key to assign shortcut</string>
+ <!-- Sub title at the top of the remove custom shortcut dialog. Explains to the user what action
+ they're about to take when they click remove shortcut. The shortcut customize dialog allows
+ users to add/remove custom shortcuts
[CHAR LIMIT=NONE] -->
- <string name="shortcut_helper_customize_mode_sub_title">Press key to assign shortcut</string>
+ <string name="shortcut_customize_mode_remove_shortcut_description">This will delete your custom shortcut permanently.</string>
<!-- Placeholder text shown in the search box of the keyboard shortcut helper, when the user
hasn't typed in anything in the search box yet. The helper is a component that shows the
user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] -->
@@ -3820,6 +3829,10 @@
confirm and assign key combination to selected shortcut. The helper is a component that
shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] -->
<string name="shortcut_helper_customize_dialog_set_shortcut_button_label">Set shortcut</string>
+ <!-- Label on the remove shortcut button in keyboard shortcut helper customize dialog, that allows user to
+ confirm and remove previously added custom shortcut. The helper is a component that
+ shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] -->
+ <string name="shortcut_helper_customize_dialog_remove_button_label">Remove</string>
<!-- Label on the cancel button in keyboard shortcut helper customize dialog, that allows user to
cancel and exit shortcut customization dialog, returning to the main shortcut helper page.
The helper is a component that shows the user which keyboard shortcuts they can use.
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCustomizationRequestInfo.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCustomizationRequestInfo.kt
index 203228b4a32b..2d3e7f6f6448 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCustomizationRequestInfo.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCustomizationRequestInfo.kt
@@ -18,8 +18,14 @@ package com.android.systemui.keyboard.shortcut.shared.model
sealed interface ShortcutCustomizationRequestInfo {
data class Add(
- val label: String,
- val categoryType: ShortcutCategoryType,
- val subCategoryLabel: String,
+ val label: String = "",
+ val categoryType: ShortcutCategoryType = ShortcutCategoryType.System,
+ val subCategoryLabel: String = "",
+ ) : ShortcutCustomizationRequestInfo
+
+ data class Delete(
+ val label: String = "",
+ val categoryType: ShortcutCategoryType = ShortcutCategoryType.System,
+ val subCategoryLabel: String = "",
) : ShortcutCustomizationRequestInfo
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/ShortcutCustomizationDialogStarter.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/ShortcutCustomizationDialogStarter.kt
index 310078a647e6..67caadba0d45 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/ShortcutCustomizationDialogStarter.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/ShortcutCustomizationDialogStarter.kt
@@ -27,8 +27,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCustomizationRequestInfo
-import com.android.systemui.keyboard.shortcut.ui.composable.AssignNewShortcutDialog
+import com.android.systemui.keyboard.shortcut.ui.composable.ShortcutCustomizationDialog
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState
+import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.AddShortcutDialog
+import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.DeleteShortcutDialog
import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutCustomizationViewModel
import com.android.systemui.lifecycle.ExclusiveActivatable
import com.android.systemui.statusbar.phone.SystemUIDialogFactory
@@ -50,12 +52,11 @@ constructor(
override suspend fun onActivated(): Nothing {
viewModel.shortcutCustomizationUiState.collect { uiState ->
- if (
- uiState is ShortcutCustomizationUiState.AddShortcutDialog &&
- !uiState.isDialogShowing
- ) {
- dialog = createAddShortcutDialog().also { it.show() }
- viewModel.onAddShortcutDialogShown()
+ val shouldShowAddDialog = uiState is AddShortcutDialog && !uiState.isDialogShowing
+ val shouldShowDeleteDialog = uiState is DeleteShortcutDialog && !uiState.isDialogShowing
+ if (shouldShowDeleteDialog || shouldShowAddDialog) {
+ dialog = createDialog().also { it.show() }
+ viewModel.onDialogShown()
} else if (uiState is ShortcutCustomizationUiState.Inactive) {
dialog?.dismiss()
dialog = null
@@ -68,7 +69,7 @@ constructor(
viewModel.onShortcutCustomizationRequested(requestInfo)
}
- private fun createAddShortcutDialog(): Dialog {
+ private fun createDialog(): Dialog {
return dialogFactory.create(dialogDelegate = ShortcutCustomizationDialogDelegate()) { dialog
->
val uiState by
@@ -76,7 +77,7 @@ constructor(
initialValue = ShortcutCustomizationUiState.Inactive
)
val coroutineScope = rememberCoroutineScope()
- AssignNewShortcutDialog(
+ ShortcutCustomizationDialog(
uiState = uiState,
modifier = Modifier
.width(364.dp)
@@ -87,6 +88,7 @@ constructor(
onConfirmSetShortcut = {
coroutineScope.launch { viewModel.onSetShortcut() }
},
+ onConfirmDeleteShortcut = { viewModel.onDeleteShortcut() },
)
dialog.setOnDismissListener { viewModel.onDialogDismissed() }
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt
index c9b778e96dd1..20040c673994 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt
@@ -61,40 +61,74 @@ import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiSt
import com.android.systemui.res.R
@Composable
-fun AssignNewShortcutDialog(
+fun ShortcutCustomizationDialog(
uiState: ShortcutCustomizationUiState,
modifier: Modifier = Modifier,
onKeyPress: (KeyEvent) -> Boolean,
onCancel: () -> Unit,
onConfirmSetShortcut: () -> Unit,
+ onConfirmDeleteShortcut: () -> Unit,
) {
- if (uiState is ShortcutCustomizationUiState.AddShortcutDialog) {
- Column(modifier = modifier) {
- Title(
- uiState.shortcutLabel,
- modifier = Modifier.padding(horizontal = 24.dp).width(316.dp),
- )
- Description(
- modifier = Modifier.padding(top = 24.dp, start = 24.dp, end = 24.dp).width(316.dp)
- )
- PromptShortcutModifier(
- modifier =
- Modifier.padding(top = 24.dp, start = 116.5.dp, end = 116.5.dp)
- .width(131.dp)
- .height(48.dp),
- defaultModifierKey = uiState.defaultCustomShortcutModifierKey,
- )
- SelectedKeyCombinationContainer(
- shouldShowError = uiState.errorMessage.isNotEmpty(),
- onKeyPress = onKeyPress,
- pressedKeys = uiState.pressedKeys,
- )
- ErrorMessageContainer(uiState.errorMessage)
- DialogButtons(
- onCancel,
- isSetShortcutButtonEnabled = uiState.pressedKeys.isNotEmpty(),
- onConfirm = onConfirmSetShortcut,
- )
+ when (uiState) {
+ is ShortcutCustomizationUiState.AddShortcutDialog -> {
+ Column(modifier = modifier) {
+ Title(uiState.shortcutLabel)
+ Description(
+ text =
+ stringResource(
+ id = R.string.shortcut_customize_mode_add_shortcut_description
+ )
+ )
+ PromptShortcutModifier(
+ modifier =
+ Modifier.padding(top = 24.dp, start = 116.5.dp, end = 116.5.dp)
+ .width(131.dp)
+ .height(48.dp),
+ defaultModifierKey = uiState.defaultCustomShortcutModifierKey,
+ )
+ SelectedKeyCombinationContainer(
+ shouldShowError = uiState.errorMessage.isNotEmpty(),
+ onKeyPress = onKeyPress,
+ pressedKeys = uiState.pressedKeys,
+ )
+ ErrorMessageContainer(uiState.errorMessage)
+ DialogButtons(
+ onCancel,
+ isConfirmButtonEnabled = uiState.pressedKeys.isNotEmpty(),
+ onConfirm = onConfirmSetShortcut,
+ confirmButtonText =
+ stringResource(
+ R.string.shortcut_helper_customize_dialog_set_shortcut_button_label
+ ),
+ )
+ }
+ }
+ is ShortcutCustomizationUiState.DeleteShortcutDialog -> {
+ Column(modifier) {
+ Title(
+ title =
+ stringResource(
+ id = R.string.shortcut_customize_mode_remove_shortcut_dialog_title
+ )
+ )
+ Description(
+ text =
+ stringResource(
+ id = R.string.shortcut_customize_mode_remove_shortcut_description
+ )
+ )
+ DialogButtons(
+ onCancel = onCancel,
+ onConfirm = onConfirmDeleteShortcut,
+ confirmButtonText =
+ stringResource(
+ R.string.shortcut_helper_customize_dialog_remove_button_label
+ ),
+ )
+ }
+ }
+ else -> {
+ /* No-Op */
}
}
}
@@ -102,8 +136,9 @@ fun AssignNewShortcutDialog(
@Composable
fun DialogButtons(
onCancel: () -> Unit,
- isSetShortcutButtonEnabled: Boolean,
+ isConfirmButtonEnabled: Boolean = true,
onConfirm: () -> Unit,
+ confirmButtonText: String,
) {
Row(
modifier =
@@ -126,9 +161,8 @@ fun DialogButtons(
color = MaterialTheme.colorScheme.primary,
width = 116.dp,
contentColor = MaterialTheme.colorScheme.onPrimary,
- text =
- stringResource(R.string.shortcut_helper_customize_dialog_set_shortcut_button_label),
- enabled = isSetShortcutButtonEnabled,
+ text = confirmButtonText,
+ enabled = isConfirmButtonEnabled,
)
}
}
@@ -262,23 +296,28 @@ private fun ShortcutTextKey(key: ShortcutKey.Text) {
}
@Composable
-private fun Title(title: String, modifier: Modifier = Modifier) {
+private fun Title(title: String) {
Text(
text = title,
style = MaterialTheme.typography.headlineSmall,
fontSize = 24.sp,
- modifier = modifier.wrapContentSize(Alignment.Center),
+ modifier =
+ Modifier.padding(horizontal = 24.dp).width(316.dp).wrapContentSize(Alignment.Center),
color = MaterialTheme.colorScheme.onSurface,
lineHeight = 32.sp,
+ fontWeight = FontWeight.W400,
)
}
@Composable
-private fun Description(modifier: Modifier = Modifier) {
+private fun Description(text: String) {
Text(
- text = stringResource(id = R.string.shortcut_helper_customize_mode_sub_title),
+ text = text,
style = MaterialTheme.typography.bodyMedium,
- modifier = modifier.wrapContentSize(Alignment.Center),
+ modifier =
+ Modifier.padding(top = 24.dp, start = 24.dp, end = 24.dp)
+ .width(316.dp)
+ .wrapContentSize(Alignment.Center),
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt
index b6b5d1716c79..cd13e87029f6 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt
@@ -111,7 +111,6 @@ import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.fastForEachIndexed
import com.android.compose.modifiers.thenIf
import com.android.compose.ui.graphics.painter.rememberDrawablePainter
-import com.android.systemui.keyboard.shortcut.shared.model.Shortcut as ShortcutModel
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCommand
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCustomizationRequestInfo
@@ -122,6 +121,7 @@ import com.android.systemui.keyboard.shortcut.ui.model.IconSource
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCategoryUi
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import com.android.systemui.res.R
+import com.android.systemui.keyboard.shortcut.shared.model.Shortcut as ShortcutModel
import kotlinx.coroutines.delay
@Composable
@@ -462,14 +462,18 @@ private fun EndSidePanel(
searchQuery = searchQuery,
subCategory = subcategory,
isCustomizing = isCustomizing,
- onCustomizationRequested = { label, subCategoryLabel ->
- onCustomizationRequested(
- ShortcutCustomizationRequestInfo.Add(
- label = label,
- subCategoryLabel = subCategoryLabel,
- categoryType = category.type,
- )
- )
+ onCustomizationRequested = { requestInfo ->
+ when (requestInfo) {
+ is ShortcutCustomizationRequestInfo.Add ->
+ onCustomizationRequested(
+ requestInfo.copy(categoryType = category.type)
+ )
+
+ is ShortcutCustomizationRequestInfo.Delete ->
+ onCustomizationRequested(
+ requestInfo.copy(categoryType = category.type)
+ )
+ }
},
)
Spacer(modifier = Modifier.height(8.dp))
@@ -500,7 +504,7 @@ private fun SubCategoryContainerDualPane(
searchQuery: String,
subCategory: ShortcutSubCategory,
isCustomizing: Boolean,
- onCustomizationRequested: (String, String) -> Unit = { _: String, _: String -> },
+ onCustomizationRequested: (ShortcutCustomizationRequestInfo) -> Unit,
) {
Surface(
modifier = Modifier.fillMaxWidth(),
@@ -522,7 +526,19 @@ private fun SubCategoryContainerDualPane(
searchQuery = searchQuery,
shortcut = shortcut,
isCustomizing = isCustomizing,
- onCustomizationRequested = { onCustomizationRequested(it, subCategory.label) },
+ onCustomizationRequested = { requestInfo ->
+ when (requestInfo) {
+ is ShortcutCustomizationRequestInfo.Add ->
+ onCustomizationRequested(
+ requestInfo.copy(subCategoryLabel = subCategory.label)
+ )
+
+ is ShortcutCustomizationRequestInfo.Delete ->
+ onCustomizationRequested(
+ requestInfo.copy(subCategoryLabel = subCategory.label)
+ )
+ }
+ },
)
}
}
@@ -544,7 +560,7 @@ private fun Shortcut(
searchQuery: String,
shortcut: ShortcutModel,
isCustomizing: Boolean = false,
- onCustomizationRequested: (String) -> Unit = {},
+ onCustomizationRequested: (ShortcutCustomizationRequestInfo) -> Unit = {},
) {
val interactionSource = remember { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState()
@@ -572,7 +588,16 @@ private fun Shortcut(
modifier = Modifier.weight(.666f),
shortcut = shortcut,
isCustomizing = isCustomizing,
- onAddShortcutRequested = { onCustomizationRequested(shortcut.label) },
+ onAddShortcutRequested = {
+ onCustomizationRequested(
+ ShortcutCustomizationRequestInfo.Add(label = shortcut.label)
+ )
+ },
+ onDeleteShortcutRequested = {
+ onCustomizationRequested(
+ ShortcutCustomizationRequestInfo.Delete(label = shortcut.label)
+ )
+ },
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt
index adadeebd0769..990257d642ff 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt
@@ -27,5 +27,7 @@ sealed interface ShortcutCustomizationUiState {
val pressedKeys: List<ShortcutKey> = emptyList(),
) : ShortcutCustomizationUiState
+ data class DeleteShortcutDialog(val isDialogShowing: Boolean) : ShortcutCustomizationUiState
+
data object Inactive : ShortcutCustomizationUiState
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt
index 8178c6a1c705..869682742043 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt
@@ -29,6 +29,8 @@ import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutCustomiz
import com.android.systemui.keyboard.shortcut.shared.model.KeyCombination
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCustomizationRequestInfo
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState
+import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.AddShortcutDialog
+import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.DeleteShortcutDialog
import com.android.systemui.res.R
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
@@ -55,7 +57,7 @@ constructor(
}
}
.combine(_shortcutCustomizationUiState) { keys, uiState ->
- if (uiState is ShortcutCustomizationUiState.AddShortcutDialog) {
+ if (uiState is AddShortcutDialog) {
uiState.copy(pressedKeys = keys)
} else {
uiState
@@ -66,7 +68,7 @@ constructor(
when (requestInfo) {
is ShortcutCustomizationRequestInfo.Add -> {
_shortcutCustomizationUiState.value =
- ShortcutCustomizationUiState.AddShortcutDialog(
+ AddShortcutDialog(
shortcutLabel = requestInfo.label,
defaultCustomShortcutModifierKey =
shortcutCustomizationInteractor.getDefaultCustomShortcutModifierKey(),
@@ -75,14 +77,20 @@ constructor(
)
shortcutCustomizationInteractor.onCustomizationRequested(requestInfo)
}
+
+ is ShortcutCustomizationRequestInfo.Delete -> {
+ _shortcutCustomizationUiState.value =
+ DeleteShortcutDialog(isDialogShowing = false)
+ shortcutCustomizationInteractor.onCustomizationRequested(requestInfo)
+ }
}
}
- fun onAddShortcutDialogShown() {
+ fun onDialogShown() {
_shortcutCustomizationUiState.update { uiState ->
- (uiState as? ShortcutCustomizationUiState.AddShortcutDialog)?.copy(
- isDialogShowing = true
- ) ?: uiState
+ (uiState as? AddShortcutDialog)?.copy(isDialogShowing = true)
+ ?: (uiState as? DeleteShortcutDialog)?.copy(isDialogShowing = true)
+ ?: uiState
}
}
@@ -115,6 +123,7 @@ constructor(
),
)
}
+
ShortcutCustomizationRequestResult.ERROR_OTHER ->
getUiStateWithErrorMessage(
uiState = uiState,
@@ -125,11 +134,15 @@ constructor(
}
}
+ fun onDeleteShortcut() {
+ // TODO(b/373631984) not yet implemented
+ }
+
private fun getUiStateWithErrorMessage(
uiState: ShortcutCustomizationUiState,
errorMessage: String,
): ShortcutCustomizationUiState {
- return (uiState as? ShortcutCustomizationUiState.AddShortcutDialog)?.copy(
+ return (uiState as? AddShortcutDialog)?.copy(
errorMessage = errorMessage
) ?: uiState
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt
index 85ab746211d6..f706cf6980e1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt
@@ -95,11 +95,21 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
}
@Test
+ fun uiState_correctlyUpdatedWhenDeleteShortcutCustomizationIsRequested() {
+ testScope.runTest {
+ viewModel.onShortcutCustomizationRequested(standardDeleteShortcutRequest)
+ val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
+
+ assertThat(uiState).isEqualTo(expectedStandardDeleteShortcutUiState)
+ }
+ }
+
+ @Test
fun uiState_consumedOnAddDialogShown() {
testScope.runTest {
val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest)
- viewModel.onAddShortcutDialogShown()
+ viewModel.onDialogShown()
assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).isDialogShowing)
.isTrue()
@@ -107,11 +117,25 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
}
@Test
+ fun uiState_consumedOnDeleteDialogShown() {
+ testScope.runTest {
+ val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
+ viewModel.onShortcutCustomizationRequested(standardDeleteShortcutRequest)
+ viewModel.onDialogShown()
+
+ assertThat(
+ (uiState as ShortcutCustomizationUiState.DeleteShortcutDialog).isDialogShowing
+ )
+ .isTrue()
+ }
+ }
+
+ @Test
fun uiState_inactiveAfterDialogIsDismissed() {
testScope.runTest {
val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest)
- viewModel.onAddShortcutDialogShown()
+ viewModel.onDialogShown()
viewModel.onDialogDismissed()
assertThat(uiState).isEqualTo(ShortcutCustomizationUiState.Inactive)
}
@@ -145,7 +169,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
testScope.runTest {
val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
viewModel.onShortcutCustomizationRequested(allAppsShortcutCustomizationRequest)
- viewModel.onAddShortcutDialogShown()
+ viewModel.onDialogShown()
assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage)
.isEmpty()
@@ -258,7 +282,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
private suspend fun openAddShortcutDialogAndSetShortcut() {
viewModel.onShortcutCustomizationRequested(allAppsShortcutCustomizationRequest)
- viewModel.onAddShortcutDialogShown()
+ viewModel.onDialogShown()
viewModel.onKeyPressed(keyDownEventWithActionKeyPressed)
viewModel.onKeyPressed(keyUpEventWithActionKeyPressed)
@@ -309,6 +333,13 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
subCategoryLabel = "Standard subcategory",
)
+ private val standardDeleteShortcutRequest =
+ ShortcutCustomizationRequestInfo.Delete(
+ label = "Standard shortcut",
+ categoryType = ShortcutCategoryType.System,
+ subCategoryLabel = "Standard subcategory",
+ )
+
private val allAppsShortcutCustomizationRequest =
ShortcutCustomizationRequestInfo.Add(
label = "Open apps list",
@@ -323,4 +354,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
ShortcutKey.Icon.ResIdIcon(R.drawable.ic_ksh_key_meta),
isDialogShowing = false,
)
+
+ private val expectedStandardDeleteShortcutUiState =
+ ShortcutCustomizationUiState.DeleteShortcutDialog(isDialogShowing = false)
}