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

Commit a2f5ee8f authored by András Klöczl's avatar András Klöczl Committed by Android (Google) Code Review
Browse files

Merge "Fix icon adding issue on two panel home" into sc-v2-dev

parents b3dc0743 88716645
Loading
Loading
Loading
Loading
+12 −21
Original line number Original line Diff line number Diff line
@@ -287,30 +287,21 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {


        // Find appropriate space for the item.
        // Find appropriate space for the item.
        int screenId = 0;
        int screenId = 0;
        int[] cordinates = new int[2];
        int[] coordinates = new int[2];
        boolean found = false;
        boolean found = false;


        int screenCount = workspaceScreens.size();
        int screenCount = workspaceScreens.size();
        // First check the preferred screen.
        int firstScreenToCheck = dataModel.isLeftPanelShown ? 2 : 1;
        int preferredScreenIndex = workspaceScreens.isEmpty() ? 0 : 1;
        // Search on the screens for empty space
        if (preferredScreenIndex < screenCount) {
        for (int screen = firstScreenToCheck; screen < screenCount; screen++) {
            screenId = workspaceScreens.get(preferredScreenIndex);
            found = findNextAvailableIconSpaceInScreen(
                    app, screenItems.get(screenId), cordinates, spanX, spanY);
        }

        if (!found) {
            // Search on any of the screens starting from the first screen.
            for (int screen = 1; screen < screenCount; screen++) {
            screenId = workspaceScreens.get(screen);
            screenId = workspaceScreens.get(screen);
            if (findNextAvailableIconSpaceInScreen(
            if (findNextAvailableIconSpaceInScreen(
                        app, screenItems.get(screenId), cordinates, spanX, spanY)) {
                    app, screenItems.get(screenId), coordinates, spanX, spanY)) {
                // We found a space for it
                // We found a space for it
                found = true;
                found = true;
                break;
                break;
            }
            }
        }
        }
        }


        if (!found) {
        if (!found) {
            // Still no position found. Add a new screen to the end.
            // Still no position found. Add a new screen to the end.
@@ -324,11 +315,11 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {


            // If we still can't find an empty space, then God help us all!!!
            // If we still can't find an empty space, then God help us all!!!
            if (!findNextAvailableIconSpaceInScreen(
            if (!findNextAvailableIconSpaceInScreen(
                    app, screenItems.get(screenId), cordinates, spanX, spanY)) {
                    app, screenItems.get(screenId), coordinates, spanX, spanY)) {
                throw new RuntimeException("Can't find space to add the item");
                throw new RuntimeException("Can't find space to add the item");
            }
            }
        }
        }
        return new int[] {screenId, cordinates[0], cordinates[1]};
        return new int[] {screenId, coordinates[0], coordinates[1]};
    }
    }


    private boolean findNextAvailableIconSpaceInScreen(
    private boolean findNextAvailableIconSpaceInScreen(