From 4bcda4ba9591aefdc7ae36aaf53b2ad23a7bf02e Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 19 Sep 2022 18:55:30 +0200 Subject: [PATCH] remove home screen icons after uninstalling an app --- .../simplemobiletools/launcher/activities/MainActivity.kt | 7 +++++++ .../launcher/interfaces/HomeScreenGridItemsDao.kt | 3 +++ .../com/simplemobiletools/launcher/views/HomeScreenGrid.kt | 1 + 3 files changed, 11 insertions(+) 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 ed2ef1d..a4b5b93 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -160,12 +160,19 @@ class MainActivity : SimpleActivity(), FlingListener { (all_apps_fragment as AllAppsFragment).gotLaunchers(launchers) (widgets_fragment as WidgetsFragment).getAppWidgets() + var hasDeletedAnything = false mCachedLaunchers.map { it.packageName }.forEach { packageName -> if (!launchers.map { it.packageName }.contains(packageName)) { + hasDeletedAnything = true launchersDB.deleteApp(packageName) + homeScreenGridItemsDB.deleteItem(packageName) } } + if (hasDeletedAnything) { + home_screen_grid.fetchAppIcons() + } + mCachedLaunchers = launchers } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HomeScreenGridItemsDao.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HomeScreenGridItemsDao.kt index 6f78fb8..b2c1520 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HomeScreenGridItemsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HomeScreenGridItemsDao.kt @@ -13,4 +13,7 @@ interface HomeScreenGridItemsDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(items: List) + + @Query("DELETE FROM home_screen_grid_items WHERE package_name = :packageName") + fun deleteItem(packageName: String) } 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 13bbf6e..7d91001 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -43,6 +43,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie fun fetchAppIcons() { ensureBackgroundThread { + appIconDrawables.clear() appIcons = context.homeScreenGridItemsDB.getAllItems() as ArrayList appIcons.forEach { item -> val drawable = context.getDrawableForPackageName(item.packageName)