Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32084d49 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Replacing ItemInfoMatcher with predicate

This removed unnecessary componentName lookups when it
is not required. Many checks just rely on IDs and
userHandle

Bug: 231153610
Test: Presubmit
Change-Id: Ief93954abc5861062a9f55dc2ef181d3de106c62
parent 34f51fbf
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -55,13 +55,13 @@ import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.uioverrides.PredictedAppIcon;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.OnboardingPrefs;
import com.android.launcher3.views.Snackbar;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
@@ -480,8 +480,8 @@ public class HotseatPredictionController implements DragController.DragListener,
     *
     * @param matcher filter matching items that have been removed
     */
    public void onModelItemsRemoved(ItemInfoMatcher matcher) {
        if (mPredictedItems.removeIf(matcher::matchesInfo)) {
    public void onModelItemsRemoved(Predicate<ItemInfo> matcher) {
        if (mPredictedItems.removeIf(matcher)) {
            fillGapsWithPrediction(true);
        }
    }
+3 −2
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import com.android.systemui.shared.recents.model.Task;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Predicate;

/**
 * Handles long click on Taskbar items to start a system drag and drop operation.
@@ -439,12 +440,12 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
                target = taskbarViewController.getAllAppsButtonView();
            } else if (item.container >= 0) {
                // Since folders close when the drag starts, target the folder icon instead.
                ItemInfoMatcher matcher = ItemInfoMatcher.forFolderMatch(
                Predicate<ItemInfo> matcher = ItemInfoMatcher.forFolderMatch(
                        ItemInfoMatcher.ofItemIds(IntSet.wrap(item.id)));
                target = taskbarViewController.getFirstIconMatch(matcher);
            } else if (item.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
                // Find first icon with same package/user as the deep shortcut.
                ItemInfoMatcher packageUserMatcher = ItemInfoMatcher.ofPackages(
                Predicate<ItemInfo> packageUserMatcher = ItemInfoMatcher.ofPackages(
                        Collections.singleton(item.getTargetPackage()), item.user);
                target = taskbarViewController.getFirstIconMatch(packageUserMatcher);
            }
+4 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.function.Predicate;

/**
 * Launcher model Callbacks for rendering taskbar.
@@ -126,16 +127,16 @@ public class TaskbarModelCallbacks implements
    }

    @Override
    public void bindWorkspaceComponentsRemoved(ItemInfoMatcher matcher) {
    public void bindWorkspaceComponentsRemoved(Predicate<ItemInfo> matcher) {
        if (handleItemsRemoved(matcher)) {
            commitItemsToUI();
        }
    }

    private boolean handleItemsRemoved(ItemInfoMatcher matcher) {
    private boolean handleItemsRemoved(Predicate<ItemInfo> matcher) {
        boolean modified = false;
        for (int i = mHotseatItems.size() - 1; i >= 0; i--) {
            if (matcher.matchesInfo(mHotseatItems.valueAt(i))) {
            if (matcher.test(mHotseatItems.valueAt(i))) {
                modified = true;
                mHotseatItems.removeAt(i);
            }
+5 −4
Original line number Diff line number Diff line
@@ -41,12 +41,13 @@ import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.uioverrides.ApiWrapper;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LauncherBindableItemsContainer;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.AllAppsButton;
import com.android.launcher3.views.DoubleShadowBubbleTextView;

import java.util.function.Predicate;

/**
 * Hosts the Taskbar content such as Hotseat and Recent Apps. Drawn on top of other apps.
 */
@@ -424,8 +425,8 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
     * Finds the first icon to match one of the given matchers, from highest to lowest priority.
     * @return The first match, or All Apps button if no match was found.
     */
    public View getFirstMatch(ItemInfoMatcher... matchers) {
        for (ItemInfoMatcher matcher : matchers) {
    public View getFirstMatch(Predicate<ItemInfo>... matchers) {
        for (Predicate<ItemInfo> matcher : matchers) {
            for (int i = 0; i < getChildCount(); i++) {
                View item = getChildAt(i);
                if (!(item.getTag() instanceof ItemInfo)) {
@@ -433,7 +434,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
                    continue;
                }
                ItemInfo info = (ItemInfo) item.getTag();
                if (matcher.matchesInfo(info)) {
                if (matcher.test(info)) {
                    return item;
                }
            }
+3 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.launcher3.util.MultiValueAlpha;
import com.android.quickstep.AnimatedFloat;

import java.io.PrintWriter;
import java.util.function.Predicate;

/**
 * Handles properties/data collection, then passes the results to TaskbarView to render.
@@ -309,8 +310,8 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
     * 2) FolderIcon of the Folder containing the given icon
     * 3) All Apps button
     */
    public View getFirstIconMatch(ItemInfoMatcher matcher) {
        ItemInfoMatcher folderMatcher = ItemInfoMatcher.forFolderMatch(matcher);
    public View getFirstIconMatch(Predicate<ItemInfo> matcher) {
        Predicate<ItemInfo> folderMatcher = ItemInfoMatcher.forFolderMatch(matcher);
        return mTaskbarView.getFirstMatch(matcher, folderMatcher);
    }

Loading