Merge "Moving predicted items to ItemIdMap instead of extraItems" into main
This commit is contained in:
@@ -53,8 +53,8 @@ import com.android.launcher3.graphics.DragPreviewProvider;
|
||||
import com.android.launcher3.logger.LauncherAtom.ContainerInfo;
|
||||
import com.android.launcher3.logger.LauncherAtom.PredictedHotseatContainer;
|
||||
import com.android.launcher3.logging.InstanceId;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.PredictedContainerInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.popup.SystemShortcut;
|
||||
@@ -285,8 +285,8 @@ public class HotseatPredictionController implements DragController.DragListener,
|
||||
/**
|
||||
* Sets or updates the predicted items
|
||||
*/
|
||||
public void setPredictedItems(FixedContainerItems items) {
|
||||
mPredictedItems = new ArrayList(items.items);
|
||||
public void setPredictedItems(PredictedContainerInfo items) {
|
||||
mPredictedItems = items.getContents();
|
||||
if (mPredictedItems.isEmpty()) {
|
||||
HotseatRestoreHelper.restoreBackup(mLauncher);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.launcher3.model.BgDataModel;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.PredictionHelper;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
|
||||
@@ -58,12 +57,9 @@ public class HotseatPredictionModel {
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
ArrayList<AppTarget> currentTargets = new ArrayList<>();
|
||||
FixedContainerItems hotseatItems = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
|
||||
if (hotseatItems != null) {
|
||||
for (ItemInfo itemInfo : hotseatItems.items) {
|
||||
AppTarget target = getAppTargetFromItemInfo(context, itemInfo);
|
||||
if (target != null) currentTargets.add(target);
|
||||
}
|
||||
for (ItemInfo itemInfo : dataModel.getPredictedContents(CONTAINER_HOTSEAT_PREDICTION)) {
|
||||
AppTarget target = getAppTargetFromItemInfo(context, itemInfo);
|
||||
if (target != null) currentTargets.add(target);
|
||||
}
|
||||
bundle.putParcelableArrayList(BUNDLE_KEY_PIN_EVENTS, events);
|
||||
bundle.putParcelableArrayList(BUNDLE_KEY_CURRENT_ITEMS, currentTargets);
|
||||
|
||||
@@ -34,12 +34,13 @@ import com.android.launcher3.ConstantItem;
|
||||
import com.android.launcher3.LauncherModel.ModelUpdateTask;
|
||||
import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
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.PredictedContainerInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -70,7 +71,7 @@ public class PredictionUpdateTask implements ModelUpdateTask {
|
||||
LauncherPrefs.get(context).put(LAST_PREDICTION_ENABLED, !mTargets.isEmpty());
|
||||
|
||||
Set<UserHandle> usersForChangedShortcuts =
|
||||
dataModel.extraItems.get(mPredictorState.containerId).items.stream()
|
||||
dataModel.getPredictedContents(mPredictorState.containerId).stream()
|
||||
.filter(info -> info.itemType == ITEM_TYPE_DEEP_SHORTCUT)
|
||||
.map(info -> info.user)
|
||||
.collect(Collectors.toSet());
|
||||
@@ -118,12 +119,12 @@ public class PredictionUpdateTask implements ModelUpdateTask {
|
||||
items.add(itemInfo);
|
||||
}
|
||||
|
||||
FixedContainerItems fci = new FixedContainerItems(mPredictorState.containerId, items);
|
||||
dataModel.extraItems.put(fci.containerId, fci);
|
||||
taskController.bindExtraContainerItems(fci);
|
||||
PredictedContainerInfo pci = new PredictedContainerInfo(mPredictorState.containerId, items);
|
||||
dataModel.itemsIdMap.put(pci.id, pci);
|
||||
taskController.bindUpdatedWorkspaceItems(Collections.singleton(pci));
|
||||
usersForChangedShortcuts.forEach(u -> dataModel.updateShortcutPinnedState(context, u));
|
||||
|
||||
// Save to disk
|
||||
mPredictorState.storage.write(context, fci.items);
|
||||
mPredictorState.storage.write(context, pci.getContents());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import static android.text.format.DateUtils.formatElapsedTime;
|
||||
|
||||
import static com.android.launcher3.EncryptionType.ENCRYPTED;
|
||||
import static com.android.launcher3.LauncherPrefs.nonRestorableItem;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS_PREDICTION;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.DESKTOP_ICON_FLAG;
|
||||
import static com.android.launcher3.hybridhotseat.HotseatPredictionModel.convertDataModelToAppTargetBundle;
|
||||
@@ -55,9 +55,9 @@ import com.android.launcher3.dagger.ApplicationContext;
|
||||
import com.android.launcher3.logger.LauncherAtom;
|
||||
import com.android.launcher3.logging.InstanceId;
|
||||
import com.android.launcher3.logging.InstanceIdSequence;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.data.CollectionInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.PredictedContainerInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
import com.android.quickstep.logging.SettingsChangeLogger;
|
||||
@@ -142,18 +142,18 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
private void loadAndBindPredictedItems(
|
||||
int numColumns, @NonNull PredictorState state) {
|
||||
PredictedItemFactory parser = mItemParserFactory.newParser(numColumns, state);
|
||||
FixedContainerItems fci = new FixedContainerItems(state.containerId,
|
||||
PredictedContainerInfo fci = new PredictedContainerInfo(state.containerId,
|
||||
state.storage.read(mContext, parser, mUserCache::getUserForSerialNumber));
|
||||
mDataModel.extraItems.put(state.containerId, fci);
|
||||
mDataModel.itemsIdMap.put(state.containerId, fci);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void loadAndBindOtherItems() {
|
||||
FixedContainerItems widgetPredictionFCI = new FixedContainerItems(
|
||||
PredictedContainerInfo widgetPredictionFCI = new PredictedContainerInfo(
|
||||
mWidgetsRecommendationState.containerId, new ArrayList<>());
|
||||
// Widgets prediction isn't used frequently. And thus, it is not persisted on disk.
|
||||
mDataModel.extraItems.put(mWidgetsRecommendationState.containerId, widgetPredictionFCI);
|
||||
mDataModel.itemsIdMap.put(mWidgetsRecommendationState.containerId, widgetPredictionFCI);
|
||||
}
|
||||
|
||||
public void markActive() {
|
||||
|
||||
@@ -31,8 +31,8 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.launcher3.LauncherModel.ModelUpdateTask;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.PredictedContainerInfo;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo;
|
||||
import com.android.launcher3.widget.picker.WidgetRecommendationCategoryProvider;
|
||||
@@ -133,11 +133,11 @@ public final class WidgetsPredictionUpdateTask implements ModelUpdateTask {
|
||||
.map(it -> new PendingAddWidgetInfo(it.widgetInfo, CONTAINER_WIDGETS_PREDICTION,
|
||||
categoryProvider.getWidgetRecommendationCategory(context, it)))
|
||||
.collect(Collectors.toList());
|
||||
FixedContainerItems fixedContainerItems =
|
||||
new FixedContainerItems(mPredictorState.containerId, items);
|
||||
PredictedContainerInfo pci =
|
||||
new PredictedContainerInfo(mPredictorState.containerId, items);
|
||||
|
||||
dataModel.extraItems.put(mPredictorState.containerId, fixedContainerItems);
|
||||
taskController.bindExtraContainerItems(fixedContainerItems);
|
||||
dataModel.itemsIdMap.put(mPredictorState.containerId, pci);
|
||||
taskController.bindUpdatedWorkspaceItems(Collections.singleton(pci));
|
||||
|
||||
// Don't store widgets prediction to disk because it is not used frequently.
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ import android.window.DesktopExperienceFlags;
|
||||
|
||||
import com.android.launcher3.appprediction.AppsDividerView;
|
||||
import com.android.launcher3.appprediction.PredictionRowView;
|
||||
import com.android.launcher3.model.BgDataModel;
|
||||
import com.android.launcher3.model.data.PredictedContainerInfo;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
|
||||
/**
|
||||
@@ -48,10 +48,10 @@ public final class SecondaryDisplayQuickstepDelegateImpl extends SecondaryDispla
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPredictedApps(BgDataModel.FixedContainerItems item) {
|
||||
public void setPredictedApps(PredictedContainerInfo info) {
|
||||
mActivityContext.getAppsView().getFloatingHeaderView()
|
||||
.findFixedRowByType(PredictionRowView.class)
|
||||
.setPredictedApps(item.items);
|
||||
.setPredictedApps(info.getContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.android.launcher3.taskbar;
|
||||
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS_PREDICTION;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
|
||||
|
||||
@@ -28,10 +29,9 @@ import androidx.annotation.UiThread;
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.celllayout.CellInfo;
|
||||
import com.android.launcher3.model.BgDataModel;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.StringCache;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.PredictedContainerInfo;
|
||||
import com.android.launcher3.taskbar.TaskbarView.TaskbarLayoutParams;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
@@ -79,18 +79,14 @@ public class TaskbarModelCallbacks implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindCompleteModel(IntSparseArrayMap<ItemInfo> itemIdMap,
|
||||
List<FixedContainerItems> extraItems, StringCache stringCache, boolean isBindingSync) {
|
||||
public void bindCompleteModel(IntSparseArrayMap<ItemInfo> itemIdMap, boolean isBindingSync) {
|
||||
mHotseatItems.clear();
|
||||
mPredictedItems = Collections.emptyList();
|
||||
mPredictedItems = itemIdMap.get(CONTAINER_HOTSEAT_PREDICTION)
|
||||
instanceof PredictedContainerInfo pci ? pci.getContents() : Collections.emptyList();
|
||||
handleItemsAdded(itemIdMap);
|
||||
|
||||
for (FixedContainerItems item: extraItems) {
|
||||
if (item.containerId == Favorites.CONTAINER_HOTSEAT_PREDICTION) {
|
||||
mPredictedItems = item.items;
|
||||
} else if (item.containerId == Favorites.CONTAINER_ALL_APPS_PREDICTION) {
|
||||
mControllers.taskbarAllAppsController.setPredictedApps(item.items);
|
||||
}
|
||||
if (itemIdMap.get(CONTAINER_ALL_APPS_PREDICTION) instanceof PredictedContainerInfo pci) {
|
||||
mControllers.taskbarAllAppsController.setPredictedApps(pci.getContents());
|
||||
}
|
||||
commitItemsToUI();
|
||||
}
|
||||
@@ -114,12 +110,23 @@ public class TaskbarModelCallbacks implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindItemsUpdated(Set<ItemInfo> updates) {
|
||||
public void bindItemsUpdated(@NonNull Set<ItemInfo> updates) {
|
||||
Set<ItemInfo> itemsToRebind = updateContainerItems(updates, mContext);
|
||||
|
||||
boolean removed = handleItemsRemoved(ItemInfoMatcher.ofItems(itemsToRebind));
|
||||
boolean added = handleItemsAdded(itemsToRebind);
|
||||
if (removed || added) {
|
||||
|
||||
boolean predictionsUpdated = false;
|
||||
for (ItemInfo update: updates) {
|
||||
if (update instanceof PredictedContainerInfo pci) {
|
||||
if (pci.id == Favorites.CONTAINER_HOTSEAT_PREDICTION) {
|
||||
mPredictedItems = pci.getContents();
|
||||
predictionsUpdated = true;
|
||||
} else if (pci.id == CONTAINER_ALL_APPS_PREDICTION) {
|
||||
mControllers.taskbarAllAppsController.setPredictedApps(pci.getContents());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (removed || added || predictionsUpdated) {
|
||||
commitItemsToUI();
|
||||
}
|
||||
}
|
||||
@@ -165,16 +172,6 @@ public class TaskbarModelCallbacks implements
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindExtraContainerItems(FixedContainerItems item) {
|
||||
if (item.containerId == Favorites.CONTAINER_HOTSEAT_PREDICTION) {
|
||||
mPredictedItems = item.items;
|
||||
commitItemsToUI();
|
||||
} else if (item.containerId == Favorites.CONTAINER_ALL_APPS_PREDICTION) {
|
||||
mControllers.taskbarAllAppsController.setPredictedApps(item.items);
|
||||
}
|
||||
}
|
||||
|
||||
private void commitItemsToUI() {
|
||||
ItemInfo[] hotseatItemInfos =
|
||||
new ItemInfo[mContext.getDeviceProfile().numShownHotseatIcons];
|
||||
|
||||
@@ -133,9 +133,9 @@ import com.android.launcher3.hybridhotseat.HotseatPredictionController;
|
||||
import com.android.launcher3.logging.InstanceId;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.logging.StatsLogManager.StatsLogger;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.WellbeingModel;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.PredictedContainerInfo;
|
||||
import com.android.launcher3.popup.SystemShortcut;
|
||||
import com.android.launcher3.proxy.ProxyActivityStarter;
|
||||
import com.android.launcher3.statehandlers.DepthController;
|
||||
@@ -238,7 +238,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer,
|
||||
|
||||
protected static final String RING_APPEAR_ANIMATION_PREFIX = "RingAppearAnimation\t";
|
||||
|
||||
private FixedContainerItems mAllAppsPredictions;
|
||||
private PredictedContainerInfo mAllAppsPredictions;
|
||||
private HotseatPredictionController mHotseatPredictionController;
|
||||
private DepthController mDepthController;
|
||||
private QuickstepTransitionManager mAppTransitionManager;
|
||||
@@ -358,16 +358,16 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer,
|
||||
if (mAllAppsPredictions != null
|
||||
&& (info.itemType == ITEM_TYPE_APPLICATION
|
||||
|| info.itemType == ITEM_TYPE_DEEP_SHORTCUT)) {
|
||||
int count = mAllAppsPredictions.items.size();
|
||||
List<ItemInfo> items = mAllAppsPredictions.getContents();
|
||||
int count = items.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
ItemInfo targetInfo = mAllAppsPredictions.items.get(i);
|
||||
ItemInfo targetInfo = items.get(i);
|
||||
if (targetInfo.itemType == info.itemType
|
||||
&& targetInfo.user.equals(info.user)
|
||||
&& Objects.equals(targetInfo.getIntent(), info.getIntent())) {
|
||||
logger.withRank(i);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
logger.log(LAUNCHER_APP_LAUNCH_TAP);
|
||||
@@ -556,17 +556,20 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindExtraContainerItems(FixedContainerItems item) {
|
||||
if (item.containerId == Favorites.CONTAINER_ALL_APPS_PREDICTION) {
|
||||
mAllAppsPredictions = item;
|
||||
PredictionRowView<?> predictionRowView =
|
||||
getAppsView().getFloatingHeaderView().findFixedRowByType(
|
||||
PredictionRowView.class);
|
||||
predictionRowView.setPredictedApps(item.items);
|
||||
} else if (item.containerId == Favorites.CONTAINER_HOTSEAT_PREDICTION) {
|
||||
mHotseatPredictionController.setPredictedItems(item);
|
||||
} else if (item.containerId == Favorites.CONTAINER_WIDGETS_PREDICTION) {
|
||||
getWidgetPickerDataProvider().setWidgetRecommendations(item.items);
|
||||
public void bindPredictedContainerInfo(PredictedContainerInfo info) {
|
||||
super.bindPredictedContainerInfo(info);
|
||||
switch (info.id) {
|
||||
case Favorites.CONTAINER_ALL_APPS_PREDICTION:
|
||||
mAllAppsPredictions = info;
|
||||
getAppsView().getFloatingHeaderView().findFixedRowByType(
|
||||
PredictionRowView.class).setPredictedApps(info.getContents());
|
||||
break;
|
||||
case Favorites.CONTAINER_HOTSEAT_PREDICTION:
|
||||
mHotseatPredictionController.setPredictedItems(info);
|
||||
break;
|
||||
case Favorites.CONTAINER_WIDGETS_PREDICTION:
|
||||
getWidgetPickerDataProvider().setWidgetRecommendations(info.getContents());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user