Copy grid items before iterating to prevent concurrent modification

This commit is contained in:
Ensar Sarajčić 2023-09-21 12:53:29 +02:00
parent d9e333ddb0
commit e2367dd5a9
3 changed files with 6 additions and 3 deletions

View File

@ -52,6 +52,7 @@ import com.simplemobiletools.launcher.interfaces.ItemMenuListener
import com.simplemobiletools.launcher.models.AppLauncher import com.simplemobiletools.launcher.models.AppLauncher
import com.simplemobiletools.launcher.models.HiddenIcon import com.simplemobiletools.launcher.models.HiddenIcon
import com.simplemobiletools.launcher.models.HomeScreenGridItem import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.collections.immutable.toImmutableList
import kotlin.math.abs import kotlin.math.abs
class MainActivity : SimpleActivity(), FlingListener { class MainActivity : SimpleActivity(), FlingListener {
@ -407,7 +408,7 @@ class MainActivity : SimpleActivity(), FlingListener {
val gridItems = homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem> val gridItems = homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem>
val maxPage = gridItems.maxOf { it.page } val maxPage = gridItems.maxOf { it.page }
val occupiedCells = ArrayList<Triple<Int, Int, Int>>() val occupiedCells = ArrayList<Triple<Int, Int, Int>>()
gridItems.filter { it.parentId == null }.forEach { item -> gridItems.toImmutableList().filter { it.parentId == null }.forEach { item ->
for (xCell in item.left..item.right) { for (xCell in item.left..item.right) {
for (yCell in item.top..item.bottom) { for (yCell in item.top..item.bottom) {
occupiedCells.add(Triple(item.page, xCell, yCell)) occupiedCells.add(Triple(item.page, xCell, yCell))

View File

@ -42,6 +42,7 @@ import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
import com.simplemobiletools.launcher.helpers.* import com.simplemobiletools.launcher.helpers.*
import com.simplemobiletools.launcher.models.HomeScreenGridItem import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.collections.immutable.toImmutableList
import kotlin.math.* import kotlin.math.*
class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) { 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 { ensureBackgroundThread {
val providers = appWidgetManager.installedProviders val providers = appWidgetManager.installedProviders
gridItems = context.homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem> gridItems = context.homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem>
gridItems.forEach { item -> gridItems.toImmutableList().forEach { item ->
if (item.type == ITEM_TYPE_ICON) { if (item.type == ITEM_TYPE_ICON) {
item.drawable = context.getDrawableForPackageName(item.packageName) item.drawable = context.getDrawableForPackageName(item.packageName)
} else if (item.type == ITEM_TYPE_FOLDER) { } else if (item.type == ITEM_TYPE_FOLDER) {

View File

@ -13,6 +13,7 @@ import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.extensions.getCellCount import com.simplemobiletools.launcher.extensions.getCellCount
import com.simplemobiletools.launcher.helpers.MAX_CLICK_DURATION import com.simplemobiletools.launcher.helpers.MAX_CLICK_DURATION
import com.simplemobiletools.launcher.models.HomeScreenGridItem import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.collections.immutable.toImmutableList
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) { 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() redrawFrame()
occupiedCells.clear() occupiedCells.clear()
allGridItems.forEach { item -> allGridItems.toImmutableList().forEach { item ->
for (xCell in item.left..item.right) { for (xCell in item.left..item.right) {
for (yCell in item.top..item.bottom) { for (yCell in item.top..item.bottom) {
occupiedCells.add(Pair(xCell, yCell)) occupiedCells.add(Pair(xCell, yCell))