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

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

Merge "Double pre-inflate counts if work profile is enabled" into main

parents d0bf41bc 25eac138
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.keyboard.FocusedItemDecorator;
import com.android.launcher3.model.StringCache;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.recyclerview.AllAppsRecyclerViewPool;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ActivityContext;
@@ -93,7 +94,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * All apps container view with search support for use in a dragging activity.
@@ -623,16 +623,18 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
    private static void setUpCustomRecyclerViewPool(
            @NonNull AllAppsRecyclerView mainRecyclerView,
            @Nullable AllAppsRecyclerView workRecyclerView,
            @NonNull RecyclerView.RecycledViewPool recycledViewPool) {
            @NonNull AllAppsRecyclerViewPool recycledViewPool) {
        if (!ENABLE_ALL_APPS_RV_PREINFLATION.get()) {
            return;
        }
        final boolean hasWorkProfile = workRecyclerView != null;
        recycledViewPool.setHasWorkProfile(hasWorkProfile);
        mainRecyclerView.setRecycledViewPool(recycledViewPool);
        if (workRecyclerView != null) {
            workRecyclerView.setRecycledViewPool(recycledViewPool);
        }
        if (ALL_APPS_GONE_VISIBILITY.get()) {
            mainRecyclerView.updatePoolSize();
            mainRecyclerView.updatePoolSize(hasWorkProfile);
        }
    }

+7 −0
Original line number Diff line number Diff line
@@ -95,6 +95,10 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
    }

    protected void updatePoolSize() {
        updatePoolSize(false);
    }

    void updatePoolSize(boolean hasWorkProfile) {
        DeviceProfile grid = ActivityContext.lookupContext(getContext()).getDeviceProfile();
        RecyclerView.RecycledViewPool pool = getRecycledViewPool();
        pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_EMPTY_SEARCH, 1);
@@ -111,6 +115,9 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
            maxPoolSizeForAppIcons +=
                    PREINFLATE_ICONS_ROW_COUNT * grid.numShownAllAppsColumns + EXTRA_ICONS_COUNT;
        }
        if (hasWorkProfile) {
            maxPoolSizeForAppIcons *= 2;
        }
        pool.setMaxRecycledViews(
                AllAppsGridAdapter.VIEW_TYPE_ICON, maxPoolSizeForAppIcons);
    }
+1 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ 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;
@@ -110,7 +109,7 @@ public class AllAppsStore<T extends Context & ActivityContext> {
        }
    }

    RecycledViewPool getRecyclerViewPool() {
    AllAppsRecyclerViewPool getRecyclerViewPool() {
        return mAllAppsRecyclerViewPool;
    }

+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ class AllAppsRecyclerViewPool<T> : RecycledViewPool() {

    private var future: Future<Void>? = null

    var hasWorkProfile = false

    /**
     * Preinflate app icons. If all apps RV cannot be scrolled down, we don't need to preinflate.
     */
@@ -95,6 +97,9 @@ class AllAppsRecyclerViewPool<T> : RecycledViewPool() {
            val grid = ActivityContext.lookupContext<T>(context).deviceProfile
            targetPreinflateCount += grid.maxAllAppsRowCount * grid.numShownAllAppsColumns
        }
        if (hasWorkProfile) {
            targetPreinflateCount *= 2
        }
        val existingPreinflateCount = getRecycledViewCount(BaseAllAppsAdapter.VIEW_TYPE_ICON)
        return targetPreinflateCount - existingPreinflateCount
    }