mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Synchronizing model data access
Test: Presubmit Bug: 173328873 Change-Id: Ifc1724e17ebfa2ee5f21bb3f272986b8a14fdbc1
This commit is contained in:
@@ -52,8 +52,7 @@ public class HotseatPredictionModel {
|
||||
public static Bundle convertDataModelToAppTargetBundle(Context context, BgDataModel dataModel) {
|
||||
Bundle bundle = new Bundle();
|
||||
ArrayList<AppTargetEvent> events = new ArrayList<>();
|
||||
ArrayList<ItemInfo> workspaceItems = new ArrayList<>(dataModel.workspaceItems);
|
||||
workspaceItems.addAll(dataModel.appWidgets);
|
||||
ArrayList<ItemInfo> workspaceItems = dataModel.getAllWorkspaceItems();
|
||||
for (ItemInfo item : workspaceItems) {
|
||||
AppTarget target = getAppTargetFromInfo(context, item);
|
||||
if (target != null && !isTrackedForPrediction(item)) continue;
|
||||
|
||||
@@ -629,11 +629,13 @@ public class LauncherPreviewRenderer extends ContextThemeWrapper
|
||||
private WorkspaceResult(BgDataModel dataModel,
|
||||
WidgetsModel widgetsModel,
|
||||
Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
|
||||
mWorkspaceItems = dataModel.workspaceItems;
|
||||
mAppWidgets = dataModel.appWidgets;
|
||||
mHotseatPredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
|
||||
mWidgetsModel = widgetsModel;
|
||||
mWidgetProvidersMap = widgetProviderInfoMap;
|
||||
synchronized (dataModel) {
|
||||
mWorkspaceItems = dataModel.workspaceItems;
|
||||
mAppWidgets = dataModel.appWidgets;
|
||||
mHotseatPredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
|
||||
mWidgetsModel = widgetsModel;
|
||||
mWidgetProvidersMap = widgetProviderInfoMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,6 +375,16 @@ public class BgDataModel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all workspace items including widgets.
|
||||
*/
|
||||
public synchronized ArrayList<ItemInfo> getAllWorkspaceItems() {
|
||||
ArrayList<ItemInfo> items = new ArrayList<>(workspaceItems.size() + appWidgets.size());
|
||||
items.addAll(workspaceItems);
|
||||
items.addAll(appWidgets);
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the provided {@code op} for all workspaceItems in the in-memory model (both persisted
|
||||
* items and dynamic/predicted items for the provided {@code userHandle}.
|
||||
|
||||
@@ -166,12 +166,7 @@ public class LoaderTask implements Runnable {
|
||||
|
||||
private void sendFirstScreenActiveInstallsBroadcast() {
|
||||
ArrayList<ItemInfo> firstScreenItems = new ArrayList<>();
|
||||
|
||||
ArrayList<ItemInfo> allItems = new ArrayList<>();
|
||||
synchronized (mBgDataModel) {
|
||||
allItems.addAll(mBgDataModel.workspaceItems);
|
||||
allItems.addAll(mBgDataModel.appWidgets);
|
||||
}
|
||||
ArrayList<ItemInfo> allItems = mBgDataModel.getAllWorkspaceItems();
|
||||
// Screen set is never empty
|
||||
final int firstScreen = mBgDataModel.collectWorkspaceScreens().get(0);
|
||||
|
||||
@@ -858,10 +853,12 @@ public class LoaderTask implements Runnable {
|
||||
.call(contentResolver,
|
||||
LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS)
|
||||
.getIntArray(LauncherSettings.Settings.EXTRA_VALUE);
|
||||
for (int folderId : deletedFolderIds) {
|
||||
mBgDataModel.workspaceItems.remove(mBgDataModel.folders.get(folderId));
|
||||
mBgDataModel.folders.remove(folderId);
|
||||
mBgDataModel.itemsIdMap.remove(folderId);
|
||||
synchronized (mBgDataModel) {
|
||||
for (int folderId : deletedFolderIds) {
|
||||
mBgDataModel.workspaceItems.remove(mBgDataModel.folders.get(folderId));
|
||||
mBgDataModel.folders.remove(folderId);
|
||||
mBgDataModel.itemsIdMap.remove(folderId);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any ghost widgets
|
||||
|
||||
Reference in New Issue
Block a user