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

Commit 9248717a authored by Coco Duan's avatar Coco Duan
Browse files

Fix bug with adding widgets via drag&drop when GH is empty

We recently removed the CTA tile in edit mode and we used to add a new
widget before the CTA card at the second to last index.
Fix is to update the index to insert to be the last in list.
Also cleaned up a few unused methods due to the removal of the CTA card.

Bug: b/334996701
Fixed: 334996701
Test: manual
Flag: ACONFIG com.android.systemui.communal_hub TEAMFOOD
Change-Id: I9fffd38fcbf62bf451a3033025fc99b81ac96d39
parent 8554d459
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -250,7 +250,6 @@ fun CommunalHub(
                            )
                        isDraggingToRemove
                    },
                    onOpenWidgetPicker = onOpenWidgetPicker,
                    gridState = gridState,
                    contentListState = contentListState,
                    selectedKey = selectedKey,
@@ -393,7 +392,6 @@ private fun BoxScope.CommunalHubLazyGrid(
    contentListState: ContentListState,
    setGridCoordinates: (coordinates: LayoutCoordinates) -> Unit,
    updateDragPositionForRemove: (offset: Offset) -> Boolean,
    onOpenWidgetPicker: (() -> Unit)? = null,
    widgetConfigurator: WidgetConfigurator?,
) {
    var gridModifier =
@@ -461,7 +459,6 @@ private fun BoxScope.CommunalHubLazyGrid(
                        model = list[index],
                        viewModel = viewModel,
                        size = size,
                        onOpenWidgetPicker = onOpenWidgetPicker,
                        selected = selected && !isDragging,
                        widgetConfigurator = widgetConfigurator,
                    )
@@ -739,7 +736,6 @@ private fun CommunalContent(
    size: SizeF,
    selected: Boolean,
    modifier: Modifier = Modifier,
    onOpenWidgetPicker: (() -> Unit)? = null,
    widgetConfigurator: WidgetConfigurator? = null,
) {
    when (model) {
+2 −2
Original line number Diff line number Diff line
@@ -161,9 +161,9 @@ internal class DragAndDropTargetState(
    private var isOnRemoveButton = false

    fun onStarted() {
        // assume item will be added to the second to last position before CTA tile.
        // assume item will be added to the end.
        contentListState.list.add(placeHolder)
        placeHolderIndex = contentListState.list.size - 1
        placeHolderIndex?.let { contentListState.list.add(it, placeHolder) }
    }

    fun onMoved(event: DragAndDropEvent) {
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ constructor(

    override val isEditMode = true

    // Only widgets are editable. The CTA tile comes last in the list and remains visible.
    // Only widgets are editable.
    override val communalContent: Flow<List<CommunalContentModel>> =
        communalInteractor.widgetContent.onEach { models ->
            logger.d({ "Content updated: $str1" }) { str1 = models.joinToString { it.key } }