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

Commit c515d02f authored by Sebastian Franco's avatar Sebastian Franco
Browse files

Fix widget resize if it last for too long on Multipage CellLayout

We need to make sure the seam is added when the countX is even
checking for => and if you reszie for a while the occupied grid
starts to have incorrect values.

Fix: 270227019
Test: atest FoldableItemsIntegrity
Test: atest ReorderWidgets
Change-Id: I3faf5d23427dc966c48ce5c613e68e42a101f45b
parent a695986d
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class MultipageCellLayout extends CellLayout {
    boolean createAreaForResize(int cellX, int cellY, int spanX, int spanY, View dragView,
            int[] direction, boolean commit) {
        // Add seam to x position
        if (cellX > mCountX / 2) {
        if (cellX >= mCountX / 2) {
            cellX++;
        }
        int finalCellX = cellX;
@@ -109,7 +109,7 @@ public class MultipageCellLayout extends CellLayout {
        lp.canReorder = false;
        mCountX++;
        mShortcutsAndWidgets.addViewInLayout(mSeam, lp);
        mOccupied = createGridOccupancy();
        mOccupied = createGridOccupancyWithSeam(mOccupied);
        mTmpOccupied = new GridOccupancy(mCountX, mCountY);
    }

@@ -139,14 +139,19 @@ public class MultipageCellLayout extends CellLayout {
        return solution;
    }

    GridOccupancy createGridOccupancy() {
        GridOccupancy grid = new GridOccupancy(mCountX, mCountY);
        for (int i = 0; i < mShortcutsAndWidgets.getChildCount(); i++) {
            View view = mShortcutsAndWidgets.getChildAt(i);
            CellLayoutLayoutParams lp = (CellLayoutLayoutParams) view.getLayoutParams();
            int seamOffset = lp.getCellX() >= mCountX / 2 && lp.canReorder ? 1 : 0;
            grid.markCells(lp.getCellX() + seamOffset, lp.getCellY(), lp.cellHSpan, lp.cellVSpan,
                    true);


    GridOccupancy createGridOccupancyWithSeam(GridOccupancy gridOccupancy) {
        GridOccupancy grid = new GridOccupancy(getCountX(), getCountY());
        for (int x = 0; x < getCountX(); x++) {
            for (int y = 0; y < getCountY(); y++) {
                int offset = x >= getCountX() / 2 ? 1 : 0;
                if (x == getCountX() / 2) {
                    grid.cells[x][y] = true;
                } else {
                    grid.cells[x][y] = gridOccupancy.cells[x - offset][y];
                }
            }
        }
        return grid;
    }