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

This commit is contained in:
Fengjiang Li
2023-10-16 21:36:52 +00:00
committed by Android (Google) Code Review
4 changed files with 18 additions and 5 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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
}