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

Commit bf0d5aff authored by Prince's avatar Prince Committed by Prince Donkor
Browse files

Edit Widgets in glanceable hub edit mode using talkback

Flag: NA
Test: Device Tested
Fixes: 333564879
Change-Id: I9f9082ff37fefabfacc93476a656a6bdc4d127d4
parent f747d863
Loading
Loading
Loading
Loading
+53 −1
Original line number Diff line number Diff line
@@ -464,6 +464,8 @@ private fun BoxScope.CommunalHubLazyGrid(
                        size = size,
                        selected = selected && !isDragging,
                        widgetConfigurator = widgetConfigurator,
                        index = index,
                        contentListState = contentListState
                    )
                }
            } else {
@@ -473,6 +475,8 @@ private fun BoxScope.CommunalHubLazyGrid(
                    viewModel = viewModel,
                    size = size,
                    selected = false,
                    index = index,
                    contentListState = contentListState
                )
            }
        }
@@ -740,10 +744,21 @@ private fun CommunalContent(
    selected: Boolean,
    modifier: Modifier = Modifier,
    widgetConfigurator: WidgetConfigurator? = null,
    index: Int,
    contentListState: ContentListState,
) {
    when (model) {
        is CommunalContentModel.WidgetContent.Widget ->
            WidgetContent(viewModel, model, size, selected, widgetConfigurator, modifier)
            WidgetContent(
                viewModel,
                model,
                size,
                selected,
                widgetConfigurator,
                modifier,
                index,
                contentListState
            )
        is CommunalContentModel.WidgetPlaceholder -> HighlightedItem(modifier)
        is CommunalContentModel.WidgetContent.DisabledWidget ->
            DisabledWidgetPlaceholder(model, viewModel, modifier)
@@ -841,6 +856,8 @@ private fun WidgetContent(
    selected: Boolean,
    widgetConfigurator: WidgetConfigurator?,
    modifier: Modifier = Modifier,
    index: Int,
    contentListState: ContentListState,
) {
    val context = LocalContext.current
    val isFocusable by viewModel.isFocusable.collectAsState(initial = false)
@@ -849,6 +866,11 @@ private fun WidgetContent(
            model.providerInfo.loadLabel(context.packageManager).toString().trim()
        }
    val clickActionLabel = stringResource(R.string.accessibility_action_label_select_widget)
    val removeWidgetActionLabel = stringResource(R.string.accessibility_action_label_remove_widget)
    val placeWidgetActionLabel = stringResource(R.string.accessibility_action_label_place_widget)
    val selectedKey by viewModel.selectedKey.collectAsState()
    val selectedIndex =
        selectedKey?.let { key -> contentListState.list.indexOfFirst { it.key == key } }
    Box(
        modifier =
            modifier
@@ -865,6 +887,36 @@ private fun WidgetContent(
                    Modifier.semantics {
                        contentDescription = accessibilityLabel
                        onClick(label = clickActionLabel, action = null)
                            val deleteAction =
                                CustomAccessibilityAction(removeWidgetActionLabel) {
                                    contentListState.onRemove(index)
                                    contentListState.onSaveList()
                                    true
                                }
                            val selectWidgetAction =
                                CustomAccessibilityAction(clickActionLabel) {
                                    val currentWidgetKey =
                                        index?.let {
                                            keyAtIndexIfEditable(contentListState.list, index)
                                        }
                                    viewModel.setSelectedKey(currentWidgetKey)
                                    true
                                }

                            val actions = mutableListOf(deleteAction, selectWidgetAction)

                            if (selectedIndex != null && selectedIndex != index) {
                                actions.add(
                                    CustomAccessibilityAction(placeWidgetActionLabel) {
                                        contentListState.onMove(selectedIndex!!, index)
                                        contentListState.onSaveList()
                                        viewModel.setSelectedKey(null)
                                        true
                                    }
                                )
                            }

                            customActions = actions
                    }
                }
    ) {
+4 −0
Original line number Diff line number Diff line
@@ -1186,6 +1186,10 @@
    <string name="accessibility_content_description_for_communal_hub">Widgets on lock screen</string>
    <!-- Label for accessibility action to select a widget in edit mode. [CHAR LIMIT=NONE] -->
    <string name="accessibility_action_label_select_widget">select widget</string>
    <!-- Label for accessibility action to remove a widget in edit mode. [CHAR LIMIT=NONE] -->
    <string name="accessibility_action_label_remove_widget">remove widget</string>
    <!-- Label for accessibility action to place a widget in edit mode after selecting move widget. [CHAR LIMIT=NONE] -->
    <string name="accessibility_action_label_place_widget">place selected widget</string>

    <!-- Related to user switcher --><skip/>