Merge "Converting ModelTask to an interface instead of an abstract class" into main
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.android.launcher3.model;
|
||||
|
||||
import static com.android.launcher3.LauncherPrefs.nonRestorableItem;
|
||||
import static com.android.launcher3.EncryptionType.ENCRYPTED;
|
||||
import static com.android.launcher3.LauncherPrefs.nonRestorableItem;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
|
||||
import static com.android.quickstep.InstantAppResolverImpl.COMPONENT_CLASS_MARKER;
|
||||
|
||||
@@ -32,6 +32,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.launcher3.ConstantItem;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherModel.ModelUpdateTask;
|
||||
import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.QuickstepModelDelegate.PredictorState;
|
||||
@@ -47,7 +48,7 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* Task to update model as a result of predicted apps update
|
||||
*/
|
||||
public class PredictionUpdateTask extends BaseModelUpdateTask {
|
||||
public class PredictionUpdateTask implements ModelUpdateTask {
|
||||
|
||||
public static final ConstantItem<Boolean> LAST_PREDICTION_ENABLED =
|
||||
nonRestorableItem("last_prediction_enabled_state", true, ENCRYPTED);
|
||||
@@ -61,8 +62,9 @@ public class PredictionUpdateTask extends BaseModelUpdateTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NonNull final LauncherAppState app, @NonNull final BgDataModel dataModel,
|
||||
@NonNull final AllAppsList apps) {
|
||||
public void execute(@NonNull ModelTaskController taskController, @NonNull BgDataModel dataModel,
|
||||
@NonNull AllAppsList apps) {
|
||||
LauncherAppState app = taskController.getApp();
|
||||
Context context = app.getContext();
|
||||
|
||||
// TODO: remove this
|
||||
@@ -119,7 +121,7 @@ public class PredictionUpdateTask extends BaseModelUpdateTask {
|
||||
|
||||
FixedContainerItems fci = new FixedContainerItems(mPredictorState.containerId, items);
|
||||
dataModel.extraItems.put(fci.containerId, fci);
|
||||
bindExtraContainerItems(fci);
|
||||
taskController.bindExtraContainerItems(fci);
|
||||
usersForChangedShortcuts.forEach(
|
||||
u -> dataModel.updateShortcutPinnedState(app.getContext(), u));
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherModel.ModelUpdateTask;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.QuickstepModelDelegate.PredictorState;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
@@ -41,7 +41,7 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** Task to update model as a result of predicted widgets update */
|
||||
public final class WidgetsPredictionUpdateTask extends BaseModelUpdateTask {
|
||||
public final class WidgetsPredictionUpdateTask implements ModelUpdateTask {
|
||||
private final PredictorState mPredictorState;
|
||||
private final List<AppTarget> mTargets;
|
||||
|
||||
@@ -58,8 +58,8 @@ public final class WidgetsPredictionUpdateTask extends BaseModelUpdateTask {
|
||||
* workspace.
|
||||
*/
|
||||
@Override
|
||||
public void execute(@NonNull final LauncherAppState appState,
|
||||
@NonNull final BgDataModel dataModel, @NonNull final AllAppsList apps) {
|
||||
public void execute(@NonNull ModelTaskController taskController, @NonNull BgDataModel dataModel,
|
||||
@NonNull AllAppsList apps) {
|
||||
Set<ComponentKey> widgetsInWorkspace = dataModel.appWidgets.stream().map(
|
||||
widget -> new ComponentKey(widget.providerName, widget.user)).collect(
|
||||
Collectors.toSet());
|
||||
@@ -98,7 +98,7 @@ public final class WidgetsPredictionUpdateTask extends BaseModelUpdateTask {
|
||||
|
||||
List<ItemInfo> items;
|
||||
if (enableCategorizedWidgetSuggestions()) {
|
||||
Context context = appState.getContext();
|
||||
Context context = taskController.getApp().getContext();
|
||||
WidgetRecommendationCategoryProvider categoryProvider =
|
||||
WidgetRecommendationCategoryProvider.newInstance(context);
|
||||
items = servicePredictedItems.stream()
|
||||
@@ -115,7 +115,7 @@ public final class WidgetsPredictionUpdateTask extends BaseModelUpdateTask {
|
||||
new FixedContainerItems(mPredictorState.containerId, items);
|
||||
|
||||
dataModel.extraItems.put(mPredictorState.containerId, fixedContainerItems);
|
||||
bindExtraContainerItems(fixedContainerItems);
|
||||
taskController.bindExtraContainerItems(fixedContainerItems);
|
||||
|
||||
// Don't store widgets prediction to disk because it is not used frequently.
|
||||
}
|
||||
|
||||
@@ -58,10 +58,6 @@ import com.android.launcher3.logger.LauncherAtomExtensions.DeviceSearchResultCon
|
||||
import com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers;
|
||||
import com.android.launcher3.logging.InstanceId;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.model.AllAppsList;
|
||||
import com.android.launcher3.model.BaseModelUpdateTask;
|
||||
import com.android.launcher3.model.BgDataModel;
|
||||
import com.android.launcher3.model.data.CollectionInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.LogConfig;
|
||||
@@ -371,17 +367,9 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
if (mItemInfo.container < 0 || !LauncherAppState.INSTANCE.executeIfCreated(app -> {
|
||||
// Item is inside a collection, fetch collection info in a BG thread
|
||||
// and then write to StatsLog.
|
||||
app.getModel().enqueueModelUpdateTask(
|
||||
new BaseModelUpdateTask() {
|
||||
@Override
|
||||
public void execute(@NonNull final LauncherAppState app,
|
||||
@NonNull final BgDataModel dataModel,
|
||||
@NonNull final AllAppsList apps) {
|
||||
CollectionInfo collectionInfo =
|
||||
dataModel.collections.get(mItemInfo.container);
|
||||
write(event, applyOverwrites(mItemInfo.buildProto(collectionInfo)));
|
||||
}
|
||||
});
|
||||
app.getModel().enqueueModelUpdateTask((taskController, dataModel, apps) ->
|
||||
write(event, applyOverwrites(mItemInfo.buildProto(
|
||||
dataModel.collections.get(mItemInfo.container)))));
|
||||
})) {
|
||||
// Write log on the model thread so that logs do not go out of order
|
||||
// (for eg: drop comes after drag)
|
||||
|
||||
Reference in New Issue
Block a user