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

Verified Commit 5008bd40 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Saalim Quadri
Browse files

feat(grid): implementation of ios reorder logic

parent 482ee241
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -97,10 +97,16 @@ class MultiModeController(val context: Context, val monitor: LauncherAppMonitor)

        @JvmStatic
        val isSingleLayerMode
            get() = prefs.get(LauncherPrefs.IS_SINGLE_LAYER_ENABLED)
            get() =
                if (::prefs.isInitialized) {
                    prefs.get(LauncherPrefs.IS_SINGLE_LAYER_ENABLED)
                } else true

        @JvmStatic
        val isNotifCountEnabled
            get() = prefs.get(LauncherPrefs.IS_NOTIF_COUNT_ENABLED)
            get() =
                if (::prefs.isInitialized) {
                    prefs.get(LauncherPrefs.IS_NOTIF_COUNT_ENABLED)
                } else true
    }
}
+173 −2
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.launcher3.celllayout.ItemConfiguration;
import com.android.launcher3.celllayout.ReorderAlgorithm;
import com.android.launcher3.celllayout.ReorderParameters;
import com.android.launcher3.celllayout.ReorderPreviewAnimation;
import com.android.launcher3.celllayout.ViewCluster;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.folder.PreviewBackground;
@@ -85,6 +86,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.Stack;

