From e2367dd5a98f66ccecec454c69d4ed049d9251b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 21 Sep 2023 12:53:29 +0200 Subject: [PATCH] Copy grid items before iterating to prevent concurrent modification --- .../com/simplemobiletools/launcher/activities/MainActivity.kt | 3 ++- .../com/simplemobiletools/launcher/views/HomeScreenGrid.kt | 3 ++- .../simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt index 1eaea4c..ba33a5c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -52,6 +52,7 @@ import com.simplemobiletools.launcher.interfaces.ItemMenuListener import com.simplemobiletools.launcher.models.AppLauncher import com.simplemobiletools.launcher.models.HiddenIcon import com.simplemobiletools.launcher.models.HomeScreenGridItem +import kotlinx.collections.immutable.toImmutableList import kotlin.math.abs class MainActivity : SimpleActivity(), FlingListener { @@ -407,7 +408,7 @@ class MainActivity : SimpleActivity(), FlingListener { val gridItems = homeScreenGridItemsDB.getAllItems() as ArrayList val maxPage = gridItems.maxOf { it.page } val occupiedCells = ArrayList>() - gridItems.filter { it.parentId == null }.forEach { item -> + gridItems.toImmutableList().filter { it.parentId == null }.forEach { item -> for (xCell in item.left..item.right) { for (yCell in item.top..item.bottom) { occupiedCells.add(Triple(item.page, xCell, yCell)) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt index 4a5b800..1b35d94 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -42,6 +42,7 @@ import com.simplemobiletools.launcher.extensions.getDrawableForPackageName import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB import com.simplemobiletools.launcher.helpers.* import com.simplemobiletools.launcher.models.HomeScreenGridItem +import kotlinx.collections.immutable.toImmutableList import kotlin.math.* class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) { @@ -179,7 +180,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel ensureBackgroundThread { val providers = appWidgetManager.installedProviders gridItems = context.homeScreenGridItemsDB.getAllItems() as ArrayList - gridItems.forEach { item -> + gridItems.toImmutableList().forEach { item -> if (item.type == ITEM_TYPE_ICON) { item.drawable = context.getDrawableForPackageName(item.packageName) } else if (item.type == ITEM_TYPE_FOLDER) { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt index c115637..b0cbf31 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetResizeFrame.kt @@ -13,6 +13,7 @@ import com.simplemobiletools.launcher.extensions.config import com.simplemobiletools.launcher.extensions.getCellCount import com.simplemobiletools.launcher.helpers.MAX_CLICK_DURATION import com.simplemobiletools.launcher.models.HomeScreenGridItem +import kotlinx.collections.immutable.toImmutableList @SuppressLint("ViewConstructor") class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) { @@ -80,7 +81,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In redrawFrame() occupiedCells.clear() - allGridItems.forEach { item -> + allGridItems.toImmutableList().forEach { item -> for (xCell in item.left..item.right) { for (yCell in item.top..item.bottom) { occupiedCells.add(Pair(xCell, yCell))