Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +1 −5 Original line number Diff line number Diff line Loading @@ -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() Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +12 −1 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +4 −4 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt +6 −3 Original line number Diff line number Diff line Loading @@ -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>, Loading Loading @@ -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 Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +1 −5 Original line number Diff line number Diff line Loading @@ -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() Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading
packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +12 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +4 −4 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt +6 −3 Original line number Diff line number Diff line Loading @@ -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>, Loading Loading @@ -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