Updating ItemInfoMatcher to work with java streams

Adding support for bulk removing items from a folder icon.
This fixes workspace item removal when a folder gets replaced
to an icon during the delete operation.

- Lets say user has a folder with the same app twice.
- User disables that app.
- Launcher removes all shorcuts of that app

However, because we call "replaceFolderWithFinalItem" during
this removal, we end up creating a new shortcut that does
not get tracked by the removal, so the user is left with
an enabled icon of the disabled app.

Bug: 162378169
Test: manual test, repo steps in bug
Change-Id: Iaf6550894c156b3b5ec2a5aa58bab76a4a28819e
This commit is contained in:
Sunny Goyal
2021-01-27 15:16:59 -08:00
parent f1db62cc98
commit bfc0c38157
6 changed files with 52 additions and 72 deletions
@@ -40,6 +40,8 @@ import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.util.ContentWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.IntStream;
@@ -137,9 +139,16 @@ public class FolderInfo extends ItemInfo {
* @param item
*/
public void remove(WorkspaceItemInfo item, boolean animate) {
contents.remove(item);
removeAll(Collections.singletonList(item), animate);
}
/**
* Remove all matching app or shortcut. Does not change the DB.
*/
public void removeAll(List<WorkspaceItemInfo> items, boolean animate) {
contents.removeAll(items);
for (int i = 0; i < mListeners.size(); i++) {
mListeners.get(i).onRemove(item);
mListeners.get(i).onRemove(items);
}
itemsChanged(animate);
}
@@ -166,9 +175,9 @@ public class FolderInfo extends ItemInfo {
}
public interface FolderListener {
public void onAdd(WorkspaceItemInfo item, int rank);
public void onRemove(WorkspaceItemInfo item);
public void onItemsChanged(boolean animate);
void onAdd(WorkspaceItemInfo item, int rank);
void onRemove(List<WorkspaceItemInfo> item);
void onItemsChanged(boolean animate);
}
public boolean hasOption(int optionFlag) {