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

Commit ea600c70 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Creating a common method to iterate over all model items.

This would allow adding different source for model items without
modifying every model task

Bug: 160748731
Change-Id: I5a14dd761e2b8696c58dc8fec7b14077da0aced3
parent c146d0c3
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ import com.android.launcher3.pm.InstallSessionTracker;
import com.android.launcher3.pm.PackageInstallInfo;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.PackageUserKey;
@@ -410,7 +410,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
        enqueueModelUpdateTask(new BaseModelUpdateTask() {
            @Override
            public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
                final IntSparseArrayMap<Boolean> removedIds = new IntSparseArrayMap<>();
                final IntSet removedIds = new IntSet();
                synchronized (dataModel) {
                    for (ItemInfo info : dataModel.itemsIdMap) {
                        if (info instanceof WorkspaceItemInfo
@@ -418,13 +418,13 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
                                && user.equals(info.user)
                                && info.getIntent() != null
                                && TextUtils.equals(packageName, info.getIntent().getPackage())) {
                            removedIds.put(info.id, true /* remove */);
                            removedIds.add(info.id);
                        }
                    }
                }

                if (!removedIds.isEmpty()) {
                    deleteAndBindComponentsRemoved(ItemInfoMatcher.ofItemIds(removedIds, false));
                    deleteAndBindComponentsRemoved(ItemInfoMatcher.ofItemIds(removedIds));
                }
            }
        });
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
    protected final BaseDraggingActivity mLauncher;
    protected final AdapterHolder[] mAH;
    private final ItemInfoMatcher mPersonalMatcher = ItemInfoMatcher.ofUser(Process.myUserHandle());
    private final ItemInfoMatcher mWorkMatcher = ItemInfoMatcher.not(mPersonalMatcher);
    private final ItemInfoMatcher mWorkMatcher = mPersonalMatcher.negate();
    private final AllAppsStore mAllAppsStore = new AllAppsStore();

    private final Paint mNavBarScrimPaint;
+14 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
@@ -348,6 +349,19 @@ public class BgDataModel {
        }
    }

    /**
     * Calls the provided {@code op} for all workspaceItems in the in-memory model (both persisted
     * items and dynamic/predicted items for the provided {@code userHandle}.
     * Note the call is not synchronized over the model, that should be handled by the called.
     */
    public void forAllWorkspaceItemInfos(UserHandle userHandle, Consumer<WorkspaceItemInfo> op) {
        for (ItemInfo info : itemsIdMap) {
            if (info instanceof WorkspaceItemInfo && userHandle.equals(info.user)) {
                op.accept((WorkspaceItemInfo) info);
            }
        }
    }

    public interface Callbacks {
        // If the launcher has permission to access deep shortcuts.
        int FLAG_HAS_SHORTCUT_PERMISSION = 1 << 0;
+8 −14
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.os.UserHandle;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;

import java.util.ArrayList;
@@ -48,14 +47,10 @@ public class CacheDataUpdatedTask extends BaseModelUpdateTask {
    @Override
    public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
        IconCache iconCache = app.getIconCache();


        ArrayList<WorkspaceItemInfo> updatedShortcuts = new ArrayList<>();

        synchronized (dataModel) {
            for (ItemInfo info : dataModel.itemsIdMap) {
                if (info instanceof WorkspaceItemInfo && mUser.equals(info.user)) {
                    WorkspaceItemInfo si = (WorkspaceItemInfo) info;
            dataModel.forAllWorkspaceItemInfos(mUser, si -> {
                ComponentName cn = si.getTargetComponent();
                if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
                        && isValidShortcut(si) && cn != null
@@ -63,8 +58,7 @@ public class CacheDataUpdatedTask extends BaseModelUpdateTask {
                    iconCache.getTitleAndIcon(si, si.usingLowResIcon());
                    updatedShortcuts.add(si);
                }
                }
            }
            });
            apps.updateIconsAndLabels(mPackages, mUser);
        }
        bindUpdatedWorkspaceItems(updatedShortcuts);
+11 −21
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel.CallbackTask;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.PromiseAppInfo;
@@ -70,9 +68,7 @@ public class PackageInstallStateChangedTask extends BaseModelUpdateTask {

        synchronized (dataModel) {
            final HashSet<ItemInfo> updates = new HashSet<>();
            for (ItemInfo info : dataModel.itemsIdMap) {
                if (info instanceof WorkspaceItemInfo) {
                    WorkspaceItemInfo si = (WorkspaceItemInfo) info;
            dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
                ComponentName cn = si.getTargetComponent();
                if (si.hasPromiseIconUi() && (cn != null)
                        && mInstallInfo.packageName.equals(cn.getPackageName())) {
@@ -83,8 +79,7 @@ public class PackageInstallStateChangedTask extends BaseModelUpdateTask {
                    }
                    updates.add(si);
                }
                }
            }
            });

            for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
                if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
@@ -94,12 +89,7 @@ public class PackageInstallStateChangedTask extends BaseModelUpdateTask {
            }

            if (!updates.isEmpty()) {
                scheduleCallbackTask(new CallbackTask() {
                    @Override
                    public void execute(Callbacks callbacks) {
                        callbacks.bindRestoreItemsChange(updates);
                    }
                });
                scheduleCallbackTask(callbacks -> callbacks.bindRestoreItemsChange(updates));
            }
        }
    }
Loading