Add two panel home support for page binding logic

There's a logic which prioritizes the binding for the
current page and defers the other pages' binding.
If two panel home is enabled, we want to bind both pages
together. LauncherPageRestoreHelper has been created to
contain the logic for persisting restoring and calculating
which pages to load immediately.

Test: manual + run LauncherPageRestoreHelperTest robo test
Bug: 174464691
Change-Id: I57ac3f7150303b95b272e922f44bda26f9d5ce2a
This commit is contained in:
Andras Kloczl
2021-05-24 23:22:06 +02:00
parent f3649f5e98
commit 55edfe55f7
17 changed files with 499 additions and 85 deletions
@@ -24,13 +24,13 @@ import android.util.Log;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel.CallbackTask;
import com.android.launcher3.PagedView;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.LooperIdleLock;
import com.android.launcher3.util.ViewOnDrawExecutor;
@@ -160,20 +160,26 @@ public abstract class BaseLoaderResults {
}
private void bind() {
final int currentScreen;
IntSet currentScreenIndices;
{
// Create an anonymous scope to calculate currentScreen as it has to be a
// final variable.
int currScreen = mCallbacks.getPageToBindSynchronously();
if (currScreen >= mOrderedScreenIds.size()) {
// There may be no workspace screens (just hotseat items and an empty page).
currScreen = PagedView.INVALID_PAGE;
IntSet screenIndices = mCallbacks.getPagesToBindSynchronously();
if (screenIndices == null || screenIndices.isEmpty()
|| screenIndices.getArray().get(screenIndices.size() - 1)
>= mOrderedScreenIds.size()) {
// There maybe no workspace screens (just hotseat items and an empty page).
// Also we want to prevent IndexOutOfBoundsExceptions.
screenIndices = new IntSet();
}
currentScreen = currScreen;
currentScreenIndices = screenIndices;
}
final boolean validFirstPage = currentScreen >= 0;
final int currentScreenId =
validFirstPage ? mOrderedScreenIds.get(currentScreen) : INVALID_SCREEN_ID;
final boolean validFirstPage = !currentScreenIndices.isEmpty();
IntSet currentScreenIds = new IntSet();
currentScreenIndices.forEach(
index -> currentScreenIds.add(mOrderedScreenIds.get(index)));
// Separate the items that are on the current screen, and all the other remaining items
ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
@@ -181,9 +187,9 @@ public abstract class BaseLoaderResults {
ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
filterCurrentWorkspaceItems(currentScreenId, mWorkspaceItems, currentWorkspaceItems,
filterCurrentWorkspaceItems(currentScreenIds, mWorkspaceItems, currentWorkspaceItems,
otherWorkspaceItems);
filterCurrentWorkspaceItems(currentScreenId, mAppWidgets, currentAppWidgets,
filterCurrentWorkspaceItems(currentScreenIds, mAppWidgets, currentAppWidgets,
otherAppWidgets);
final InvariantDeviceProfile idp = mApp.getInvariantDeviceProfile();
sortWorkspaceItemsSpatially(idp, currentWorkspaceItems);
@@ -220,14 +226,14 @@ public abstract class BaseLoaderResults {
bindWorkspaceItems(otherWorkspaceItems, deferredExecutor);
bindAppWidgets(otherAppWidgets, deferredExecutor);
// Tell the workspace that we're done binding items
executeCallbacksTask(c -> c.finishBindingItems(currentScreen), deferredExecutor);
executeCallbacksTask(c -> c.finishBindingItems(currentScreenIndices), deferredExecutor);
if (validFirstPage) {
executeCallbacksTask(c -> {
// We are loading synchronously, which means, some of the pages will be
// bound after first draw. Inform the mCallbacks that page binding is
// not complete, and schedule the remaining pages.
c.onPageBoundSynchronously(currentScreen);
c.onPagesBoundSynchronously(currentScreenIndices);
c.executeOnNextDraw((ViewOnDrawExecutor) deferredExecutor);
}, mUiExecutor);