mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-28 07:46:55 +00:00
Merge "Widget migration now supports widgets and repeated elements in the worskpace." into tm-qpr-dev am: ce213d3306
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/18442023 Change-Id: Iab4b26b486e157e9a1ddfb1adaf82ba2b3e8da34 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -56,6 +56,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This class takes care of shrinking the workspace (by maximum of one row and one column), as a
|
||||
@@ -267,38 +268,33 @@ public class GridSizeMigrationTaskV2 {
|
||||
|
||||
/** Return what's in the src but not in the dest */
|
||||
private static List<DbEntry> calcDiff(List<DbEntry> src, List<DbEntry> dest) {
|
||||
Set<String> destIntentSet = new HashSet<>();
|
||||
Set<Map<String, Integer>> destFolderIntentSet = new HashSet<>();
|
||||
Map<String, Integer> destIdSet = new HashMap<>();
|
||||
for (DbEntry entry : dest) {
|
||||
if (entry.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
|
||||
destFolderIntentSet.add(getFolderIntents(entry));
|
||||
String entryID = entry.getEntryMigrationId();
|
||||
if (destIdSet.containsKey(entryID)) {
|
||||
destIdSet.put(entryID, destIdSet.get(entryID) + 1);
|
||||
} else {
|
||||
destIntentSet.add(entry.mIntent);
|
||||
destIdSet.put(entryID, 1);
|
||||
}
|
||||
}
|
||||
List<DbEntry> diff = new ArrayList<>();
|
||||
for (DbEntry entry : src) {
|
||||
if (entry.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
|
||||
if (!destFolderIntentSet.contains(getFolderIntents(entry))) {
|
||||
String entryID = entry.getEntryMigrationId();
|
||||
if (destIdSet.containsKey(entryID)) {
|
||||
Integer count = destIdSet.get(entryID);
|
||||
if (count <= 0) {
|
||||
diff.add(entry);
|
||||
destIdSet.remove(entryID);
|
||||
} else {
|
||||
destIdSet.put(entryID, count - 1);
|
||||
}
|
||||
} else {
|
||||
if (!destIntentSet.contains(entry.mIntent)) {
|
||||
diff.add(entry);
|
||||
}
|
||||
diff.add(entry);
|
||||
}
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
private static Map<String, Integer> getFolderIntents(DbEntry entry) {
|
||||
Map<String, Integer> folder = new HashMap<>();
|
||||
for (String intent : entry.mFolderItems.keySet()) {
|
||||
folder.put(intent, entry.mFolderItems.get(intent).size());
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
||||
private static void insertEntryInDb(SQLiteDatabase db, Context context, DbEntry entry,
|
||||
String srcTableName, String destTableName) {
|
||||
int id = copyEntryAndUpdate(db, context, entry, srcTableName, destTableName);
|
||||
@@ -780,5 +776,31 @@ public class GridSizeMigrationTaskV2 {
|
||||
values.put(LauncherSettings.Favorites.SPANX, spanX);
|
||||
values.put(LauncherSettings.Favorites.SPANY, spanY);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should return an id that should be the same for two folders containing the
|
||||
* same elements.
|
||||
*/
|
||||
private String getFolderMigrationId() {
|
||||
return mFolderItems.keySet().stream()
|
||||
.map(intentString -> mFolderItems.get(intentString).size() + intentString)
|
||||
.sorted()
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/** This id is not used in the DB is only used while doing the migration and it identifies
|
||||
* an entry on each workspace. For example two calculator icons would have the same
|
||||
* migration id even thought they have different database ids.
|
||||
*/
|
||||
public String getEntryMigrationId() {
|
||||
switch (itemType) {
|
||||
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
|
||||
return getFolderMigrationId();
|
||||
case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
|
||||
return mProvider;
|
||||
default:
|
||||
return mIntent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user