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

Commit 78a28f77 authored by Romain Hunault's avatar Romain Hunault 🚴🏻
Browse files

Merge branch '4286-blisslauncher_folder_fix' into 'master'

Fix IndexOutOfBoundsException while loading items

See merge request !76
parents 078209a9 2ff37d27
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ public class LauncherItem {

    @Override
    public String toString() {
        return "[id: " + id + "item_type: " + itemType + ", container: " + container + ", screen: " + screenId
        return "[id: " + id + ", item_type: " + itemType + ", container: " + container + ", screen: " + screenId
                + ", cell: " + cell + "]";
    }

+18 −11
Original line number Diff line number Diff line
@@ -337,6 +337,8 @@ public class AppProvider {
                    if (index != null) {
                        FolderItem folderItem = (FolderItem) mLauncherItems.get(index);
                        folderItem.items.add(applicationItem);
                    } else {
                        Log.e("AppProvider", "folder not found for item: " + applicationItem.id);
                    }
                }
            } else if (databaseItem.itemType == Constants.ITEM_TYPE_SHORTCUT) {
@@ -377,19 +379,24 @@ public class AppProvider {
            }
        }

        if (foldersIndex.size() > 0) {
        List<Integer> folderItemsIndex = new ArrayList<>();
        for (int i = 0; i < foldersIndex.size(); i++) {
            int itemIndex = foldersIndex.get(foldersIndex.keyAt(i));
            folderItemsIndex.add(itemIndex);
        }
        Collections.sort(folderItemsIndex);
        for (int i = folderItemsIndex.size() - 1; i >= 0; i--) {
            int itemIndex = folderItemsIndex.get(i);
            FolderItem folderItem =
                        (FolderItem) mLauncherItems.get(foldersIndex.get(foldersIndex.keyAt(i)));
                    (FolderItem) mLauncherItems.get(itemIndex);
            if (folderItem.items == null || folderItem.items.size() == 0) {
                DatabaseManager.getManager(mContext).removeLauncherItem(folderItem.id);
                    mLauncherItems.remove((int) foldersIndex.get(foldersIndex.keyAt(i)));
                mLauncherItems.remove(itemIndex);
            } else {
                folderItem.icon = new GraphicsUtil(mContext).generateFolderIcon(mContext,
                        folderItem);
            }
        }
        }

        applicationItems.removeAll(mDatabaseItems);
        List<ApplicationItem> mutableList = new ArrayList<>(applicationItems);