diff --git a/src/com/android/launcher3/FastScrollRecyclerView.java b/src/com/android/launcher3/FastScrollRecyclerView.java index e1a216e3d8..c16b319934 100644 --- a/src/com/android/launcher3/FastScrollRecyclerView.java +++ b/src/com/android/launcher3/FastScrollRecyclerView.java @@ -20,7 +20,6 @@ import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import android.view.ViewGroup; import android.view.accessibility.AccessibilityNodeInfo; import androidx.annotation.Nullable; @@ -53,21 +52,9 @@ public abstract class FastScrollRecyclerView extends RecyclerView { super(context, attrs, defStyleAttr); } - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (mScrollbar == null || !mScrollbar.hasRecyclerView()) { - bindFastScrollbar(); - } - } - - public void bindFastScrollbar() { - ViewGroup parent = (ViewGroup) getParent().getParent(); - if (parent.findViewById(R.id.fast_scroller) == null) { - parent = (ViewGroup) parent.getParent(); - } - mScrollbar = parent.findViewById(R.id.fast_scroller); - mScrollbar.setRecyclerView(this, parent.findViewById(R.id.fast_scroller_popup)); + public void bindFastScrollbar(RecyclerViewFastScroller scrollbar) { + mScrollbar = scrollbar; + mScrollbar.setRecyclerView(this); onUpdateScrollbar(0); } diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index 14e3fa6fa4..3e98cd9158 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -134,6 +134,8 @@ public class ActivityAllAppsContainerView protected AllAppsPagedView mViewPager; protected FloatingHeaderView mHeader; protected View mBottomSheetBackground; + protected RecyclerViewFastScroller mFastScroller; + /** * View that defines the search box. Result is rendered inside {@link #mSearchRecyclerView}. */ @@ -219,6 +221,8 @@ public class ActivityAllAppsContainerView mBottomSheetBackground = findViewById(R.id.bottom_sheet_background); mBottomSheetHandleArea = findViewById(R.id.bottom_sheet_handle_area); mSearchRecyclerView = findViewById(R.id.search_results_list_view); + mFastScroller = findViewById(R.id.fast_scroller); + mFastScroller.setPopupView(findViewById(R.id.fast_scroller_popup)); // Add the search box above everything else. mSearchContainer = inflateSearchBox(); @@ -302,6 +306,7 @@ public class ActivityAllAppsContainerView if (!mSearchTransitionController.isRunning() && goingToSearch == isSearching()) { return; } + mFastScroller.setVisibility(goingToSearch ? INVISIBLE : VISIBLE); if (goingToSearch) { // Fade out the button to pause work apps. mWorkManager.onActivePageChanged(SEARCH); @@ -408,7 +413,7 @@ public class ActivityAllAppsContainerView return; } if (mAH.get(currentActivePage).mRecyclerView != null) { - mAH.get(currentActivePage).mRecyclerView.bindFastScrollbar(); + mAH.get(currentActivePage).mRecyclerView.bindFastScrollbar(mFastScroller); } // Header keeps track of active recycler view to properly render header protection. mHeader.setActiveRV(currentActivePage); @@ -491,7 +496,7 @@ public class ActivityAllAppsContainerView if (isSearchBarOnBottom()) { // Keep the scroller above the search bar. RelativeLayout.LayoutParams scrollerLayoutParams = - (LayoutParams) findViewById(R.id.fast_scroller).getLayoutParams(); + (LayoutParams) mFastScroller.getLayoutParams(); scrollerLayoutParams.addRule(RelativeLayout.ABOVE, R.id.search_container_all_apps); scrollerLayoutParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); scrollerLayoutParams.bottomMargin = getResources().getDimensionPixelSize( @@ -1052,12 +1057,6 @@ public class ActivityAllAppsContainerView : mViewPager == null ? AdapterHolder.MAIN : mViewPager.getNextPage(); } - /** The scroll bar for the active apps recycler view. */ - public RecyclerViewFastScroller getScrollBar() { - AllAppsRecyclerView rv = getActiveAppsRecyclerView(); - return rv == null ? null : rv.getScrollbar(); - } - /** * Adds an update listener to animator that adds springs to the animation. */ @@ -1249,6 +1248,7 @@ public class ActivityAllAppsContainerView void setup(@NonNull View rv, @Nullable Predicate matcher) { mAppsList.updateItemFilter(matcher); mRecyclerView = (AllAppsRecyclerView) rv; + mRecyclerView.bindFastScrollbar(mFastScroller); mRecyclerView.setEdgeEffectFactory(createEdgeEffectFactory()); mRecyclerView.setApps(mAppsList); mRecyclerView.setLayoutManager(mLayoutManager); diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java index 6b45fe64b2..7c5c003915 100644 --- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java +++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java @@ -43,7 +43,6 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.views.ActivityContext; -import com.android.launcher3.views.RecyclerViewFastScroller; import java.util.List; @@ -274,10 +273,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView { : getRootWindowInsets().getSystemWindowInsetBottom(); } - public RecyclerViewFastScroller getScrollbar() { - return mScrollbar; - } - @Override public boolean hasOverlappingRendering() { return false; diff --git a/src/com/android/launcher3/views/RecyclerViewFastScroller.java b/src/com/android/launcher3/views/RecyclerViewFastScroller.java index 3af2e3c9dc..1274294aa5 100644 --- a/src/com/android/launcher3/views/RecyclerViewFastScroller.java +++ b/src/com/android/launcher3/views/RecyclerViewFastScroller.java @@ -171,12 +171,14 @@ public class RecyclerViewFastScroller extends View { ta.recycle(); } - /** @return whether there is a RecyclerView bound to this scroller. */ - public boolean hasRecyclerView() { - return mRv != null; + /** Sets the popup view to show while the scroller is being dragged */ + public void setPopupView(TextView popupView) { + mPopupView = popupView; + mPopupView.setBackground( + new FastScrollThumbDrawable(mThumbPaint, Utilities.isRtl(getResources()))); } - public void setRecyclerView(FastScrollRecyclerView rv, TextView popupView) { + public void setRecyclerView(FastScrollRecyclerView rv) { if (mRv != null && mOnScrollListener != null) { mRv.removeOnScrollListener(mOnScrollListener); } @@ -194,10 +196,6 @@ public class RecyclerViewFastScroller extends View { mRv.onUpdateScrollbar(dy); } }); - - mPopupView = popupView; - mPopupView.setBackground( - new FastScrollThumbDrawable(mThumbPaint, Utilities.isRtl(getResources()))); } public void reattachThumbToScroll() { @@ -331,7 +329,7 @@ public class RecyclerViewFastScroller extends View { } public void onDraw(Canvas canvas) { - if (mThumbOffsetY < 0) { + if (mThumbOffsetY < 0 || mRv == null) { return; } int saveCount = canvas.save(); diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index 545e661b8a..d72914b224 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -159,7 +159,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet WidgetsRecyclerView searchRecyclerView = mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView; if (mIsInSearchMode && searchRecyclerView != null) { - searchRecyclerView.bindFastScrollbar(); + searchRecyclerView.bindFastScrollbar(mFastScroller); } } @@ -253,6 +253,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet if (mIsTwoPane) { mFastScroller.setVisibility(GONE); } + mFastScroller.setPopupView(findViewById(R.id.fast_scroller_popup)); + mAdapters.get(AdapterHolder.PRIMARY).setup(findViewById(R.id.primary_widgets_list_view)); mAdapters.get(AdapterHolder.SEARCH).setup(findViewById(R.id.search_widgets_list_view)); if (mHasWorkProfile) { @@ -373,7 +375,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet } private void attachScrollbarToRecyclerView(WidgetsRecyclerView recyclerView) { - recyclerView.bindFastScrollbar(); + recyclerView.bindFastScrollbar(mFastScroller); if (mCurrentWidgetsRecyclerView != recyclerView) { // Only reset the scroll position & expanded apps if the currently shown recycler view // has been updated. @@ -583,7 +585,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet workUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets); onActivePageChanged(mViewPager.getCurrentPage()); } else { - updateRecyclerViewVisibility(primaryUserAdapterHolder); + onActivePageChanged(0); } // Update recommended widgets section so that it occupies appropriate space on screen to // leave enough space for presence/absence of mNoWidgetsView. @@ -1021,6 +1023,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet mWidgetsRecyclerView.setClipToOutline(true); mWidgetsRecyclerView.setClipChildren(false); mWidgetsRecyclerView.setAdapter(mWidgetsListAdapter); + mWidgetsRecyclerView.bindFastScrollbar(mFastScroller); mWidgetsRecyclerView.setItemAnimator(mWidgetsListItemAnimator); mWidgetsRecyclerView.setHeaderViewDimensionsProvider(WidgetsFullSheet.this); if (!mIsTwoPane) {