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

Commit a4729d35 authored by Darrell Shi's avatar Darrell Shi
Browse files

Keep selection of widget at the end of widget dragging

Previously, the Glanceable Hub clears widget selection as soon as a
widget dragging starts. This change makes it so that a drag action also
selects that widget being dragged, and does not reset it after the
dragging completes.

Test: atest CommunalEditModeViewModelTest
Test: verified selection remains at the end of a widget dragging;
      see bug for before and after video
Fix: 376492600
Flag: com.android.systemui.communal_hub
Change-Id: I51970469cb73c77e909142b154cbbc67f4ae4dad
parent 923f969d
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ internal constructor(
    private val scope: CoroutineScope,
    private val updateDragPositionForRemove: (draggingBoundingBox: IntRect) -> Boolean,
) {
    var draggingItemKey by mutableStateOf<Any?>(null)
    var draggingItemKey by mutableStateOf<String?>(null)
        private set

    var isDraggingToRemove by mutableStateOf(false)
@@ -138,7 +138,7 @@ internal constructor(
            // before content padding from the initial pointer position
            .firstItemAtOffset(normalizedOffset - contentOffset)
            ?.apply {
                draggingItemKey = key
                draggingItemKey = key as String
                draggingItemInitialOffset = this.offset.toOffset()
                return true
            }
@@ -284,7 +284,9 @@ fun Modifier.dragContainer(
                            contentOffset,
                        )
                    ) {
                        viewModel.onReorderWidgetStart()
                        // draggingItemKey is guaranteed to be non-null here because it is set in
                        // onDragStart()
                        viewModel.onReorderWidgetStart(dragDropState.draggingItemKey!!)
                    }
                },
                onDragEnd = {
+6 −6
Original line number Diff line number Diff line
@@ -172,16 +172,16 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
        }

    @Test
    fun selectedKey_onReorderWidgets_isCleared() =
    fun selectedKey_onReorderWidgets_isSet() =
        testScope.runTest {
            val selectedKey by collectLastValue(underTest.selectedKey)

            underTest.setSelectedKey(null)
            assertThat(selectedKey).isNull()

            val key = CommunalContentModel.KEY.widget(123)
            underTest.setSelectedKey(key)
            underTest.onReorderWidgetStart(key)
            assertThat(selectedKey).isEqualTo(key)

            underTest.onReorderWidgetStart()
            assertThat(selectedKey).isNull()
        }

    @Test
@@ -234,7 +234,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {

    @Test
    fun reorderWidget_uiEventLogging_start() {
        underTest.onReorderWidgetStart()
        underTest.onReorderWidgetStart(CommunalContentModel.KEY.widget(123))
        verify(uiEventLogger).log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_START)
    }

+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ abstract class BaseCommunalViewModel(
    open fun onDismissCtaTile() {}

    /** Called as the user starts dragging a widget to reorder. */
    open fun onReorderWidgetStart() {}
    open fun onReorderWidgetStart(draggingItemKey: String) {}

    /** Called as the user finishes dragging a widget to reorder. */
    open fun onReorderWidgetEnd() {}
+2 −3
Original line number Diff line number Diff line
@@ -164,9 +164,8 @@ constructor(
        )
    }

    override fun onReorderWidgetStart() {
        // Clear selection status
        setSelectedKey(null)
    override fun onReorderWidgetStart(draggingItemKey: String) {
        setSelectedKey(draggingItemKey)
        _reorderingWidgets.value = true
        uiEventLogger.log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_START)
    }