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 c8632c3..71d8c52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -91,13 +91,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel fun removeAppIcon(item: HomeScreenGridItem) { ensureBackgroundThread { - context.homeScreenGridItemsDB.deleteById(item.id!!) - if (item.type == ITEM_TYPE_WIDGET) { - appWidgetHost.deleteAppWidgetId(item.widgetId) - - post { - removeView(widgetViews.firstOrNull { it.tag == item.widgetId }) - } + removeItemFromHomeScreen(item) + post { + removeView(widgetViews.firstOrNull { it.tag == item.widgetId }) } gridItems.removeIf { it.id == item.id } @@ -105,6 +101,18 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel } } + private fun removeItemFromHomeScreen(item: HomeScreenGridItem) { + ensureBackgroundThread { + if (item.id != null) { + context.homeScreenGridItemsDB.deleteById(item.id!!) + } + + if (item.type == ITEM_TYPE_WIDGET) { + appWidgetHost.deleteAppWidgetId(item.widgetId) + } + } + } + fun itemDraggingStarted(draggedGridItem: HomeScreenGridItem) { draggedItem = draggedGridItem if (draggedItem!!.drawable == null) { @@ -288,19 +296,15 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel activity.handleWidgetConfigureScreen(appWidgetHost, appWidgetId) { success -> if (success) { placeAppWidget(appWidgetId, appWidgetProviderInfo, item) - } else if (item.id != null) { - ensureBackgroundThread { - context.homeScreenGridItemsDB.deleteById(item.id!!) - } + } else { + removeItemFromHomeScreen(item) } } } else { placeAppWidget(appWidgetId, appWidgetProviderInfo, item) } - } else if (item.id != null) { - ensureBackgroundThread { - context.homeScreenGridItemsDB.deleteById(item.id!!) - } + } else { + removeItemFromHomeScreen(item) } } }