From d670f3032fafee002a408cb578dd0031a60d56b3 Mon Sep 17 00:00:00 2001 From: Holly Sun Date: Tue, 7 Nov 2023 14:29:23 -0800 Subject: [PATCH] [ps] Add helper function to scroll a recycler view to bottom and `resetAndScrollToPrivateSpace`. Bug: 309522136 Test: manual Flag: ACONFIG com.google.android.apps.nexuslauncher.inject_private_space_tile DEVELOPMENT Change-Id: I96a1eed97dd1e4626ddc5ad42c029d94eb174f00 --- .../launcher3/FastScrollRecyclerView.java | 10 ++++++++ .../allapps/ActivityAllAppsContainerView.java | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/com/android/launcher3/FastScrollRecyclerView.java b/src/com/android/launcher3/FastScrollRecyclerView.java index 67ed55dc4d..01e65ae9b5 100644 --- a/src/com/android/launcher3/FastScrollRecyclerView.java +++ b/src/com/android/launcher3/FastScrollRecyclerView.java @@ -192,4 +192,14 @@ public abstract class FastScrollRecyclerView extends RecyclerView { } scrollToPosition(0); } + + /** + * Scrolls this recycler view to the bottom. + */ + public void scrollToBottom() { + if (mScrollbar != null) { + mScrollbar.reattachThumbToScroll(); + } + smoothScrollToPosition(getAdapter().getItemCount() - 1); + } } diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index 7d52cbbef2..6bc0ca5cc7 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -476,6 +476,30 @@ public class ActivityAllAppsContainerView } } + /** + * Exits search and returns to A-Z apps list. Scroll to the bottom. + */ + public void resetAndScrollToBottom() { + if (mTouchHandler != null) { + mTouchHandler.endFastScrolling(); + } + + // Reset the base recycler view after transitioning home. + updateHeaderScroll(0); + + // Animate to A-Z with 0 time to reset the animation with proper state management. + animateToSearchState(false, 0); + + MAIN_EXECUTOR.getHandler().post(() -> { + // Reset the search bar after transitioning home. + mSearchUiManager.resetSearch(); + // Switch to the main tab + switchToTab(ActivityAllAppsContainerView.AdapterHolder.MAIN); + // Scroll to bottom + getActiveRecyclerView().scrollToBottom(); + }); + } + @Override public boolean dispatchKeyEvent(KeyEvent event) { mSearchUiManager.preDispatchKeyEvent(event);