mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-18 18:28:20 +00:00
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:
@@ -34,6 +34,8 @@ import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.ShortcutInfo;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.util.GridOccupancy;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -59,12 +61,12 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
Context context = app.getContext();
|
||||
|
||||
final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
|
||||
final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<>();
|
||||
final IntArray addedWorkspaceScreensFinal = new IntArray();
|
||||
|
||||
// Get the list of workspace screens. We need to append to this list and
|
||||
// can not use sBgWorkspaceScreens because loadWorkspace() may not have been
|
||||
// called.
|
||||
ArrayList<Long> workspaceScreens = LauncherModel.loadWorkspaceScreensDb(context);
|
||||
IntArray workspaceScreens = LauncherModel.loadWorkspaceScreensDb(context);
|
||||
synchronized(dataModel) {
|
||||
|
||||
List<ItemInfo> filteredItems = new ArrayList<>();
|
||||
@@ -90,10 +92,9 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
|
||||
for (ItemInfo item : filteredItems) {
|
||||
// Find appropriate space for the item.
|
||||
Pair<Long, int[]> coords = findSpaceForItem(app, dataModel, workspaceScreens,
|
||||
int[] coords = findSpaceForItem(app, dataModel, workspaceScreens,
|
||||
addedWorkspaceScreensFinal, item.spanX, item.spanY);
|
||||
long screenId = coords.first;
|
||||
int[] cordinates = coords.second;
|
||||
int screenId = coords[0];
|
||||
|
||||
ItemInfo itemInfo;
|
||||
if (item instanceof ShortcutInfo || item instanceof FolderInfo ||
|
||||
@@ -108,7 +109,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
// Add the shortcut to the db
|
||||
getModelWriter().addItemToDatabase(itemInfo,
|
||||
LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId,
|
||||
cordinates[0], cordinates[1]);
|
||||
coords[1], coords[2]);
|
||||
|
||||
// Save the ShortcutInfo for binding in the workspace
|
||||
addedItemsFinal.add(itemInfo);
|
||||
@@ -126,7 +127,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
final ArrayList<ItemInfo> addNotAnimated = new ArrayList<>();
|
||||
if (!addedItemsFinal.isEmpty()) {
|
||||
ItemInfo info = addedItemsFinal.get(addedItemsFinal.size() - 1);
|
||||
long lastScreenId = info.screenId;
|
||||
int lastScreenId = info.screenId;
|
||||
for (ItemInfo i : addedItemsFinal) {
|
||||
if (i.screenId == lastScreenId) {
|
||||
addAnimated.add(i);
|
||||
@@ -142,7 +143,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateScreens(Context context, ArrayList<Long> workspaceScreens) {
|
||||
protected void updateScreens(Context context, IntArray workspaceScreens) {
|
||||
LauncherModel.updateWorkspaceScreenOrder(context, workspaceScreens);
|
||||
}
|
||||
|
||||
@@ -204,13 +205,10 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
|
||||
/**
|
||||
* Find a position on the screen for the given size or adds a new screen.
|
||||
* @return screenId and the coordinates for the item.
|
||||
* @return screenId and the coordinates for the item in an int array of size 3.
|
||||
*/
|
||||
protected Pair<Long, int[]> findSpaceForItem(
|
||||
LauncherAppState app, BgDataModel dataModel,
|
||||
ArrayList<Long> workspaceScreens,
|
||||
ArrayList<Long> addedWorkspaceScreensFinal,
|
||||
int spanX, int spanY) {
|
||||
protected int[] findSpaceForItem( LauncherAppState app, BgDataModel dataModel,
|
||||
IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY) {
|
||||
LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
|
||||
|
||||
// Use sBgItemsIdMap as all the items are already loaded.
|
||||
@@ -228,7 +226,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
}
|
||||
|
||||
// Find appropriate space for the item.
|
||||
long screenId = 0;
|
||||
int screenId = 0;
|
||||
int[] cordinates = new int[2];
|
||||
boolean found = false;
|
||||
|
||||
@@ -258,7 +256,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
// Still no position found. Add a new screen to the end.
|
||||
screenId = LauncherSettings.Settings.call(app.getContext().getContentResolver(),
|
||||
LauncherSettings.Settings.METHOD_NEW_SCREEN_ID)
|
||||
.getLong(LauncherSettings.Settings.EXTRA_VALUE);
|
||||
.getInt(LauncherSettings.Settings.EXTRA_VALUE);
|
||||
|
||||
// Save the screen id for binding in the workspace
|
||||
workspaceScreens.add(screenId);
|
||||
@@ -270,7 +268,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
throw new RuntimeException("Can't find space to add the item");
|
||||
}
|
||||
}
|
||||
return Pair.create(screenId, cordinates);
|
||||
return new int[] {screenId, cordinates[0], cordinates[1]};
|
||||
}
|
||||
|
||||
private boolean findNextAvailableIconSpaceInScreen(
|
||||
|
||||
Reference in New Issue
Block a user