Converting long item IDs to int

> Items ids were already being typecasted to int when being bound on the UI
> Using a consistent type allow better use of platform data-structures
> Adding IntArray and IntSet as a replacement for various Collection classes

Change-Id: Id3c650ed2420c2bfca3bd7671d2b705b56112371
This commit is contained in:
Sunny Goyal
2018-10-04 15:11:00 -07:00
parent f307b6032e
commit efb7e84242
39 changed files with 756 additions and 403 deletions

View File

@@ -11,7 +11,6 @@ import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Point;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
@@ -27,7 +26,9 @@ import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSparseArrayMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -59,7 +60,7 @@ public class GridSizeMigrationTask {
private final InvariantDeviceProfile mIdp;
private final ContentValues mTempValues = new ContentValues();
protected final ArrayList<Long> mEntryToRemove = new ArrayList<>();
protected final IntArray mEntryToRemove = new IntArray();
private final ArrayList<ContentProviderOperation> mUpdateOperations = new ArrayList<>();
protected final ArrayList<DbEntry> mCarryOver = new ArrayList<>();
private final HashSet<String> mValidPackages;
@@ -118,7 +119,7 @@ public class GridSizeMigrationTask {
if (!mEntryToRemove.isEmpty()) {
if (DEBUG) {
Log.d(TAG, "Removing items: " + TextUtils.join(", ", mEntryToRemove));
Log.d(TAG, "Removing items: " + mEntryToRemove.toConcatString());
}
mContext.getContentResolver().delete(LauncherSettings.Favorites.CONTENT_URI,
Utilities.createDbSelectionQuery(
@@ -177,12 +178,13 @@ public class GridSizeMigrationTask {
* @return true if any DB change was made
*/
protected boolean migrateWorkspace() throws Exception {
ArrayList<Long> allScreens = LauncherModel.loadWorkspaceScreensDb(mContext);
IntArray allScreens = LauncherModel.loadWorkspaceScreensDb(mContext);
if (allScreens.isEmpty()) {
throw new Exception("Unable to get workspace screens");
}
for (long screenId : allScreens) {
for (int i = 0; i < allScreens.size(); i++) {
int screenId = allScreens.get(i);
if (DEBUG) {
Log.d(TAG, "Migrating " + screenId);
}
@@ -190,7 +192,7 @@ public class GridSizeMigrationTask {
}
if (!mCarryOver.isEmpty()) {
LongArrayMap<DbEntry> itemMap = new LongArrayMap<>();
IntSparseArrayMap<DbEntry> itemMap = new IntSparseArrayMap<>();
for (DbEntry e : mCarryOver) {
itemMap.put(e.id, e);
}
@@ -205,10 +207,10 @@ public class GridSizeMigrationTask {
new GridOccupancy(mTrgX, mTrgY), deepCopy(mCarryOver), 0, true);
placement.find();
if (placement.finalPlacedItems.size() > 0) {
long newScreenId = LauncherSettings.Settings.call(
int newScreenId = LauncherSettings.Settings.call(
mContext.getContentResolver(),
LauncherSettings.Settings.METHOD_NEW_SCREEN_ID)
.getLong(LauncherSettings.Settings.EXTRA_VALUE);
.getInt(LauncherSettings.Settings.EXTRA_VALUE);
allScreens.add(newScreenId);
for (DbEntry item : placement.finalPlacedItems) {
@@ -230,7 +232,7 @@ public class GridSizeMigrationTask {
int count = allScreens.size();
for (int i = 0; i < count; i++) {
ContentValues v = new ContentValues();
long screenId = allScreens.get(i);
int screenId = allScreens.get(i);
v.put(LauncherSettings.WorkspaceScreens._ID, screenId);
v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
mUpdateOperations.add(ContentProviderOperation.newInsert(uri).withValues(v).build());
@@ -249,7 +251,7 @@ public class GridSizeMigrationTask {
* 3) If all those items from the above list can be placed on this screen, place them
* (otherwise they are placed on a new screen).
*/
protected void migrateScreen(long screenId) {
protected void migrateScreen(int screenId) {
// If we are migrating the first screen, do not touch the first row.
int startY =
(FeatureFlags.getInstance(mContext).isQsbOnFirstScreenEnabled()
@@ -304,7 +306,7 @@ public class GridSizeMigrationTask {
removedRow, removedCol, screenId));
}
LongArrayMap<DbEntry> itemMap = new LongArrayMap<>();
IntSparseArrayMap<DbEntry> itemMap = new IntSparseArrayMap<>();
for (DbEntry e : deepCopy(items)) {
itemMap.put(e.id, e);
}
@@ -615,9 +617,9 @@ public class GridSizeMigrationTask {
ArrayList<DbEntry> entries = new ArrayList<>();
while (c.moveToNext()) {
DbEntry entry = new DbEntry();
entry.id = c.getLong(indexId);
entry.id = c.getInt(indexId);
entry.itemType = c.getInt(indexItemType);
entry.screenId = c.getLong(indexScreen);
entry.screenId = c.getInt(indexScreen);
if (entry.screenId >= mSrcHotseatSize) {
mEntryToRemove.add(entry.id);
@@ -663,7 +665,7 @@ public class GridSizeMigrationTask {
/**
* Loads entries for a particular screen id.
*/
protected ArrayList<DbEntry> loadWorkspaceEntries(long screen) {
protected ArrayList<DbEntry> loadWorkspaceEntries(int screen) {
Cursor c = queryWorkspace(
new String[]{
Favorites._ID, // 0
@@ -691,7 +693,7 @@ public class GridSizeMigrationTask {
ArrayList<DbEntry> entries = new ArrayList<>();
while (c.moveToNext()) {
DbEntry entry = new DbEntry();
entry.id = c.getLong(indexId);
entry.id = c.getInt(indexId);
entry.itemType = c.getInt(indexItemType);
entry.cellX = c.getInt(indexCellX);
entry.cellY = c.getInt(indexCellY);
@@ -764,7 +766,7 @@ public class GridSizeMigrationTask {
/**
* @return the number of valid items in the folder.
*/
private int getFolderItemsCount(long folderId) {
private int getFolderItemsCount(int folderId) {
Cursor c = queryWorkspace(
new String[]{Favorites._ID, Favorites.INTENT},
Favorites.CONTAINER + " = " + folderId);
@@ -775,7 +777,7 @@ public class GridSizeMigrationTask {
verifyIntent(c.getString(1));
total++;
} catch (Exception e) {
mEntryToRemove.add(c.getLong(0));
mEntryToRemove.add(c.getInt(0));
}
}
c.close();
@@ -970,7 +972,7 @@ public class GridSizeMigrationTask {
* Removes any broken item from the hotseat.
* @return a map with occupied hotseat position set to non-null value.
*/
public static LongArrayMap<Object> removeBrokenHotseatItems(Context context) throws Exception {
public static IntSparseArrayMap<Object> removeBrokenHotseatItems(Context context) throws Exception {
GridSizeMigrationTask task = new GridSizeMigrationTask(
context, LauncherAppState.getIDP(context), getValidPackages(context),
Integer.MAX_VALUE, Integer.MAX_VALUE);
@@ -979,7 +981,7 @@ public class GridSizeMigrationTask {
ArrayList<DbEntry> items = task.loadHotseatEntries();
// Delete any entry marked for deletion by above load.
task.applyOperations();
LongArrayMap<Object> positions = new LongArrayMap<>();
IntSparseArrayMap<Object> positions = new IntSparseArrayMap<>();
for (DbEntry item : items) {
positions.put(item.screenId, item);
}