Always 0 if there is no work profile.
- */
- private int mCollapsibleHeightForTabs = 0;
+ private float mLastScroll = 0;
+ private float mScrollOffset = 0;
+ private Animator mOffsetAnimator;
private boolean mShouldForwardToRecyclerView = false;
+ private int mHeaderHeight;
+
SearchAndRecommendationsScrollController(
- boolean hasWorkProfile,
- int tabsHeight,
- SearchAndRecommendationViewHolder viewHolder,
- WidgetsRecyclerView primaryRecyclerView,
- @Nullable WidgetsRecyclerView workRecyclerView,
- WidgetsRecyclerView searchRecyclerView,
- @Nullable View personalWorkTabsView,
- @Nullable PersonalWorkPagedView primaryWorkViewPager,
- TextView noWidgetsView) {
- mHasWorkProfile = hasWorkProfile;
- mViewHolder = viewHolder;
- mViewHolder.mContainer.setSearchAndRecommendationScrollController(this);
- mSearchAndRecommendationViewParent = (View) mViewHolder.mContainer.getParent();
- mPrimaryRecyclerView = primaryRecyclerView;
- mWorkRecyclerView = workRecyclerView;
- mSearchRecyclerView = searchRecyclerView;
- mPrimaryWorkTabsView = personalWorkTabsView;
- mPrimaryWorkViewPager = primaryWorkViewPager;
- mTabsHeight = tabsHeight;
- mNoWidgetsView = noWidgetsView;
- setCurrentRecyclerView(mPrimaryRecyclerView, /* animateReset= */ false);
+ SearchAndRecommendationsView searchAndRecommendationContainer) {
+ mContainer = searchAndRecommendationContainer;
+ mSearchBarContainer = mContainer.findViewById(R.id.search_bar_container);
+ mSearchBar = mContainer.findViewById(R.id.widgets_search_bar);
+ mHeaderTitle = mContainer.findViewById(R.id.title);
+ mRecommendedWidgetsTable = mContainer.findViewById(R.id.recommended_widget_table);
+ mTabBar = mContainer.findViewById(R.id.tabs);
+
+ mContainer.setSearchAndRecommendationScrollController(this);
}
public void setCurrentRecyclerView(WidgetsRecyclerView currentRecyclerView) {
- setCurrentRecyclerView(currentRecyclerView, /* animateReset= */ true);
- }
-
- /** Sets the current active {@link WidgetsRecyclerView}. */
- private void setCurrentRecyclerView(WidgetsRecyclerView currentRecyclerView,
- boolean animateReset) {
- if (mCurrentRecyclerView == currentRecyclerView) {
- return;
- }
+ boolean animateReset = mCurrentRecyclerView != null;
if (mCurrentRecyclerView != null) {
- mCurrentRecyclerView.setOnContentChangeListener(null);
+ mCurrentRecyclerView.removeOnChildAttachStateChangeListener(this);
}
mCurrentRecyclerView = currentRecyclerView;
- mCurrentRecyclerView.setOnContentChangeListener(mOnContentChangeListener);
+ mCurrentRecyclerView.addOnChildAttachStateChangeListener(this);
+ findCurrentEmptyView();
reset(animateReset);
}
- /**
- * Updates padding of {@link WidgetsFullSheet} contents to include {@code bottomInset} wherever
- * necessary.
- */
- public boolean updateBottomInset(int bottomInset) {
- mBottomInset = bottomInset;
- return updateMarginAndPadding();
+ public int getHeaderHeight() {
+ return mHeaderHeight;
+ }
+
+ private void updateHeaderScroll() {
+ mLastScroll = getCurrentScroll();
+ mHeaderTitle.setTranslationY(mLastScroll);
+ mRecommendedWidgetsTable.setTranslationY(mLastScroll);
+
+ float searchYDisplacement = Math.max(mLastScroll, -mSearchBarContainer.getTop());
+ mSearchBarContainer.setTranslationY(searchYDisplacement);
+
+ if (mTabBar != null) {
+ float tabsDisplacement = Math.max(mLastScroll, -mTabBar.getTop()
+ + mSearchBarContainer.getHeight());
+ mTabBar.setTranslationY(tabsDisplacement);
+ }
+ }
+
+ private float getCurrentScroll() {
+ return mScrollOffset + (mCurrentEmptySpaceView == null ? 0 : mCurrentEmptySpaceView.getY());
}
/**
- * Updates the margin and padding of {@link WidgetsFullSheet} to accumulate collapsible views.
+ * Updates the scrollable header height
*
- * @return {@code true} if margins or/and padding of views in the search and recommendations
- * container have been updated.
+ * @return {@code true} if the header height or dependent property changed.
*/
- public boolean updateMarginAndPadding() {
- boolean hasMarginOrPaddingUpdated = false;
- mCollapsibleHeightForSearch = measureHeightWithVerticalMargins(mViewHolder.mHeaderTitle);
- mCollapsibleHeightForRecommendation =
- measureHeightWithVerticalMargins(mViewHolder.mHeaderTitle)
- + measureHeightWithVerticalMargins(mViewHolder.mCollapseHandle)
- + measureHeightWithVerticalMargins((View) mViewHolder.mSearchBarContainer)
- + measureHeightWithVerticalMargins(mViewHolder.mRecommendedWidgetsTable);
+ public boolean updateHeaderHeight() {
+ boolean hasSizeUpdated = false;
- int topContainerHeight = measureHeightWithVerticalMargins(mViewHolder.mContainer);
- int noWidgetsViewHeight = topContainerHeight - mBottomInset;
-
- if (mHasWorkProfile) {
- mCollapsibleHeightForTabs = measureHeightWithVerticalMargins(mViewHolder.mHeaderTitle)
- + measureHeightWithVerticalMargins(mViewHolder.mRecommendedWidgetsTable);
- // In a work profile setup, the full widget sheet contains the following views:
- // ------- (pinned) -|
- // Widgets (collapsible) -|---> LinearLayout for search & recommendations
- // Search bar (pinned) -|
- // Widgets recommendation (collapsible)-|
- // Personal | Work (pinned)
- // View Pager
- //
- // Views after the search & recommendations are not bound by RelativelyLayout param.
- // To position them on the expected location, padding & margin are added to these views
-
- // Tabs should have a padding of the height of the search & recommendations container.
- RelativeLayout.LayoutParams tabsLayoutParams =
- (RelativeLayout.LayoutParams) mPrimaryWorkTabsView.getLayoutParams();
- tabsLayoutParams.topMargin = topContainerHeight;
- mPrimaryWorkTabsView.setLayoutParams(tabsLayoutParams);
-
- // Instead of setting the top offset directly, we split the top offset into two values:
- // 1. topOffsetAfterAllViewsCollapsed: this is the top offset after all collapsible
- // views are no longer visible on the screen.
- // This value is set as the margin for the view pager.
- // 2. mMaxCollapsibleDistance
- // This value is set as the padding for the recycler views in order to work with
- // clipToPadding="false", which is an attribute for not showing top / bottom padding
- // when a recycler view has not reached the top or bottom of the list.
- // e.g. a list of 10 entries, only 3 entries are visible at a time.
- // case 1: recycler view is scrolled to the top. Top padding is visible/
- // (top padding)
- // item 1
- // item 2
- // item 3
- //
- // case 2: recycler view is scrolled to the middle. No padding is visible.
- // item 4
- // item 5
- // item 6
- //
- // case 3: recycler view is scrolled to the end. bottom padding is visible.
- // item 8
- // item 9
- // item 10
- // (bottom padding): not set in this case.
- //
- // When the views are first inflated, the sum of topOffsetAfterAllViewsCollapsed and
- // mMaxCollapsibleDistance should equal to the top container height.
- int topOffsetAfterAllViewsCollapsed =
- topContainerHeight + mTabsHeight - mCollapsibleHeightForTabs;
-
- if (mPrimaryWorkTabsView.getVisibility() == View.VISIBLE) {
- noWidgetsViewHeight += mTabsHeight;
- }
-
- RelativeLayout.LayoutParams viewPagerLayoutParams =
- (RelativeLayout.LayoutParams) mPrimaryWorkViewPager.getLayoutParams();
- if (viewPagerLayoutParams.topMargin != topOffsetAfterAllViewsCollapsed) {
- viewPagerLayoutParams.topMargin = topOffsetAfterAllViewsCollapsed;
- mPrimaryWorkViewPager.setLayoutParams(viewPagerLayoutParams);
- hasMarginOrPaddingUpdated = true;
- }
-
- if (mPrimaryRecyclerView.getPaddingTop() != mCollapsibleHeightForTabs) {
- mPrimaryRecyclerView.setPadding(
- mPrimaryRecyclerView.getPaddingLeft(),
- mCollapsibleHeightForTabs,
- mPrimaryRecyclerView.getPaddingRight(),
- mPrimaryRecyclerView.getPaddingBottom());
- hasMarginOrPaddingUpdated = true;
- }
- if (mWorkRecyclerView.getPaddingTop() != mCollapsibleHeightForTabs) {
- mWorkRecyclerView.setPadding(
- mWorkRecyclerView.getPaddingLeft(),
- mCollapsibleHeightForTabs,
- mWorkRecyclerView.getPaddingRight(),
- mWorkRecyclerView.getPaddingBottom());
- hasMarginOrPaddingUpdated = true;
- }
- } else {
- if (mPrimaryRecyclerView.getPaddingTop() != topContainerHeight) {
- mPrimaryRecyclerView.setPadding(
- mPrimaryRecyclerView.getPaddingLeft(),
- topContainerHeight,
- mPrimaryRecyclerView.getPaddingRight(),
- mPrimaryRecyclerView.getPaddingBottom());
- hasMarginOrPaddingUpdated = true;
- }
- }
- if (mSearchRecyclerView.getPaddingTop() != topContainerHeight) {
- mSearchRecyclerView.setPadding(
- mSearchRecyclerView.getPaddingLeft(),
- topContainerHeight,
- mSearchRecyclerView.getPaddingRight(),
- mSearchRecyclerView.getPaddingBottom());
- hasMarginOrPaddingUpdated = true;
- }
- if (mNoWidgetsView.getPaddingTop() != noWidgetsViewHeight) {
- mNoWidgetsView.setPadding(
- mNoWidgetsView.getPaddingLeft(),
- noWidgetsViewHeight,
- mNoWidgetsView.getPaddingRight(),
- mNoWidgetsView.getPaddingBottom());
- hasMarginOrPaddingUpdated = true;
- }
- return hasMarginOrPaddingUpdated;
- }
-
- @Override
- public void onScrollChanged() {
- int recyclerViewYOffset = mCurrentRecyclerView.getCurrentScrollY();
- if (recyclerViewYOffset < 0) return;
- mCurrentRecyclerViewScrollY = recyclerViewYOffset;
- if (mAnimator.isStarted()) {
- mAnimator.cancel();
- }
- applyVerticalTransition();
- }
-
- /**
- * Changes the displacement of collapsible views (e.g. title & widget recommendations) and fixed
- * views (e.g. recycler views, tabs) upon scrolling / content changes in the recycler view.
- */
- private void applyVerticalTransition() {
- if (mCollapsibleHeightForRecommendation > 0) {
- int yDisplacement = Math.max(-mCurrentRecyclerViewScrollY,
- -mCollapsibleHeightForRecommendation);
- mViewHolder.mHeaderTitle.setTranslationY(yDisplacement);
- mViewHolder.mRecommendedWidgetsTable.setTranslationY(yDisplacement);
+ int headerHeight = mContainer.getMeasuredHeight();
+ if (headerHeight != mHeaderHeight) {
+ mHeaderHeight = headerHeight;
+ hasSizeUpdated = true;
}
- if (mCollapsibleHeightForSearch > 0) {
- int searchYDisplacement = Math.max(-mCurrentRecyclerViewScrollY,
- -mCollapsibleHeightForSearch);
- mViewHolder.mSearchBarContainer.setTranslationY(searchYDisplacement);
- }
-
- if (mHasWorkProfile && mCollapsibleHeightForTabs > 0) {
- int yDisplacementForTabs = Math.max(-mCurrentRecyclerViewScrollY,
- -mCollapsibleHeightForTabs);
- mPrimaryWorkTabsView.setTranslationY(yDisplacementForTabs);
+ if (mCurrentEmptySpaceView != null
+ && mCurrentEmptySpaceView.setFixedHeight(mHeaderHeight)) {
+ hasSizeUpdated = true;
}
+ return hasSizeUpdated;
}
/** Resets any previous view translation. */
public void reset(boolean animate) {
- if (mCurrentRecyclerViewScrollY == 0) {
- return;
- }
- if (mAnimator.isStarted()) {
- mAnimator.cancel();
+ if (mOffsetAnimator != null) {
+ mOffsetAnimator.cancel();
+ mOffsetAnimator = null;
}
- if (animate) {
- mAnimator.setIntValues(mCurrentRecyclerViewScrollY, 0);
- mAnimator.addUpdateListener(this);
- mAnimator.setDuration(300);
- mAnimator.start();
+ mScrollOffset = 0;
+ if (!animate) {
+ updateHeaderScroll();
} else {
- mCurrentRecyclerViewScrollY = 0;
- applyVerticalTransition();
+ float startValue = mLastScroll - getCurrentScroll();
+ mOffsetAnimator = ObjectAnimator.ofFloat(this, SCROLL_OFFSET, startValue, 0);
+ mOffsetAnimator.addListener(forEndCallback(() -> mOffsetAnimator = null));
+ mOffsetAnimator.start();
}
}
@@ -313,61 +164,60 @@ final class SearchAndRecommendationsScrollController implements
* Returns {@code true} if a touch event should be intercepted by this controller.
*/
public boolean onInterceptTouchEvent(MotionEvent event) {
- calculateMotionEventOffset(mTempOffset);
- event.offsetLocation(mTempOffset.x, mTempOffset.y);
- try {
- mShouldForwardToRecyclerView = mCurrentRecyclerView.onInterceptTouchEvent(event);
- return mShouldForwardToRecyclerView;
- } finally {
- event.offsetLocation(-mTempOffset.x, -mTempOffset.y);
- }
+ return (mShouldForwardToRecyclerView = proxyMotionEvent(event, INTERCEPT_PROXY));
}
/**
* Returns {@code true} if this controller has intercepted and consumed a touch event.
*/
public boolean onTouchEvent(MotionEvent event) {
- if (mShouldForwardToRecyclerView) {
- calculateMotionEventOffset(mTempOffset);
- event.offsetLocation(mTempOffset.x, mTempOffset.y);
- try {
- return mCurrentRecyclerView.onTouchEvent(event);
- } finally {
- event.offsetLocation(-mTempOffset.x, -mTempOffset.y);
- }
- }
- return false;
+ return mShouldForwardToRecyclerView && proxyMotionEvent(event, TOUCH_PROXY);
}
- private void calculateMotionEventOffset(Point p) {
- p.x = mViewHolder.mContainer.getLeft() - mCurrentRecyclerView.getLeft()
- - mSearchAndRecommendationViewParent.getLeft();
- p.y = mViewHolder.mContainer.getTop() - mCurrentRecyclerView.getTop()
- - mSearchAndRecommendationViewParent.getTop();
- }
-
- /** private the height, in pixel, + the vertical margins of a given view. */
- private static int measureHeightWithVerticalMargins(View view) {
- if (view.getVisibility() != View.VISIBLE) {
- return 0;
+ private boolean proxyMotionEvent(MotionEvent event, MotionEventProxyMethod method) {
+ float dx = mCurrentRecyclerView.getLeft() - mContainer.getLeft();
+ float dy = mCurrentRecyclerView.getTop() - mContainer.getTop();
+ event.offsetLocation(dx, dy);
+ try {
+ return method.proxyEvent(mCurrentRecyclerView, event);
+ } finally {
+ event.offsetLocation(-dx, -dy);
}
- MarginLayoutParams marginLayoutParams = (MarginLayoutParams) view.getLayoutParams();
- return view.getMeasuredHeight() + marginLayoutParams.bottomMargin
- + marginLayoutParams.topMargin;
}
@Override
- public void onAnimationUpdate(ValueAnimator animation) {
- mCurrentRecyclerViewScrollY = (Integer) animation.getAnimatedValue();
- applyVerticalTransition();
+ public void onChildViewAttachedToWindow(@NonNull View view) {
+ if (view instanceof EmptySpaceView) {
+ findCurrentEmptyView();
+ }
}
- /**
- * A listener to be notified when there is a content change in the recycler view that may affect
- * the relative position of the search and recommendation container.
- */
- public interface OnContentChangeListener {
- /** Notifies a content change in the recycler view. */
- void onContentChanged();
+ @Override
+ public void onChildViewDetachedFromWindow(@NonNull View view) {
+ if (view == mCurrentEmptySpaceView) {
+ findCurrentEmptyView();
+ }
+ }
+
+ private void findCurrentEmptyView() {
+ if (mCurrentEmptySpaceView != null) {
+ mCurrentEmptySpaceView.setOnYChangeCallback(null);
+ mCurrentEmptySpaceView = null;
+ }
+ int childCount = mCurrentRecyclerView.getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ View view = mCurrentRecyclerView.getChildAt(i);
+ if (view instanceof EmptySpaceView) {
+ mCurrentEmptySpaceView = (EmptySpaceView) view;
+ mCurrentEmptySpaceView.setFixedHeight(getHeaderHeight());
+ mCurrentEmptySpaceView.setOnYChangeCallback(this::updateHeaderScroll);
+ return;
+ }
+ }
+ }
+
+ private interface MotionEventProxyMethod {
+
+ boolean proxyEvent(ViewGroup view, MotionEvent event);
}
}
diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
index be83f9ac13..9dbfa87861 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
@@ -57,13 +57,12 @@ import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.views.ArrowTipView;
import com.android.launcher3.views.RecyclerViewFastScroller;
-import com.android.launcher3.views.TopRoundedCornerView;
+import com.android.launcher3.views.SpringRelativeLayout;
import com.android.launcher3.views.WidgetsEduView;
import com.android.launcher3.widget.BaseWidgetSheet;
import com.android.launcher3.widget.LauncherAppWidgetHost.ProviderChangedListener;
import com.android.launcher3.widget.model.WidgetsListBaseEntry;
import com.android.launcher3.widget.picker.search.SearchModeListener;
-import com.android.launcher3.widget.picker.search.WidgetsSearchBar;
import com.android.launcher3.widget.util.WidgetsTableUtils;
import com.android.launcher3.workprofile.PersonalWorkPagedView;
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.OnActivePageChangedListener;
@@ -79,7 +78,6 @@ import java.util.stream.IntStream;
public class WidgetsFullSheet extends BaseWidgetSheet
implements ProviderChangedListener, OnActivePageChangedListener,
WidgetsRecyclerView.HeaderViewDimensionsProvider, SearchModeListener {
- private static final String TAG = WidgetsFullSheet.class.getSimpleName();
private static final long DEFAULT_OPEN_DURATION = 267;
private static final long FADE_IN_DURATION = 150;
@@ -149,8 +147,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
};
private final int mTabsHeight;
- private final int mViewPagerTopPadding;
- private final int mSearchAndRecommendationContainerBottomMargin;
private final int mWidgetSheetContentHorizontalPadding;
@Nullable private WidgetsRecyclerView mCurrentWidgetsRecyclerView;
@@ -158,10 +154,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet
private boolean mIsInSearchMode;
private boolean mIsNoWidgetsViewNeeded;
private int mMaxSpansPerRow = DEFAULT_MAX_HORIZONTAL_SPANS;
- private View mTabsView;
private TextView mNoWidgetsView;
- private SearchAndRecommendationViewHolder mSearchAndRecommendationViewHolder;
- private SearchAndRecommendationsScrollController mSearchAndRecommendationsScrollController;
+ private SearchAndRecommendationsScrollController mSearchScrollController;
public WidgetsFullSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
@@ -174,14 +168,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
mTabsHeight = mHasWorkProfile
? resources.getDimensionPixelSize(R.dimen.all_apps_header_pill_height)
: 0;
- mViewPagerTopPadding = mHasWorkProfile
- ? getContext().getResources()
- .getDimensionPixelSize(R.dimen.widget_picker_view_pager_top_padding)
- : 0;
- mSearchAndRecommendationContainerBottomMargin = resources.getDimensionPixelSize(
- mHasWorkProfile
- ? R.dimen.search_and_recommended_widgets_container_small_bottom_margin
- : R.dimen.search_and_recommended_widgets_container_bottom_margin);
mWidgetSheetContentHorizontalPadding = 2 * resources.getDimensionPixelSize(
R.dimen.widget_cell_horizontal_padding);
}
@@ -194,12 +180,11 @@ public class WidgetsFullSheet extends BaseWidgetSheet
protected void onFinishInflate() {
super.onFinishInflate();
mContent = findViewById(R.id.container);
- TopRoundedCornerView springLayout = (TopRoundedCornerView) mContent;
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
int contentLayoutRes = mHasWorkProfile ? R.layout.widgets_full_sheet_paged_view
: R.layout.widgets_full_sheet_recyclerview;
- layoutInflater.inflate(contentLayoutRes, springLayout, true);
+ layoutInflater.inflate(contentLayoutRes, mContent, true);
RecyclerViewFastScroller fastScroller = findViewById(R.id.fast_scroller);
mAdapters.get(AdapterHolder.PRIMARY).setup(findViewById(R.id.primary_widgets_list_view));
@@ -209,7 +194,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
mViewPager.initParentViews(this);
mViewPager.getPageIndicator().setOnActivePageChangedListener(this);
mViewPager.getPageIndicator().setActiveMarker(AdapterHolder.PRIMARY);
- mTabsView = findViewById(R.id.tabs);
findViewById(R.id.tab_personal)
.setOnClickListener((View view) -> mViewPager.snapToPage(0));
findViewById(R.id.tab_work)
@@ -220,33 +204,18 @@ public class WidgetsFullSheet extends BaseWidgetSheet
mViewPager = null;
}
- layoutInflater.inflate(R.layout.widgets_full_sheet_search_and_recommendations, springLayout,
- true);
mNoWidgetsView = findViewById(R.id.no_widgets_text);
- mSearchAndRecommendationViewHolder = new SearchAndRecommendationViewHolder(
+ mSearchScrollController = new SearchAndRecommendationsScrollController(
findViewById(R.id.search_and_recommendations_container));
- TopRoundedCornerView.LayoutParams layoutParams =
- (TopRoundedCornerView.LayoutParams)
- mSearchAndRecommendationViewHolder.mContainer.getLayoutParams();
- layoutParams.bottomMargin = mSearchAndRecommendationContainerBottomMargin;
- mSearchAndRecommendationViewHolder.mContainer.setLayoutParams(layoutParams);
- mSearchAndRecommendationsScrollController = new SearchAndRecommendationsScrollController(
- mHasWorkProfile,
- mTabsHeight,
- mSearchAndRecommendationViewHolder,
- findViewById(R.id.primary_widgets_list_view),
- mHasWorkProfile ? findViewById(R.id.work_widgets_list_view) : null,
- findViewById(R.id.search_widgets_list_view),
- mTabsView,
- mViewPager,
- mNoWidgetsView);
- fastScroller.setOnFastScrollChangeListener(mSearchAndRecommendationsScrollController);
-
+ mSearchScrollController.setCurrentRecyclerView(
+ findViewById(R.id.primary_widgets_list_view));
+ mSearchScrollController.mRecommendedWidgetsTable.setWidgetCellLongClickListener(this);
+ mSearchScrollController.mRecommendedWidgetsTable.setWidgetCellOnClickListener(this);
onRecommendedWidgetsBound();
onWidgetsBound();
- mSearchAndRecommendationViewHolder.mSearchBar.initialize(
+ mSearchScrollController.mSearchBar.initialize(
mActivityContext.getPopupDataProvider(), /* searchModeListener= */ this);
setUpEducationViewsIfNeeded();
@@ -270,12 +239,13 @@ public class WidgetsFullSheet extends BaseWidgetSheet
reset();
resetExpandedHeaders();
mCurrentWidgetsRecyclerView = recyclerView;
- mSearchAndRecommendationsScrollController.setCurrentRecyclerView(recyclerView);
+ mSearchScrollController.setCurrentRecyclerView(recyclerView);
}
}
private void updateRecyclerViewVisibility(AdapterHolder adapterHolder) {
- boolean isWidgetAvailable = adapterHolder.mWidgetsListAdapter.getItemCount() > 0;
+ // The first item is always an empty space entry. Look for any more items.
+ boolean isWidgetAvailable = adapterHolder.mWidgetsListAdapter.hasVisibleEntries();
adapterHolder.mWidgetsRecyclerView.setVisibility(isWidgetAvailable ? VISIBLE : GONE);
mNoWidgetsView.setText(
@@ -291,7 +261,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView.scrollToTop();
}
mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView.scrollToTop();
- mSearchAndRecommendationsScrollController.reset(/* animate= */ true);
+ mSearchScrollController.reset(/* animate= */ true);
}
@VisibleForTesting
@@ -340,7 +310,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet
if (mHasWorkProfile) {
setBottomPadding(mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView, insets.bottom);
}
- mSearchAndRecommendationsScrollController.updateBottomInset(insets.bottom);
+ ((MarginLayoutParams) mNoWidgetsView.getLayoutParams()).bottomMargin = insets.bottom;
+
if (insets.bottom > 0) {
setupNavBarColor();
} else {
@@ -360,7 +331,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
@Override
protected void onContentHorizontalMarginChanged(int contentHorizontalMarginInPx) {
- setContentViewChildHorizontalMargin(mSearchAndRecommendationViewHolder.mContainer,
+ setContentViewChildHorizontalMargin(mSearchScrollController.mContainer,
contentHorizontalMarginInPx);
if (mViewPager == null) {
setContentViewChildHorizontalMargin(
@@ -385,14 +356,14 @@ public class WidgetsFullSheet extends BaseWidgetSheet
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
doMeasure(widthMeasureSpec, heightMeasureSpec);
- if (mSearchAndRecommendationsScrollController.updateMarginAndPadding()) {
+ if (mSearchScrollController.updateHeaderHeight()) {
doMeasure(widthMeasureSpec, heightMeasureSpec);
}
if (updateMaxSpansPerRow()) {
doMeasure(widthMeasureSpec, heightMeasureSpec);
- if (mSearchAndRecommendationsScrollController.updateMarginAndPadding()) {
+ if (mSearchScrollController.updateHeaderHeight()) {
doMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@@ -455,7 +426,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
if (mHasWorkProfile) {
mViewPager.setVisibility(VISIBLE);
- mTabsView.setVisibility(VISIBLE);
+ mSearchScrollController.mTabBar.setVisibility(VISIBLE);
AdapterHolder workUserAdapterHolder = mAdapters.get(AdapterHolder.WORK);
workUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets);
onActivePageChanged(mViewPager.getCurrentPage());
@@ -465,9 +436,9 @@ public class WidgetsFullSheet extends BaseWidgetSheet
// Update recommended widgets section so that it occupies appropriate space on screen to
// leave enough space for presence/absence of mNoWidgetsView.
boolean isNoWidgetsViewNeeded =
- mAdapters.get(AdapterHolder.PRIMARY).mWidgetsListAdapter.getItemCount() == 0
+ !mAdapters.get(AdapterHolder.PRIMARY).mWidgetsListAdapter.hasVisibleEntries()
|| (mHasWorkProfile && mAdapters.get(AdapterHolder.WORK)
- .mWidgetsListAdapter.getItemCount() == 0);
+ .mWidgetsListAdapter.hasVisibleEntries());
if (mIsNoWidgetsViewNeeded != isNoWidgetsViewNeeded) {
mIsNoWidgetsViewNeeded = isNoWidgetsViewNeeded;
onRecommendedWidgetsBound();
@@ -491,8 +462,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
mViewPager.snapToPage(AdapterHolder.PRIMARY);
}
attachScrollbarToRecyclerView(mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView);
-
- mSearchAndRecommendationsScrollController.updateMarginAndPadding();
}
@Override
@@ -505,10 +474,10 @@ public class WidgetsFullSheet extends BaseWidgetSheet
private void setViewVisibilityBasedOnSearch(boolean isInSearchMode) {
mIsInSearchMode = isInSearchMode;
if (isInSearchMode) {
- mSearchAndRecommendationViewHolder.mRecommendedWidgetsTable.setVisibility(GONE);
+ mSearchScrollController.mRecommendedWidgetsTable.setVisibility(GONE);
if (mHasWorkProfile) {
mViewPager.setVisibility(GONE);
- mTabsView.setVisibility(GONE);
+ mSearchScrollController.mTabBar.setVisibility(GONE);
} else {
mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView.setVisibility(GONE);
}
@@ -536,8 +505,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
}
List