Merge "Fix All Apps Icons Count estimation" into main

This commit is contained in:
Fengjiang Li
2023-10-03 21:57:36 +00:00
committed by Android (Google) Code Review
3 changed files with 21 additions and 10 deletions
@@ -704,6 +704,17 @@ public class DeviceProfile {
return renderer;
}
/**
* Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed
* row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This
* method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus
* reasonable over estimation is fine.
*/
public int getMaxAllAppsRowCount() {
return (int) (Math.ceil((availableHeightPx - allAppsTopPadding)
/ (float) allAppsCellHeightPx));
}
/**
* QSB width is always calculated because when in 3 button nav the width doesn't follow the
* width of the hotseat.
@@ -16,6 +16,7 @@
package com.android.launcher3.allapps;
import static com.android.launcher3.config.FeatureFlags.ALL_APPS_GONE_VISIBILITY;
import static com.android.launcher3.config.FeatureFlags.ENABLE_ALL_APPS_RV_PREINFLATION;
import static com.android.launcher3.logger.LauncherAtom.ContainerInfo;
import static com.android.launcher3.logger.LauncherAtom.SearchResultContainer;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_PERSONAL_SCROLLED_DOWN;
@@ -96,16 +97,17 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
protected void updatePoolSize() {
DeviceProfile grid = ActivityContext.lookupContext(getContext()).getDeviceProfile();
RecyclerView.RecycledViewPool pool = getRecycledViewPool();
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);
// If all apps' hidden visibility is INVISIBLE, we will need to preinflate one page of
// all apps icons for smooth scrolling.
int maxPoolSizeForAppIcons = (approxRows + 1) * grid.numShownAllAppsColumns;
if (ALL_APPS_GONE_VISIBILITY.get()) {
// If all apps' hidden visibility is GONE, we need to increase prefinated icons number
// by [PREINFLATE_ICONS_ROW_COUNT] rows + [EXTRA_ICONS_COUNT] for fast opening all apps.
// By default the max num of pool size for app icons is num of app icons in one page of
// all apps.
int maxPoolSizeForAppIcons = grid.getMaxAllAppsRowCount()
* grid.numShownAllAppsColumns;
if (ALL_APPS_GONE_VISIBILITY.get() && ENABLE_ALL_APPS_RV_PREINFLATION.get()) {
// If we set all apps' hidden visibility to GONE and enable pre-inflation, we want to
// preinflate one page of all apps icons plus [PREINFLATE_ICONS_ROW_COUNT] rows +
// [EXTRA_ICONS_COUNT]. Thus we need to bump the max pool size of app icons accordingly.
maxPoolSizeForAppIcons +=
PREINFLATE_ICONS_ROW_COUNT * grid.numShownAllAppsColumns + EXTRA_ICONS_COUNT;
}
@@ -93,9 +93,7 @@ class AllAppsRecyclerViewPool<T> : RecycledViewPool() {
EXTRA_ICONS_COUNT
if (FeatureFlags.ALL_APPS_GONE_VISIBILITY.get()) {
val grid = ActivityContext.lookupContext<T>(context).deviceProfile
val approxRows =
Math.ceil((grid.availableHeightPx / grid.allAppsIconSizePx).toDouble()).toInt()
targetPreinflateCount += (approxRows + 1) * grid.numShownAllAppsColumns
targetPreinflateCount += grid.maxAllAppsRowCount * grid.numShownAllAppsColumns
}
val existingPreinflateCount = getRecycledViewCount(BaseAllAppsAdapter.VIEW_TYPE_ICON)
return targetPreinflateCount - existingPreinflateCount