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

Commit 215b82c5 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Fix persisted scoll position on glanceable hub" into main

parents 34a5ab05 3191da9c
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -241,11 +241,7 @@ fun CommunalHub(
    val gridState =
        rememberLazyGridState(viewModel.savedFirstScrollIndex, viewModel.savedFirstScrollOffset)

    LaunchedEffect(Unit) {
        if (!viewModel.isEditMode) {
            viewModel.clearPersistedScrollPosition()
        }
    }
    LaunchedEffect(Unit) { viewModel.clearPersistedScrollPosition("ui rendered") }

    val contentListState = rememberContentListState(widgetConfigurator, communalContent, viewModel)
    val reorderingWidgets by viewModel.reorderingWidgets.collectAsStateWithLifecycle()
+2 −2
Original line number Diff line number Diff line
@@ -356,12 +356,12 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
        }

    @Test
    fun scrollPosition_persistedOnEditCleanup() =
    fun scrollPosition_persistedOnEditDone() =
        kosmos.runTest {
            val index = 2
            val offset = 30
            underTest.onScrollPositionUpdated(index, offset)
            underTest.cleanupEditModeState()
            underTest.onEditDone()

            assertThat(communalInteractor.firstVisibleItemIndex).isEqualTo(index)
            assertThat(communalInteractor.firstVisibleItemOffset).isEqualTo(offset)
+12 −1
Original line number Diff line number Diff line
@@ -639,11 +639,22 @@ constructor(
     * memory) so that the next presentation of the grid (either as glanceable hub or edit mode) can
     * restore position.
     */
    fun setScrollPosition(firstVisibleItemIndex: Int, firstVisibleItemOffset: Int) {
    fun setScrollPosition(firstVisibleItemIndex: Int, firstVisibleItemOffset: Int, reason: String) {
        logger.d({ "On persist scroll position ($str1) - index=$int1 offset=$int2" }) {
            int1 = firstVisibleItemIndex
            int2 = firstVisibleItemOffset
            str1 = reason
        }
        _firstVisibleItemIndex = firstVisibleItemIndex
        _firstVisibleItemOffset = firstVisibleItemOffset
    }

    fun clearScrollPosition(reason: String) {
        logger.d({ "On clear scroll position ($str1)" }) { str1 = reason }
        _firstVisibleItemIndex = 0
        _firstVisibleItemOffset = 0
    }

    val firstVisibleItemIndex: Int
        get() = _firstVisibleItemIndex

+4 −4
Original line number Diff line number Diff line
@@ -239,13 +239,13 @@ abstract class BaseCommunalViewModel(
    }

    /** Stores scroll values to interactor. */
    protected fun persistScrollPosition() {
        communalInteractor.setScrollPosition(currentScrollIndex, currentScrollOffset)
    protected fun persistScrollPosition(reason: String) {
        communalInteractor.setScrollPosition(currentScrollIndex, currentScrollOffset, reason)
    }

    /** Invoked after scroll values are used to initialize grid position. */
    open fun clearPersistedScrollPosition() {
        communalInteractor.setScrollPosition(0, 0)
    open fun clearPersistedScrollPosition(reason: String) {
        communalInteractor.clearScrollPosition(reason)
    }

    val savedFirstScrollIndex: Int
+6 −3
Original line number Diff line number Diff line
@@ -245,6 +245,12 @@ constructor(
            false
        }

    /** Called when user is done editing widgets and will return back to hub */
    fun onEditDone() {
        // Persist scroll position in edit mode so we go back to the position in glanceable hub.
        persistScrollPosition("edit done")
    }

    private fun getWidgetPickerActivityIntent(
        resources: Resources,
        excludeList: ArrayList<AppWidgetProviderInfo>,
@@ -292,9 +298,6 @@ constructor(
    /** Called when exiting the edit mode, before transitioning back to the communal scene. */
    fun cleanupEditModeState() {
        communalSceneInteractor.setEditModeState(null)

        // Set the scroll position of the glanceable hub to match where we are now.
        persistScrollPosition()
    }

    /** Whether screen rotation is allowed. If false, screen orientation should remain portrait. */
Loading