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

Commit 296b69bc authored by Joshua Mokut's avatar Joshua Mokut Committed by Android (Google) Code Review
Browse files

Merge "Revert^2 "Added Remove shortcut Dialog UI"" into main

parents b7347349 1de4398b
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -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.
+9 −3
Original line number Diff line number Diff line
@@ -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
}
+11 −9
Original line number Diff line number Diff line
@@ -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() }

+76 −37
Original line number Diff line number Diff line
@@ -61,21 +61,23 @@ 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) {
    when (uiState) {
        is ShortcutCustomizationUiState.AddShortcutDialog -> {
            Column(modifier = modifier) {
            Title(
                uiState.shortcutLabel,
                modifier = Modifier.padding(horizontal = 24.dp).width(316.dp),
            )
                Title(uiState.shortcutLabel)
                Description(
                modifier = Modifier.padding(top = 24.dp, start = 24.dp, end = 24.dp).width(316.dp)
                    text =
                        stringResource(
                            id = R.string.shortcut_customize_mode_add_shortcut_description
                        )
                )
                PromptShortcutModifier(
                    modifier =
@@ -92,18 +94,51 @@ fun AssignNewShortcutDialog(
                ErrorMessageContainer(uiState.errorMessage)
                DialogButtons(
                    onCancel,
                isSetShortcutButtonEnabled = uiState.pressedKeys.isNotEmpty(),
                    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 */
        }
    }
}

@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,
    )
}
+38 −13
Original line number Diff line number Diff line
@@ -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 = { requestInfo ->
                    when (requestInfo) {
                        is ShortcutCustomizationRequestInfo.Add ->
                            onCustomizationRequested(
                        ShortcutCustomizationRequestInfo.Add(
                            label = label,
                            subCategoryLabel = subCategoryLabel,
                            categoryType = category.type,
                                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)
                )
            },
        )
    }
}
Loading