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

Commit ef4b102a authored by Shamali P's avatar Shamali P Committed by Shamali Patwa
Browse files

Pause page scrolls while new recommendation are being applied

http://screencast/cast/NDg4NzU2MjI3NDQ3MTkzNnw5MTU1NTc4Yy1lYw
http://screencast/cast/NDk5Nzg4MzQ5MjMwMjg0OHxmZGM0MGZlYS0wMg

This cl is NO-OP for anything else using it already. Just renamed it.

Bug: 318410881
Test: Manual (see screencast)
Flag: ACONFIG com.android.launcher3.enable_categorized_widget_recommendations DEVELOPMENT
Change-Id: I55d599437b2554f58d635d11f2b603516b030f30
parent 18f3f63a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
        launcher.viewCache.setCacheSize(R.layout.folder_page, 2)
        TraceHelper.INSTANCE.endSection()
        launcher.workspace.removeExtraEmptyScreen(/* stripEmptyScreens= */ true)
        launcher.workspace.pageIndicator.setAreScreensBinding(false, deviceProfile.isTwoPanels)
        launcher.workspace.pageIndicator.setPauseScroll(/*pause=*/ false, deviceProfile.isTwoPanels)
    }

    /**
@@ -299,8 +299,8 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
    }

    override fun bindScreens(orderedScreenIds: LIntArray) {
        launcher.workspace.pageIndicator.setAreScreensBinding(
            true,
        launcher.workspace.pageIndicator.setPauseScroll(
            /*pause=*/ true,
            launcher.deviceProfile.isTwoPanels
        )
        val firstScreenPosition = 0
