Moving finishBindingItems to ModelCallbacks
Changes are part of go/launcher_SoR .
Flag: NA
Bug: 301108526
Test: TaplWorkspace
Change-Id: I4c35b540511c9655de1aa1fd0a808a75e7295c1b
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 126efbb..1e50220 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -847,6 +847,17 @@
return screenId;
}
+ /**
+ * Process any pending activity result if it was put on hold for any reason like item binding.
+ */
+ public void processActivityResult() {
+ if (mPendingActivityResult != null) {
+ handleActivityResult(mPendingActivityResult.requestCode,
+ mPendingActivityResult.resultCode, mPendingActivityResult.data);
+ mPendingActivityResult = null;
+ }
+ }
+
private void handleActivityResult(
final int requestCode, final int resultCode, final Intent data) {
if (isWorkspaceLoading()) {
@@ -2520,34 +2531,7 @@
* Implementation of the method from LauncherModel.Callbacks.
*/
public void finishBindingItems(IntSet pagesBoundFirst) {
- TraceHelper.INSTANCE.beginSection("finishBindingItems");
- mWorkspace.restoreInstanceStateForRemainingPages();
-
- mModelCallbacks.setWorkspaceLoading(false);
-
- if (mPendingActivityResult != null) {
- handleActivityResult(mPendingActivityResult.requestCode,
- mPendingActivityResult.resultCode, mPendingActivityResult.data);
- mPendingActivityResult = null;
- }
-
- int currentPage = pagesBoundFirst != null && !pagesBoundFirst.isEmpty()
- ? mWorkspace.getPageIndexForScreenId(pagesBoundFirst.getArray().get(0))
- : PagedView.INVALID_PAGE;
- // When undoing the removal of the last item on a page, return to that page.
- // Since we are just resetting the current page without user interaction,
- // override the previous page so we don't log the page switch.
- mWorkspace.setCurrentPage(currentPage, currentPage /* overridePrevPage */);
- mModelCallbacks.setPagesToBindSynchronously(new IntSet());
-
- // Cache one page worth of icons
- getViewCache().setCacheSize(R.layout.folder_application,
- mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
- getViewCache().setCacheSize(R.layout.folder_page, 2);
-
- TraceHelper.INSTANCE.endSection();
- mWorkspace.removeExtraEmptyScreen(/* stripEmptyScreens= */ true);
- mWorkspace.mPageIndicator.setAreScreensBinding(false, mDeviceProfile.isTwoPanels);
+ mModelCallbacks.finishBindingItems(pagesBoundFirst);
}
private boolean canAnimatePageChange() {
diff --git a/src/com/android/launcher3/ModelCallbacks.kt b/src/com/android/launcher3/ModelCallbacks.kt
index 51d7690..c05158b 100644
--- a/src/com/android/launcher3/ModelCallbacks.kt
+++ b/src/com/android/launcher3/ModelCallbacks.kt
@@ -14,7 +14,6 @@
import com.android.launcher3.popup.PopupContainerWithArrow
import com.android.launcher3.util.ComponentKey
import com.android.launcher3.util.IntArray as LIntArray
-import com.android.launcher3.util.IntArray
import com.android.launcher3.util.IntSet as LIntSet
import com.android.launcher3.util.IntSet
import com.android.launcher3.util.PackageUserKey
@@ -66,6 +65,38 @@
}
/**
+ * Callback saying that there aren't any more items to bind.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ override fun finishBindingItems(pagesBoundFirst: LIntSet?) {
+ TraceHelper.INSTANCE.beginSection("finishBindingItems")
+ val deviceProfile = launcher.deviceProfile
+ launcher.workspace.restoreInstanceStateForRemainingPages()
+ workspaceLoading = false
+ launcher.processActivityResult()
+ val currentPage =
+ if (pagesBoundFirst != null && !pagesBoundFirst.isEmpty)
+ launcher.workspace.getPageIndexForScreenId(pagesBoundFirst.array[0])
+ else PagedView.INVALID_PAGE
+ // When undoing the removal of the last item on a page, return to that page.
+ // Since we are just resetting the current page without user interaction,
+ // override the previous page so we don't log the page switch.
+ launcher.workspace.setCurrentPage(currentPage, currentPage /* overridePrevPage */)
+ pagesToBindSynchronously = IntSet()
+
+ // Cache one page worth of icons
+ launcher.viewCache.setCacheSize(
+ R.layout.folder_application,
+ deviceProfile.inv.numFolderColumns * deviceProfile.inv.numFolderRows
+ )
+ launcher.viewCache.setCacheSize(R.layout.folder_page, 2)
+ TraceHelper.INSTANCE.endSection()
+ launcher.workspace.removeExtraEmptyScreen(/* stripEmptyScreens= */ true)
+ launcher.workspace.pageIndicator.setAreScreensBinding(false, deviceProfile.isTwoPanels)
+ }
+
+ /**
* Clear any pending bind callbacks. This is called when is loader is planning to perform a full
* rebind from scratch.
*/
@@ -225,7 +256,7 @@
)
}
- override fun bindScreens(orderedScreenIds: IntArray) {
+ override fun bindScreens(orderedScreenIds: LIntArray) {
launcher.workspace.pageIndicator.setAreScreensBinding(
true,
launcher.deviceProfile.isTwoPanels
@@ -255,7 +286,7 @@
}
override fun bindAppsAdded(
- newScreens: IntArray?,
+ newScreens: LIntArray?,
addNotAnimated: java.util.ArrayList<ItemInfo?>?,
addAnimated: java.util.ArrayList<ItemInfo?>?
) {
@@ -280,7 +311,7 @@
launcher.workspace.removeExtraEmptyScreen(false)
}
- private fun bindAddScreens(orderedScreenIdsArg: IntArray) {
+ private fun bindAddScreens(orderedScreenIdsArg: LIntArray) {
var orderedScreenIds = orderedScreenIdsArg
if (launcher.deviceProfile.isTwoPanels) {
if (FeatureFlags.FOLDABLE_SINGLE_PAGE.get()) {
@@ -311,7 +342,7 @@
* Remove odd number because they are already included when isTwoPanels and add the pair screen
* if not present.
*/
- private fun filterTwoPanelScreenIds(orderedScreenIds: IntArray): IntArray {
+ private fun filterTwoPanelScreenIds(orderedScreenIds: LIntArray): LIntArray {
val screenIds = IntSet.wrap(orderedScreenIds)
orderedScreenIds
.filter { screenId -> screenId % 2 == 1 }