Fixing duplicate/inconsistent definitions for model and callbacks
> 2 implementations for filtering workspace items > 2 implementations for binding widgets > duplicate logic for add and update appInfo Change-Id: Id68a49926af398478deca8ac85ab1f22341a9449
This commit is contained in:
@@ -3249,13 +3249,13 @@ public class Launcher extends BaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindAppsAdded(final ArrayList<Long> newScreens,
|
||||
final ArrayList<ItemInfo> addNotAnimated,
|
||||
final ArrayList<ItemInfo> addAnimated,
|
||||
final ArrayList<AppInfo> addedApps) {
|
||||
final ArrayList<ItemInfo> addAnimated) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
|
||||
bindAppsAdded(newScreens, addNotAnimated, addAnimated);
|
||||
}
|
||||
};
|
||||
if (waitUntilResume(r)) {
|
||||
@@ -3270,20 +3270,14 @@ public class Launcher extends BaseActivity
|
||||
// We add the items without animation on non-visible pages, and with
|
||||
// animations on the new page (which we will try and snap to).
|
||||
if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
|
||||
bindItems(addNotAnimated, 0,
|
||||
addNotAnimated.size(), false);
|
||||
bindItems(addNotAnimated, false);
|
||||
}
|
||||
if (addAnimated != null && !addAnimated.isEmpty()) {
|
||||
bindItems(addAnimated, 0,
|
||||
addAnimated.size(), true);
|
||||
bindItems(addAnimated, true);
|
||||
}
|
||||
|
||||
// Remove the extra empty screen
|
||||
mWorkspace.removeExtraEmptyScreen(false, false);
|
||||
|
||||
if (addedApps != null && mAppsView != null) {
|
||||
mAppsView.addApps(addedApps);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3292,11 +3286,10 @@ public class Launcher extends BaseActivity
|
||||
* Implementation of the method from LauncherModel.Callbacks.
|
||||
*/
|
||||
@Override
|
||||
public void bindItems(final ArrayList<ItemInfo> items, final int start, final int end,
|
||||
final boolean forceAnimateIcons) {
|
||||
public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
bindItems(items, start, end, forceAnimateIcons);
|
||||
bindItems(items, forceAnimateIcons);
|
||||
}
|
||||
};
|
||||
if (waitUntilResume(r)) {
|
||||
@@ -3309,7 +3302,8 @@ public class Launcher extends BaseActivity
|
||||
final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
|
||||
Workspace workspace = mWorkspace;
|
||||
long newItemsScreenId = -1;
|
||||
for (int i = start; i < end; i++) {
|
||||
int end = items.size();
|
||||
for (int i = 0; i < end; i++) {
|
||||
final ItemInfo item = items.get(i);
|
||||
|
||||
// Short circuit if we are loading dock items for a configuration which has no dock
|
||||
@@ -3334,19 +3328,10 @@ public class Launcher extends BaseActivity
|
||||
break;
|
||||
}
|
||||
case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: {
|
||||
LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
|
||||
if (mIsSafeModeEnabled) {
|
||||
view = new PendingAppWidgetHostView(this, info, mIconCache, true);
|
||||
} else {
|
||||
LauncherAppWidgetProviderInfo providerInfo =
|
||||
mAppWidgetManager.getLauncherAppWidgetInfo(info.appWidgetId);
|
||||
if (providerInfo == null) {
|
||||
deleteWidgetInfo(info);
|
||||
continue;
|
||||
}
|
||||
view = mAppWidgetHost.createView(this, info.appWidgetId, providerInfo);
|
||||
view = bindAppWidget((LauncherAppWidgetInfo) item);
|
||||
if (view == null) {
|
||||
continue;
|
||||
}
|
||||
prepareAppWidget((AppWidgetHostView) view, info);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -3416,26 +3401,15 @@ public class Launcher extends BaseActivity
|
||||
|
||||
/**
|
||||
* Add the views for a widget to the workspace.
|
||||
*
|
||||
* Implementation of the method from LauncherModel.Callbacks.
|
||||
*/
|
||||
public void bindAppWidget(final LauncherAppWidgetInfo item) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
bindAppWidget(item);
|
||||
}
|
||||
};
|
||||
if (waitUntilResume(r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
public View bindAppWidget(LauncherAppWidgetInfo item) {
|
||||
if (mIsSafeModeEnabled) {
|
||||
PendingAppWidgetHostView view =
|
||||
new PendingAppWidgetHostView(this, item, mIconCache, true);
|
||||
prepareAppWidget(view, item);
|
||||
mWorkspace.addInScreen(view, item);
|
||||
mWorkspace.requestLayout();
|
||||
return;
|
||||
return view;
|
||||
}
|
||||
|
||||
final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
|
||||
@@ -3465,7 +3439,7 @@ public class Launcher extends BaseActivity
|
||||
+ ", as the provider is null");
|
||||
}
|
||||
getModelWriter().deleteItemFromDatabase(item);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// If we do not have a valid id, try to bind an id.
|
||||
@@ -3533,7 +3507,7 @@ public class Launcher extends BaseActivity
|
||||
if (appWidgetInfo == null) {
|
||||
FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
|
||||
deleteWidgetInfo(item);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
item.minSpanX = appWidgetInfo.minSpanX;
|
||||
@@ -3550,6 +3524,7 @@ public class Launcher extends BaseActivity
|
||||
Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
|
||||
+ (SystemClock.uptimeMillis()-start) + "ms");
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3744,10 +3719,10 @@ public class Launcher extends BaseActivity
|
||||
*
|
||||
* Implementation of the method from LauncherModel.Callbacks.
|
||||
*/
|
||||
public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
|
||||
public void bindAppsAddedOrUpdated(final ArrayList<AppInfo> apps) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
bindAppsUpdated(apps);
|
||||
bindAppsAddedOrUpdated(apps);
|
||||
}
|
||||
};
|
||||
if (waitUntilResume(r)) {
|
||||
@@ -3755,7 +3730,7 @@ public class Launcher extends BaseActivity
|
||||
}
|
||||
|
||||
if (mAppsView != null) {
|
||||
mAppsView.updateApps(apps);
|
||||
mAppsView.addOrUpdateApps(apps);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,18 +138,15 @@ public class LauncherModel extends BroadcastReceiver
|
||||
public int getCurrentWorkspaceScreen();
|
||||
public void clearPendingBinds();
|
||||
public void startBinding();
|
||||
public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end,
|
||||
boolean forceAnimateIcons);
|
||||
public void bindItems(List<ItemInfo> shortcuts, boolean forceAnimateIcons);
|
||||
public void bindScreens(ArrayList<Long> orderedScreenIds);
|
||||
public void finishFirstPageBind(ViewOnDrawExecutor executor);
|
||||
public void finishBindingItems();
|
||||
public void bindAppWidget(LauncherAppWidgetInfo info);
|
||||
public void bindAllApplications(ArrayList<AppInfo> apps);
|
||||
public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps);
|
||||
public void bindAppsAdded(ArrayList<Long> newScreens,
|
||||
ArrayList<ItemInfo> addNotAnimated,
|
||||
ArrayList<ItemInfo> addAnimated,
|
||||
ArrayList<AppInfo> addedApps);
|
||||
public void bindAppsUpdated(ArrayList<AppInfo> apps);
|
||||
ArrayList<ItemInfo> addAnimated);
|
||||
public void bindPromiseAppProgressUpdated(PromiseAppInfo app);
|
||||
public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated,
|
||||
ArrayList<ShortcutInfo> removed, UserHandle user);
|
||||
@@ -537,7 +534,7 @@ public class LauncherModel extends BroadcastReceiver
|
||||
scheduleCallbackTask(new CallbackTask() {
|
||||
@Override
|
||||
public void execute(Callbacks callbacks) {
|
||||
callbacks.bindAppsAdded(null, null, null, arrayList);
|
||||
callbacks.bindAppsAddedOrUpdated(arrayList);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
|
||||
|
||||
ArrayList<ItemInfo> itemList = new ArrayList<>();
|
||||
itemList.add(info);
|
||||
mLauncher.bindItems(itemList, 0, itemList.size(), true);
|
||||
mLauncher.bindItems(itemList, true);
|
||||
} else if (item instanceof PendingAddItemInfo) {
|
||||
PendingAddItemInfo info = (PendingAddItemInfo) item;
|
||||
Workspace workspace = mLauncher.getWorkspace();
|
||||
@@ -205,7 +205,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
|
||||
public void run() {
|
||||
ArrayList<ItemInfo> itemList = new ArrayList<>();
|
||||
itemList.add(item);
|
||||
mLauncher.bindItems(itemList, 0, itemList.size(), true);
|
||||
mLauncher.bindItems(itemList, true);
|
||||
announceConfirmation(R.string.item_moved);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ShortcutMenuAccessibilityDelegate extends LauncherAccessibilityDele
|
||||
screenId, coordinates[0], coordinates[1]);
|
||||
ArrayList<ItemInfo> itemList = new ArrayList<>();
|
||||
itemList.add(info);
|
||||
mLauncher.bindItems(itemList, 0, itemList.size(), true);
|
||||
mLauncher.bindItems(itemList, true);
|
||||
AbstractFloatingView.closeAllOpenViews(mLauncher);
|
||||
announceConfirmation(R.string.item_added_to_workspace);
|
||||
}
|
||||
|
||||
@@ -132,18 +132,10 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new apps to the list.
|
||||
* Adds or updates existing apps in the list
|
||||
*/
|
||||
public void addApps(List<AppInfo> apps) {
|
||||
mApps.addApps(apps);
|
||||
mSearchUiManager.refreshSearchResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates existing apps in the list
|
||||
*/
|
||||
public void updateApps(List<AppInfo> apps) {
|
||||
mApps.updateApps(apps);
|
||||
public void addOrUpdateApps(List<AppInfo> apps) {
|
||||
mApps.addOrUpdateApps(apps);
|
||||
mSearchUiManager.refreshSearchResult();
|
||||
}
|
||||
|
||||
|
||||
@@ -374,20 +374,13 @@ public class AlphabeticalAppsList {
|
||||
*/
|
||||
public void setApps(List<AppInfo> apps) {
|
||||
mComponentToAppMap.clear();
|
||||
addApps(apps);
|
||||
addOrUpdateApps(apps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new apps to the list.
|
||||
* Adds or updates existing apps in the list
|
||||
*/
|
||||
public void addApps(List<AppInfo> apps) {
|
||||
updateApps(apps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates existing apps in the list
|
||||
*/
|
||||
public void updateApps(List<AppInfo> apps) {
|
||||
public void addOrUpdateApps(List<AppInfo> apps) {
|
||||
for (AppInfo app : apps) {
|
||||
mComponentToAppMap.put(app.toComponentKey(), app);
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
|
||||
}
|
||||
}
|
||||
callbacks.bindAppsAdded(addedWorkspaceScreensFinal,
|
||||
addNotAnimated, addAnimated, null);
|
||||
addNotAnimated, addAnimated);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class CacheDataUpdatedTask extends BaseModelUpdateTask {
|
||||
scheduleCallbackTask(new CallbackTask() {
|
||||
@Override
|
||||
public void execute(Callbacks callbacks) {
|
||||
callbacks.bindAppsUpdated(updatedApps);
|
||||
callbacks.bindAppsAddedOrUpdated(updatedApps);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class LoaderResults {
|
||||
|
||||
filterCurrentWorkspaceItems(currentScreenId, workspaceItems, currentWorkspaceItems,
|
||||
otherWorkspaceItems);
|
||||
filterCurrentAppWidgets(currentScreenId, appWidgets, currentAppWidgets,
|
||||
filterCurrentWorkspaceItems(currentScreenId, appWidgets, currentAppWidgets,
|
||||
otherAppWidgets);
|
||||
sortWorkspaceItemsSpatially(currentWorkspaceItems);
|
||||
sortWorkspaceItemsSpatially(otherWorkspaceItems);
|
||||
@@ -208,12 +208,12 @@ public class LoaderResults {
|
||||
|
||||
/** Filters the set of items who are directly or indirectly (via another container) on the
|
||||
* specified screen. */
|
||||
private void filterCurrentWorkspaceItems(long currentScreenId,
|
||||
ArrayList<ItemInfo> allWorkspaceItems,
|
||||
ArrayList<ItemInfo> currentScreenItems,
|
||||
ArrayList<ItemInfo> otherScreenItems) {
|
||||
private <T extends ItemInfo> void filterCurrentWorkspaceItems(long currentScreenId,
|
||||
ArrayList<T> allWorkspaceItems,
|
||||
ArrayList<T> currentScreenItems,
|
||||
ArrayList<T> otherScreenItems) {
|
||||
// Purge any null ItemInfos
|
||||
Iterator<ItemInfo> iter = allWorkspaceItems.iterator();
|
||||
Iterator<T> iter = allWorkspaceItems.iterator();
|
||||
while (iter.hasNext()) {
|
||||
ItemInfo i = iter.next();
|
||||
if (i == null) {
|
||||
@@ -224,14 +224,14 @@ public class LoaderResults {
|
||||
// Order the set of items by their containers first, this allows use to walk through the
|
||||
// list sequentially, build up a list of containers that are in the specified screen,
|
||||
// as well as all items in those containers.
|
||||
Set<Long> itemsOnScreen = new HashSet<Long>();
|
||||
Set<Long> itemsOnScreen = new HashSet<>();
|
||||
Collections.sort(allWorkspaceItems, new Comparator<ItemInfo>() {
|
||||
@Override
|
||||
public int compare(ItemInfo lhs, ItemInfo rhs) {
|
||||
return Utilities.longCompare(lhs.container, rhs.container);
|
||||
}
|
||||
});
|
||||
for (ItemInfo info : allWorkspaceItems) {
|
||||
for (T info : allWorkspaceItems) {
|
||||
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
|
||||
if (info.screenId == currentScreenId) {
|
||||
currentScreenItems.add(info);
|
||||
@@ -253,23 +253,6 @@ public class LoaderResults {
|
||||
}
|
||||
}
|
||||
|
||||
/** Filters the set of widgets which are on the specified screen. */
|
||||
private void filterCurrentAppWidgets(long currentScreenId,
|
||||
ArrayList<LauncherAppWidgetInfo> appWidgets,
|
||||
ArrayList<LauncherAppWidgetInfo> currentScreenWidgets,
|
||||
ArrayList<LauncherAppWidgetInfo> otherScreenWidgets) {
|
||||
|
||||
for (LauncherAppWidgetInfo widget : appWidgets) {
|
||||
if (widget == null) continue;
|
||||
if (widget.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
|
||||
widget.screenId == currentScreenId) {
|
||||
currentScreenWidgets.add(widget);
|
||||
} else {
|
||||
otherScreenWidgets.add(widget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to
|
||||
* right) */
|
||||
private void sortWorkspaceItemsSpatially(ArrayList<ItemInfo> workspaceItems) {
|
||||
@@ -322,7 +305,7 @@ public class LoaderResults {
|
||||
public void run() {
|
||||
Callbacks callbacks = mCallbacks.get();
|
||||
if (callbacks != null) {
|
||||
callbacks.bindItems(workspaceItems, start, start+chunkSize, false);
|
||||
callbacks.bindItems(workspaceItems.subList(start, start+chunkSize), false);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -332,12 +315,12 @@ public class LoaderResults {
|
||||
// Bind the widgets, one at a time
|
||||
N = appWidgets.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
final LauncherAppWidgetInfo widget = appWidgets.get(i);
|
||||
final ItemInfo widget = appWidgets.get(i);
|
||||
final Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
Callbacks callbacks = mCallbacks.get();
|
||||
if (callbacks != null) {
|
||||
callbacks.bindAppWidget(widget);
|
||||
callbacks.bindItems(Collections.singletonList(widget), false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -147,51 +147,28 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
||||
break;
|
||||
}
|
||||
|
||||
ArrayList<AppInfo> added = null;
|
||||
ArrayList<AppInfo> modified = null;
|
||||
final ArrayList<AppInfo> removedApps = new ArrayList<>();
|
||||
final ArrayList<AppInfo> addedOrModified = new ArrayList<>();
|
||||
addedOrModified.addAll(appsList.added);
|
||||
appsList.added.clear();
|
||||
addedOrModified.addAll(appsList.modified);
|
||||
appsList.modified.clear();
|
||||
|
||||
if (appsList.added.size() > 0) {
|
||||
added = new ArrayList<>(appsList.added);
|
||||
appsList.added.clear();
|
||||
}
|
||||
if (appsList.modified.size() > 0) {
|
||||
modified = new ArrayList<>(appsList.modified);
|
||||
appsList.modified.clear();
|
||||
}
|
||||
if (appsList.removed.size() > 0) {
|
||||
removedApps.addAll(appsList.removed);
|
||||
appsList.removed.clear();
|
||||
}
|
||||
final ArrayList<AppInfo> removedApps = new ArrayList<>(appsList.removed);
|
||||
appsList.removed.clear();
|
||||
|
||||
final ArrayMap<ComponentName, AppInfo> addedOrUpdatedApps = new ArrayMap<>();
|
||||
|
||||
if (added != null) {
|
||||
final ArrayList<AppInfo> addedApps = added;
|
||||
if (!addedOrModified.isEmpty()) {
|
||||
scheduleCallbackTask(new CallbackTask() {
|
||||
@Override
|
||||
public void execute(Callbacks callbacks) {
|
||||
callbacks.bindAppsAdded(null, null, null, addedApps);
|
||||
callbacks.bindAppsAddedOrUpdated(addedOrModified);
|
||||
}
|
||||
});
|
||||
for (AppInfo ai : added) {
|
||||
for (AppInfo ai : addedOrModified) {
|
||||
addedOrUpdatedApps.put(ai.componentName, ai);
|
||||
}
|
||||
}
|
||||
|
||||
if (modified != null) {
|
||||
final ArrayList<AppInfo> modifiedFinal = modified;
|
||||
for (AppInfo ai : modified) {
|
||||
addedOrUpdatedApps.put(ai.componentName, ai);
|
||||
}
|
||||
scheduleCallbackTask(new CallbackTask() {
|
||||
@Override
|
||||
public void execute(Callbacks callbacks) {
|
||||
callbacks.bindAppsUpdated(modifiedFinal);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Update shortcut infos
|
||||
if (mOp == OP_ADD || flagOp != FlagOp.NO_OP) {
|
||||
final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<>();
|
||||
|
||||
@@ -131,7 +131,7 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase {
|
||||
// only info2 should be added because info was already added to the workspace
|
||||
// in setupWorkspaceWithHoles()
|
||||
verify(callbacks).bindAppsAdded(any(ArrayList.class), notAnimated.capture(),
|
||||
animated.capture(), isNull(ArrayList.class));
|
||||
animated.capture());
|
||||
assertTrue(notAnimated.getValue().isEmpty());
|
||||
|
||||
assertEquals(1, animated.getValue().size());
|
||||
|
||||
Reference in New Issue
Block a user