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

Commit b67c9d7c authored by brycelee's avatar brycelee
Browse files

Clear selected widget on scroll.

This changelist ensures that the selected widget is cleared when
scrolling in edit mode. This prevents unexpected rendering due to
maintaining the selected highlight when the widget leaves the viewable
space.

Test: atest CommunalEditModeViewModelTest#scrollPosition_clearsSelectedItem
Fixes: 395086108
Flag: EXEMPT bugfix
Change-Id: I6ce7e66462706bafe44bc9cadea16128187f5dae
parent bac0225e
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -361,6 +361,20 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
            assertThat(communalInteractor.firstVisibleItemOffset).isEqualTo(offset)
        }

    @Test
    fun scrollPosition_clearsSelectedItem() =
        kosmos.runTest {
            val index = 2
            val offset = 30
            val testKey = "testKey"
            underTest.setSelectedKey(testKey)
            assertThat(underTest.selectedKey.value).isNotNull()
            underTest.onScrollPositionUpdated(index, communalInteractor.firstVisibleItemOffset)
            assertThat(underTest.selectedKey.value).isEqualTo(testKey)
            underTest.onScrollPositionUpdated(index, offset)
            assertThat(underTest.selectedKey.value).isNull()
        }

    @Test
    fun onResizeWidget_logsMetrics() =
        kosmos.runTest {
+7 −0
Original line number Diff line number Diff line
@@ -199,6 +199,13 @@ constructor(
        uiEventLogger.log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_CANCEL)
    }

    override fun onScrollPositionUpdated(firstVisibleItemIndex: Int, firstVisibleItemScroll: Int) {
        super.onScrollPositionUpdated(firstVisibleItemIndex, firstVisibleItemScroll)
        if (!_reorderingWidgets.value && firstVisibleItemScroll != savedFirstScrollOffset) {
            setSelectedKey(null)
        }
    }

    val isIdleOnCommunal: StateFlow<Boolean> = communalInteractor.isIdleOnCommunal

    /** Launch the widget picker activity using the given startActivity method. */