import foundation.e.bliss.multimode.MultiModeController;
@@ -216,6 +218,8 @@ public class CellLayout extends ViewGroup {

    CellLayoutContainer mCellLayoutContainer;

    ArrayList<CellAndSpan> mWidgetCellAndSpanList = new ArrayList<>();

    public static final FloatProperty<CellLayout> SPRING_LOADED_PROGRESS =
            new FloatProperty<CellLayout>("spring_loaded_progress") {
                @Override
@@ -1586,12 +1590,16 @@ public class CellLayout extends ViewGroup {
    }

    public void copyCurrentStateToSolution(ItemConfiguration solution) {
        mWidgetCellAndSpanList.clear();
        int childCount = mShortcutsAndWidgets.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = mShortcutsAndWidgets.getChildAt(i);
            CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams();
            solution.add(child,
                    new CellAndSpan(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan));
            CellAndSpan c = new CellAndSpan(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan);
            if (child instanceof LauncherAppWidgetHostView) {
                mWidgetCellAndSpanList.add(c);
            }
            solution.add(child, c);
        }
    }

@@ -1756,6 +1764,34 @@ public class CellLayout extends ViewGroup {
        return mOccupied.findVacantCell(cellXY, spanX, spanY);
    }

    public int[] getLastOccupiedCells() {
        int[] loc = new int[]{-1, -1};
        out:
        for (int y = mCountY - 1; y >= 0; y--) {
            for (int x = mCountX - 1; x >= 0; x--) {
                if (isOccupied(x, y)) {
                    loc[0] = x;
                    loc[1] = y;
                    break out;
                }
            }
        }
        /*
        if (loc[0] >= 0 && loc[1] >= 0) {
            if (loc[0] == mCountX - 1) {
                loc[0] = 0;
                loc[1]++;
                if (loc[1] > mCountY - 1) {
                    return null;
                }
            } else {
                loc[0] = loc[0] + 1;
            }
        }
         */
        return loc;
    }

    /**
     * A drag event has begun over this layout.
     * It may have begun over this layout (in which case onDragChild is called first),
@@ -1960,4 +1996,139 @@ public class CellLayout extends ViewGroup {
    public void setSpaceBetweenCellLayoutsPx(@Px int spaceBetweenCellLayoutsPx) {
        mSpaceBetweenCellLayoutsPx = spaceBetweenCellLayoutsPx;
    }

    public int isCellInLauncherAppWidget(int x, int y, int whichEdge) {
        for (CellAndSpan c : mWidgetCellAndSpanList) {
            if (x >= c.cellX && x < c.cellX + c.spanX && y >= c.cellY && y < c.cellY + c.spanY) {
                if (whichEdge == ViewCluster.LEFT) {
                    return c.cellX;
                } else if (whichEdge == ViewCluster.RIGHT) {
                    return c.cellX + c.spanX - 1;
                }
            }
        }
        return -1;
    }

    public void reArrangeIcons(int x, int y) {
        ItemConfiguration solution = new ItemConfiguration();
        copyCurrentStateToSolution(solution);
        View dragView = null;
        int[] intersecting = new int[2];

        if (x == 0) {
            intersecting[0] = getCountX() - 1;
            intersecting[1] = y - 1;
        } else {
            intersecting[0] = x - 1;
            intersecting[1] = y;
        }

        ArrayList<View> views = new ArrayList<>();
        for (Map.Entry <View, CellAndSpan> keyValue : solution.map.entrySet()) {
            CellAndSpan c = keyValue.getValue();

            if (c.cellX == x && c.cellY == y) {
                mTmpOccupied.markCells(c, false);
                dragView = keyValue.getKey();
                views.add(dragView);
                pushIconByRow(c, getCountX(), getCountY(), ViewCluster.LEFT);

                int screenId = getCellLayoutContainer().getCellLayoutId(this);
                int container = LauncherSettings.Favorites.CONTAINER_DESKTOP;

                CellLayoutLayoutParams lp = (CellLayoutLayoutParams) dragView.getLayoutParams();
                ItemInfo info = (ItemInfo) dragView.getTag();
                info.cellX = intersecting[0];
                lp.setCellX(info.cellX);
                info.cellY = intersecting[1];
                lp.setCellY(info.cellY);
                info.spanX = lp.cellHSpan = 1;
                info.spanY = lp.cellVSpan = 1;
                lp.isLockedToGrid = true;

                Launcher.cast(mActivity).getModelWriter().modifyItemInDatabase(info, container,
                        screenId, info.cellX, info.cellY, info.spanX, info.spanY);
            }
        }
        ViewCluster cluster = new ViewCluster(this, views, solution);
        cluster.sortConfigurationForEdgePush(ViewCluster.LEFT);
        solution.sortedViews.sort((lhs, rhs) -> {
            CellLayoutLayoutParams lplhs = (CellLayoutLayoutParams) lhs.getLayoutParams();
            CellLayoutLayoutParams lprhs = (CellLayoutLayoutParams) rhs.getLayoutParams();
            if (lprhs.getCellY() + lprhs.cellVSpan == lplhs.getCellY() + lplhs.cellVSpan) {
                return lprhs.getCellX() - lplhs.getCellX();
            }
            return (lprhs.getCellY() + lprhs.cellVSpan) - (lplhs.getCellY() + lplhs.cellVSpan);
        });

        for (View v: solution.sortedViews) {
            CellAndSpan c = solution.map.get(v);
            CellLayoutLayoutParams lp = (CellLayoutLayoutParams) v.getLayoutParams();
            if (!lp.canReorder) {
                // The push solution includes the all apps button, this is not viable.
                break;
            }
            if (cluster.isViewTouchingEdge(v, ViewCluster.LEFT)) {
                if (!cluster.views.contains(v)) {
                    cluster.addView(v);
                }
                mTmpOccupied.markCells(c, false);
                pushIconByRow(c, getCountX(), getCountY(),ViewCluster.LEFT);
            }
        }
        cluster.shift(ViewCluster.LEFT, 1);

        solution.cellX = intersecting[0];
        solution.cellY = intersecting[1];
        solution.spanX = 1;
        solution.spanY = 1;
        solution.isSolution = true;

        if (dragView != null) {
            performReorder(solution, dragView, MODE_ON_DROP);
        }
    }

    public void pushIconByRow(CellAndSpan c, int countX, int countY, int whichEdge) {
        if (whichEdge == ViewCluster.LEFT) {
            if (c.cellX == 0 && c.cellY - c.spanY >= 0) {
                c.cellY = c.cellY - c.spanY;
                c.cellX = countX;
            }
            int result = isCellInLauncherAppWidget(c.cellX - 1, c.cellY, ViewCluster.LEFT);
            if (result != -1) {
                c.cellX = result;
                while (c.cellX == 0 && c.cellY - c.spanY >= 0) {
                    c.cellY = c.cellY - c.spanY;
                    c.cellX = countX;
                    int cellX = isCellInLauncherAppWidget(c.cellX - 1, c.cellY, ViewCluster.LEFT);
                    if (cellX != -1) {
                        c.cellX = cellX;
                    }
                }
            }
        } else if (whichEdge == ViewCluster.RIGHT) {
            if (c.cellX == countX - 1 && c.cellY + c.spanY <= countY - 1) {
                c.cellY = c.cellY + c.spanY;
                c.cellX = -1;
            }
            int result = isCellInLauncherAppWidget(c.cellX + 1, c.cellY, ViewCluster.RIGHT);
            if (result != -1) {
                c.cellX = result;
                while (c.cellX == countX - 1 && c.cellY + c.spanY <= countY - 1) {
                    c.cellY = c.cellY + c.spanY;
                    c.cellX = -1;
                    int cellX = isCellInLauncherAppWidget(c.cellX + 1, c.cellY, ViewCluster.RIGHT);
                    if (cellX != -1) {
                        c.cellX = cellX;
                    }
                }
            }
        }
    }

    public boolean isWidget() {
        return Workspace.isWidget;
    }
}
+34 −2
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ import com.android.launcher3.dragndrop.SpringLoadedDragController;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.PreviewBackground;
import com.android.launcher3.folder.PreviewItemManager;
import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.icons.BitmapRenderer;
import com.android.launcher3.icons.FastBitmapDrawable;
@@ -2576,9 +2577,12 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
        }
    }

    public static boolean isWidget;

    private boolean isDragWidget(DragObject d) {
        return (d.dragInfo instanceof LauncherAppWidgetInfo ||
        isWidget = (d.dragInfo instanceof LauncherAppWidgetInfo ||
                d.dragInfo instanceof PendingAddWidgetInfo);
        return isWidget;
    }

    public void onDragOver(DragObject d) {
@@ -3294,6 +3298,32 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
            cell.setVisibility(VISIBLE);
        }
        mDragInfo = null;
        clearEmptyCell();
    }

    private void clearEmptyCell() {
        int numberOfScreens = mScreenOrder.size();
        for (int i = 1; i < numberOfScreens; i++) {
            CellLayout cellLayout = mWorkspaceScreens.get(mScreenOrder.get(i));
            needCellCleanup(cellLayout);
        }
    }

    public void needCellCleanup(CellLayout cellLayout) {
        int[] vacantCell = {-1, -1};
        int[] lastCellOccupied = cellLayout.getLastOccupiedCells();
        cellLayout.findCellForSpan(vacantCell, 1, 1);

        if ((lastCellOccupied != null && lastCellOccupied[0] != -1) &&
                ((vacantCell[1] < lastCellOccupied[1]) ||
                        (vacantCell[1] == lastCellOccupied[1] && vacantCell[0] < lastCellOccupied[0])) &&
                (vacantCell[0] != -1 && vacantCell[1] != -1) &&
                !cellLayout.isOccupied(vacantCell[0], vacantCell[1])) {
            postDelayed(() -> {
                cellLayout.reArrangeIcons(lastCellOccupied[0], lastCellOccupied[1]);
                needCellCleanup(cellLayout);
            }, PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION);
        }
    }

    /**
@@ -3520,6 +3550,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>

        // Strip all the empty screens
        stripEmptyScreens();
        clearEmptyCell();
    }

    @Override
@@ -3746,7 +3777,8 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
            mapOverItems((info, view) -> {
                view.setLayerType(LAYER_TYPE_HARDWARE, null);
                if (excludeDraggingView && mDragObjectInfo != null) {
                    if (mDragObjectInfo instanceof WorkspaceItemInfo
                    if ((mDragObjectInfo instanceof WorkspaceItemInfo ||
                            mDragObjectInfo instanceof FolderInfo)
                            && mDragObjectInfo.equals(view.getTag())) {
                        return false;
                    }
+224 −39

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ public class PreviewItemManager {
    private float mCurrentPageItemsTransX = 0;
    private boolean mShouldSlideInFirstPage;

    static final int INITIAL_ITEM_ANIMATION_DURATION = 350;
    public static final int INITIAL_ITEM_ANIMATION_DURATION = 350;
    private static final int FINAL_ITEM_ANIMATION_DURATION = 200;

    private static final int SLIDE_IN_FIRST_PAGE_ANIMATION_DURATION_DELAY = 100;
+1 −1

File changed.

Contains only whitespace changes.

Loading