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

Commit 2f0b2d3b authored by Samuel Fufa's avatar Samuel Fufa
Browse files

Dedupe Items on Workspace for hotseat prediction

Bug:145236832
Test:Manual
Change-Id: I46da38998486c7f58aca829d33b42cbb04da515a
parent 51a5bf15
Loading
Loading
Loading
Loading
+36 −12
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ public class HotseatPredictionController implements DragController.DragListener,
    //TODO: replace this with AppTargetEvent.ACTION_UNPIN (b/144119543)
    private static final int APPTARGET_ACTION_UNPIN = 4;

    private static final String APP_LOCATION_HOTSEAT = "hotseat";
    private static final String APP_LOCATION_WORKSPACE = "workspace";

    private static final String PREDICTION_CLIENT = "hotseat";

    private DropTarget.DragObject mDragObject;
@@ -204,17 +207,24 @@ public class HotseatPredictionController implements DragController.DragListener,

    private Bundle getAppPredictionContextExtra() {
        Bundle bundle = new Bundle();
        ViewGroup vg = mHotseat.getShortcutsAndWidgets();
        bundle.putParcelableArrayList(APP_LOCATION_HOTSEAT,
                getPinnedAppTargetsInViewGroup((mHotseat.getShortcutsAndWidgets())));
        bundle.putParcelableArrayList(APP_LOCATION_WORKSPACE, getPinnedAppTargetsInViewGroup(
                mLauncher.getWorkspace().getScreenWithId(
                        Workspace.FIRST_SCREEN_ID).getShortcutsAndWidgets()));
        return bundle;
    }

    private ArrayList<AppTarget> getPinnedAppTargetsInViewGroup(ViewGroup viewGroup) {
        ArrayList<AppTarget> pinnedApps = new ArrayList<>();
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            if (isPinnedIcon(child)) {
                WorkspaceItemInfo itemInfo = (WorkspaceItemInfo) child.getTag();
                pinnedApps.add(getAppTargetFromItemInfo(itemInfo));
            }
        }
        bundle.putParcelableArrayList("pinned_apps", pinnedApps);
        return bundle;
        return pinnedApps;
    }

    private void setPredictedApps(List<AppTarget> appTargets) {
@@ -252,7 +262,7 @@ public class HotseatPredictionController implements DragController.DragListener,
        ObjectAnimator.ofFloat(icon, SCALE_PROPERTY, 1, 0.8f, 1).start();
        icon.pin(workspaceItemInfo);
        AppTarget appTarget = getAppTargetFromItemInfo(workspaceItemInfo);
        notifyItemAction(appTarget, AppTargetEvent.ACTION_PIN);
        notifyItemAction(appTarget, APP_LOCATION_HOTSEAT, AppTargetEvent.ACTION_PIN);
    }

    private List<WorkspaceItemInfo> mapToWorkspaceItemInfo(
@@ -312,9 +322,10 @@ public class HotseatPredictionController implements DragController.DragListener,
    }


    private void notifyItemAction(AppTarget target, int action) {
    private void notifyItemAction(AppTarget target, String location, int action) {
        if (mAppPredictor != null) {
            mAppPredictor.notifyAppTargetEvent(new AppTargetEvent.Builder(target, action).build());
            mAppPredictor.notifyAppTargetEvent(new AppTargetEvent.Builder(target,
                    action).setLaunchLocation(location).build());
        }
    }

@@ -336,10 +347,18 @@ public class HotseatPredictionController implements DragController.DragListener,
        }
        ItemInfo dragInfo = mDragObject.dragInfo;
        if (dragInfo instanceof WorkspaceItemInfo && dragInfo.getTargetComponent() != null) {
            AppTarget appTarget = getAppTargetFromItemInfo(dragInfo);
            if (!isInHotseat(dragInfo) && isInHotseat(mDragObject.originalDragInfo)) {
                notifyItemAction(appTarget, APP_LOCATION_HOTSEAT, APPTARGET_ACTION_UNPIN);
            }
            if (!isInFirstPage(dragInfo) && isInFirstPage(mDragObject.originalDragInfo)) {
                notifyItemAction(appTarget, APP_LOCATION_WORKSPACE, APPTARGET_ACTION_UNPIN);
            }
            if (isInHotseat(dragInfo) && !isInHotseat(mDragObject.originalDragInfo)) {
                notifyItemAction(getAppTargetFromItemInfo(dragInfo), AppTargetEvent.ACTION_PIN);
            } else if (!isInHotseat(dragInfo) && isInHotseat(mDragObject.originalDragInfo)) {
                notifyItemAction(getAppTargetFromItemInfo(dragInfo), APPTARGET_ACTION_UNPIN);
                notifyItemAction(appTarget, APP_LOCATION_HOTSEAT, AppTargetEvent.ACTION_PIN);
            }
            if (isInFirstPage(dragInfo) && !isInFirstPage(mDragObject.originalDragInfo)) {
                notifyItemAction(appTarget, APP_LOCATION_WORKSPACE, AppTargetEvent.ACTION_PIN);
            }
        }
        mDragObject = null;
@@ -412,7 +431,7 @@ public class HotseatPredictionController implements DragController.DragListener,
            return false;
        }
        ItemInfo info = (ItemInfo) view.getTag();
        return info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && (
        return info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION && (
                info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
                        || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT);
    }
@@ -421,6 +440,11 @@ public class HotseatPredictionController implements DragController.DragListener,
        return itemInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT;
    }

    private static boolean isInFirstPage(ItemInfo itemInfo) {
        return itemInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP
                && itemInfo.screenId == Workspace.FIRST_SCREEN_ID;
    }

    private static AppTarget getAppTargetFromItemInfo(ItemInfo info) {
        if (info.getTargetComponent() == null) return null;
        ComponentName cn = info.getTargetComponent();
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ public class DeleteDropTarget extends ButtonDropTarget {
    public void onDrop(DragObject d, DragOptions options) {
        if (canRemove(d.dragInfo)) {
            mLauncher.getModelWriter().prepareToUndoDelete();
            d.dragInfo.container = NO_ID;
        }
        super.onDrop(d, options);
    }