+5 −3
Original line number Diff line number Diff line
@@ -27,10 +27,12 @@ public interface PageIndicator {
    void setMarkersCount(int numMarkers);

    /**
     * Sets flag to indicate when the screens are in the process of binding so that we don't animate
     * during that period.
     * Sets a flag indicating whether to pause scroll.
     * <p>Should be set to {@code true} while the screen is binding or new data is being applied,
     * and to {@code false} once done. This prevents animation conflicts due to scrolling during
     * those periods.</p>
     */
    default void setAreScreensBinding(boolean areScreensBinding, boolean isTwoPanels) {
    default void setPauseScroll(boolean pause, boolean isTwoPanels) {
        // No-op by default
    }

+5 −5
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
     */
    private float mCurrentPosition;
    private float mFinalPosition;
    private boolean mAreScreensBinding;
    private boolean mIsScrollPaused;
    private boolean mIsTwoPanels;
    private ObjectAnimator mAnimator;
    private @Nullable ObjectAnimator mAlphaAnimator;
@@ -172,7 +172,7 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
        }

        // Skip scroll update during binding. We will update it when binding completes.
        if (mAreScreensBinding) {
        if (mIsScrollPaused) {
            return;
        }

@@ -376,15 +376,15 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
    }

    @Override
    public void setAreScreensBinding(boolean areScreensBinding, boolean isTwoPanels) {
    public void setPauseScroll(boolean pause, boolean isTwoPanels) {
        mIsTwoPanels = isTwoPanels;

        // Reapply correct current position which was skipped during setScroll.
        if (mAreScreensBinding && !areScreensBinding) {
        if (mIsScrollPaused && !pause) {
            CURRENT_POSITION.set(this, (float) mActivePage);
        }

        mAreScreensBinding = areScreensBinding;
        mIsScrollPaused = pause;
    }

    @Override
+19 −8
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.Px;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.model.WidgetItem;
@@ -88,6 +87,7 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
     * Displays all the provided recommendations in a single table if they fit.
     *
     * @param recommendedWidgets list of widgets to be displayed in recommendation section.
     * @param deviceProfile      the current {@link DeviceProfile}
     * @param availableHeight    height in px that can be used to display the recommendations;
     *                           recommendations that don't fit in this height won't be shown
     * @param availableWidth     width in px that the recommendations should display in
@@ -96,12 +96,13 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
     * @return {@code false} if no recommendations could fit in the available space.
     */
    public boolean setRecommendations(
            List<WidgetItem> recommendedWidgets, final @Px float availableHeight,
            final @Px int availableWidth, final @Px int cellPadding) {
            List<WidgetItem> recommendedWidgets, DeviceProfile deviceProfile,
            final @Px float availableHeight, final @Px int availableWidth,
            final @Px int cellPadding) {
        this.mAvailableHeight = availableHeight;
        removeAllViews();

        maybeDisplayInTable(recommendedWidgets, availableWidth, cellPadding);
        maybeDisplayInTable(recommendedWidgets, deviceProfile, availableWidth, cellPadding);
        updateTitleAndIndicator();
        return getChildCount() > 0;
    }
@@ -111,6 +112,7 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
     * <p>In case of a single category, no title is displayed for it.</p>
     *
     * @param recommendations a map of widget items per recommendation category
     * @param deviceProfile   the current {@link DeviceProfile}
     * @param availableHeight height in px that can be used to display the recommendations;
     *                        recommendations that don't fit in this height won't be shown
     * @param availableWidth  width in px that the recommendations should display in
@@ -120,10 +122,12 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
     */
    public boolean setRecommendations(
            Map<WidgetRecommendationCategory, List<WidgetItem>> recommendations,
            DeviceProfile deviceProfile,
            final @Px float availableHeight, final @Px int availableWidth,
            final @Px int cellPadding) {
        this.mAvailableHeight = availableHeight;
        Context context = getContext();
        mPageIndicator.setPauseScroll(true, deviceProfile.isTwoPanels);
        removeAllViews();

        int displayedCategories = 0;
@@ -133,7 +137,7 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
                new TreeMap<>(recommendations).entrySet()) {
            // If none of the recommendations for the category could fit in the mAvailableHeight, we
            // don't want to add that category; and we look for the next one.
            if (maybeDisplayInTable(entry.getValue(), availableWidth, cellPadding)) {
            if (maybeDisplayInTable(entry.getValue(), deviceProfile, availableWidth, cellPadding)) {
                mCategoryTitles.add(
                        context.getResources().getString(entry.getKey().categoryTitleRes));
                displayedCategories++;
@@ -145,14 +149,21 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
        }

        updateTitleAndIndicator();
        mPageIndicator.setPauseScroll(false, deviceProfile.isTwoPanels);
        return getChildCount() > 0;
    }

    /** Displays the page title and paging indicator if there are multiple pages. */
    private void updateTitleAndIndicator() {
        int titleAndIndicatorVisibility = getPageCount() > 1 ? View.VISIBLE : View.GONE;
        boolean showPaginatedView = getPageCount() > 1;
        int titleAndIndicatorVisibility = showPaginatedView ? View.VISIBLE : View.GONE;
        mRecommendationPageTitle.setVisibility(titleAndIndicatorVisibility);
        mPageIndicator.setVisibility(titleAndIndicatorVisibility);
        if (showPaginatedView) {
            mPageIndicator.setActiveMarker(0);
            setCurrentPage(0);
            mRecommendationPageTitle.setText(mCategoryTitles.get(0));
        }
    }

    @Override
@@ -218,9 +229,9 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
     * <p>Returns false if none of the recommendations could fit.</p>
     */
    private boolean maybeDisplayInTable(List<WidgetItem> recommendedWidgets,
            DeviceProfile deviceProfile,
            final @Px int availableWidth, final @Px int cellPadding) {
        Context context = getContext();
        DeviceProfile deviceProfile = Launcher.getLauncher(context).getDeviceProfile();
        LayoutInflater inflater = LayoutInflater.from(context);

        List<ArrayList<WidgetItem>> rows = groupWidgetItemsUsingRowPxWithoutReordering(
@@ -239,7 +250,7 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
        recommendationsTable.setWidgetCellLongClickListener(mWidgetCellOnLongClickListener);

        boolean displayedAtLeastOne = recommendationsTable.setRecommendedWidgets(rows,
                mAvailableHeight);
                deviceProfile, mAvailableHeight);
        if (displayedAtLeastOne) {
            addView(recommendationsTable);
        }
+2 −0
Original line number Diff line number Diff line
@@ -590,6 +590,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
        if (enableCategorizedWidgetSuggestions()) {
            mHasRecommendedWidgets = mWidgetRecommendationsView.setRecommendations(
                    mActivityContext.getPopupDataProvider().getCategorizedRecommendedWidgets(),
                    mDeviceProfile,
                    /* availableHeight= */ getMaxAvailableHeightForRecommendations(),
                    /* availableWidth= */ mMaxSpanPerRow,
                    /* cellPadding= */ mWidgetCellHorizontalPadding
@@ -597,6 +598,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
        } else {
            mHasRecommendedWidgets = mWidgetRecommendationsView.setRecommendations(
                    mActivityContext.getPopupDataProvider().getRecommendedWidgets(),
                    mDeviceProfile,
                    /* availableHeight= */ getMaxAvailableHeightForRecommendations(),
                    /* availableWidth= */ mMaxSpanPerRow,
                    /* cellPadding= */ mWidgetCellHorizontalPadding
Loading