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

Commit 558afdaf authored by Shamali P's avatar Shamali P
Browse files

[part 2] Update standalone picker to align widget loading and animations

In usual picker, widgets are already available before picker opens, so,
the work that happens during animations doesn't interrupt animations
on the scale it interrupt animations in standalone picker.

Bug: 346341156
Flag: EXEMPT bugfix
Test: Manual / see before after video
Change-Id: I7c8701447bd519b306799b28341d8f2f03daf59f
parent e4ca1910
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -120,10 +120,6 @@ public class WidgetPickerActivity extends BaseActivity {
        WindowInsetsController wc = mDragLayer.getWindowInsetsController();
        wc.hide(navigationBars() + statusBars());

        BaseWidgetSheet widgetSheet = WidgetsFullSheet.show(this, true);
        widgetSheet.disableNavBarScrim(true);
        widgetSheet.addOnCloseListener(this::finish);

        parseIntentExtras();
        refreshAndBindWidgets();
    }
@@ -224,9 +220,10 @@ public class WidgetPickerActivity extends BaseActivity {
        };
    }

    /** Updates the model with widgets and provides them after applying the provided filter. */
    /** Updates the model with widgets, applies filters and launches the widgets sheet once
     * widgets are available */
    private void refreshAndBindWidgets() {
        MODEL_EXECUTOR.execute(() -> {
        MODEL_EXECUTOR.getHandler().postDelayed(() -> {
            LauncherAppState app = LauncherAppState.getInstance(this);
            mModel.update(app, null);
            final List<WidgetsListBaseEntry> allWidgets =
@@ -240,6 +237,9 @@ public class WidgetPickerActivity extends BaseActivity {
                            }
                    );
            bindWidgets(allWidgets);
            // Open sheet once widgets are available, so that it doesn't interrupt the open
            // animation.
            openWidgetsSheet();
            if (mUiSurface != null) {
                Map<ComponentKey, WidgetItem> allWidgetItems = allWidgets.stream()
                        .filter(entry -> entry instanceof WidgetsListContentEntry)
@@ -253,15 +253,26 @@ public class WidgetPickerActivity extends BaseActivity {
                        mUiSurface, allWidgetItems);
                mWidgetPredictionsRequester.request(mAddedWidgets, this::bindRecommendedWidgets);
            }
        });
        }, mDeviceProfile.bottomSheetOpenDuration);
    }

    private void bindWidgets(List<WidgetsListBaseEntry> widgets) {
        MAIN_EXECUTOR.execute(() -> mPopupDataProvider.setAllWidgets(widgets));
    }

    private void openWidgetsSheet() {
        MAIN_EXECUTOR.execute(() -> {
            BaseWidgetSheet widgetSheet = WidgetsFullSheet.show(this, true);
            widgetSheet.disableNavBarScrim(true);
            widgetSheet.addOnCloseListener(this::finish);
        });
    }

    private void bindRecommendedWidgets(List<ItemInfo> recommendedWidgets) {
        MAIN_EXECUTOR.execute(() -> mPopupDataProvider.setRecommendedWidgets(recommendedWidgets));
        // Bind recommendations once picker has finished open animation.
        MAIN_EXECUTOR.getHandler().postDelayed(
                () -> mPopupDataProvider.setRecommendedWidgets(recommendedWidgets),
                mDeviceProfile.bottomSheetOpenDuration);
    }

    @Override
+11 −5
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class WidgetPredictionsRequester {
    private final Context mContext;
    @NonNull
    private final String mUiSurface;
    private boolean mPredictionsAvailable;
    @NonNull
    private final Map<ComponentKey, WidgetItem> mAllWidgets;

@@ -76,8 +77,8 @@ public class WidgetPredictionsRequester {
    }

    /**
     * Requests predictions from the app predictions manager and registers the provided callback to
     * receive updates when predictions are available.
     * Requests one time predictions from the app predictions manager and invokes provided callback
     * once predictions are available.
     *
     * @param existingWidgets widgets that are currently added to the surface;
     * @param callback        consumer of prediction results to be called when predictions are
@@ -159,10 +160,14 @@ public class WidgetPredictionsRequester {
    @WorkerThread
    private void bindPredictions(List<AppTarget> targets, Predicate<WidgetItem> filter,
            Consumer<List<ItemInfo>> callback) {
        if (!mPredictionsAvailable) {
            mPredictionsAvailable = true;
            List<WidgetItem> filteredPredictions = filterPredictions(targets, mAllWidgets, filter);
            List<ItemInfo> mappedPredictions = mapWidgetItemsToItemInfo(filteredPredictions);

            MAIN_EXECUTOR.execute(() -> callback.accept(mappedPredictions));
            MODEL_EXECUTOR.execute(this::clear);
        }
    }

    /**
@@ -214,5 +219,6 @@ public class WidgetPredictionsRequester {
            mAppPredictor.destroy();
            mAppPredictor = null;
        }
        mPredictionsAvailable = false;
    }
}