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

Commit 1e3d799f authored by Fengjiang Li's avatar Fengjiang Li Committed by Android (Google) Code Review
Browse files

Merge changes from topic "preinflate-allapps-rv" into udc-qpr-dev

* changes:
  Pre-inflate BubbleTextViews into Launcher/TaskBar All Apps RV
  Fix calculation of all apps recyclerview pool size of app icons
parents 66ec0f6a 1519c168
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.launcher3.allapps;
import static com.android.launcher3.allapps.ActivityAllAppsContainerView.AdapterHolder.SEARCH;
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_DISABLED_CARD;
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_EDU_CARD;
import static com.android.launcher3.config.FeatureFlags.ENABLE_ALL_APPS_RV_PREINFLATION;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_COUNT;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_PERSONAL_TAB;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_WORK_TAB;
@@ -79,7 +80,6 @@ import com.android.launcher3.keyboard.FocusedItemDecorator;
import com.android.launcher3.model.StringCache;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ActivityContext;
@@ -141,7 +141,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
    private final SearchTransitionController mSearchTransitionController;
    private final Paint mHeaderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private final Rect mInsets = new Rect();
    private final AllAppsStore mAllAppsStore = new AllAppsStore();
    private final AllAppsStore mAllAppsStore;
    private final RecyclerView.OnScrollListener mScrollListener =
            new RecyclerView.OnScrollListener() {
                @Override
@@ -194,6 +194,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
    public ActivityAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mActivityContext = ActivityContext.lookupContext(context);
        mAllAppsStore = new AllAppsStore(mActivityContext);

        mScrimColor = Themes.getAttrColor(context, R.attr.allAppsScrimColor);
        mHeaderThreshold = getResources().getDimensionPixelSize(
@@ -559,6 +560,13 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
            mAH.get(AdapterHolder.MAIN).setup(mViewPager.getChildAt(0), mPersonalMatcher);
            mAH.get(AdapterHolder.WORK).setup(mViewPager.getChildAt(1), mWorkManager.getMatcher());
            mAH.get(AdapterHolder.WORK).mRecyclerView.setId(R.id.apps_list_view_work);
            if (ENABLE_ALL_APPS_RV_PREINFLATION.get()) {
                // Let main and work rv share same view pool.
                ((RecyclerView) mViewPager.getChildAt(0))
                        .setRecycledViewPool(mAllAppsStore.getRecyclerViewPool());
                ((RecyclerView) mViewPager.getChildAt(1))
                        .setRecycledViewPool(mAllAppsStore.getRecyclerViewPool());
            }
            if (FeatureFlags.ENABLE_EXPANDING_PAUSE_WORK_BUTTON.get()) {
                mAH.get(AdapterHolder.WORK).mRecyclerView.addOnScrollListener(
                        mWorkManager.newScrollListener());
+2 −2
Original line number Diff line number Diff line
@@ -96,8 +96,8 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
        int approxRows = (int) Math.ceil(grid.availableHeightPx / grid.allAppsIconSizePx);
        pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_EMPTY_SEARCH, 1);
        pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_ALL_APPS_DIVIDER, 1);
        pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_ICON, approxRows
                * (mNumAppsPerRow + 1));
        pool.setMaxRecycledViews(
                AllAppsGridAdapter.VIEW_TYPE_ICON, (approxRows + 1) * grid.numShownAllAppsColumns);
    }

    @Override
+26 −2
Original line number Diff line number Diff line
@@ -15,24 +15,30 @@
 */
package com.android.launcher3.allapps;

import static com.android.launcher3.config.FeatureFlags.ENABLE_ALL_APPS_RV_PREINFLATION;
import static com.android.launcher3.model.data.AppInfo.COMPONENT_KEY_COMPARATOR;
import static com.android.launcher3.model.data.AppInfo.EMPTY_ARRAY;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK;
import static com.android.launcher3.testing.shared.TestProtocol.WORK_TAB_MISSING;

import android.content.Context;
import android.os.UserHandle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.recyclerview.AllAppsRecyclerViewPool;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.views.ActivityContext;

import java.util.ArrayList;
import java.util.Arrays;
@@ -45,8 +51,10 @@ import java.util.function.Predicate;

/**
 * A utility class to maintain the collection of all apps.
 *
 * @param <T> The type of the context.
 */
public class AllAppsStore {
public class AllAppsStore<T extends Context & ActivityContext> {

    // Defer updates flag used to defer all apps updates to the next draw.
    public static final int DEFER_UPDATES_NEXT_DRAW = 1 << 0;
@@ -64,11 +72,18 @@ public class AllAppsStore {
    private int mModelFlags;
    private int mDeferUpdatesFlags = 0;
    private boolean mUpdatePending = false;
    private final AllAppsRecyclerViewPool mAllAppsRecyclerViewPool = new AllAppsRecyclerViewPool();

    private final T mContext;

    public AppInfo[] getApps() {
        return mApps;
    }

    public AllAppsStore(@NonNull T context) {
        mContext = context;
    }

    /**
     * Sets the current set of apps and sets mapping for {@link PackageUserKey} to Uid for
     * the current set of apps.
@@ -78,6 +93,15 @@ public class AllAppsStore {
        mModelFlags = flags;
        notifyUpdate();
        mPackageUserKeytoUidMap = map;
        // Preinflate all apps RV when apps has changed, which can happen after unlocking screen,
        // rotating screen, or downloading/upgrading apps.
        if (ENABLE_ALL_APPS_RV_PREINFLATION.get()) {
            mAllAppsRecyclerViewPool.preInflateAllAppsViewHolders(mContext);
        }
    }

    RecycledViewPool getRecyclerViewPool() {
        return mAllAppsRecyclerViewPool;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ import androidx.recyclerview.widget.RecyclerView;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.views.ActivityContext;
+6 −0
Original line number Diff line number Diff line
@@ -396,6 +396,12 @@ public final class FeatureFlags {
            "ENABLE_RESPONSIVE_WORKSPACE", DISABLED,
            "Enables new workspace grid calculations method.");

    // TODO(Block 33): Clean up flags

    public static final BooleanFlag ENABLE_ALL_APPS_RV_PREINFLATION = getDebugFlag(288161355,
            "ENABLE_ALL_APPS_RV_PREINFLATION", DISABLED,
            "Enables preinflating all apps icons to avoid scrolling jank.");

    public static class BooleanFlag {

        private final boolean mCurrentValue;
Loading