From 69ee50167b906b392515bf34f7ab405c3be70479 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 18 Sep 2022 11:57:32 +0200 Subject: [PATCH] remove non existing apps from cache --- .../simplemobiletools/launcher/fragments/AllAppsFragment.kt | 6 ++++++ .../launcher/interfaces/AppLaunchersDao.kt | 3 +++ 2 files changed, 9 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt index f7324cc..4f47cdf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt @@ -98,6 +98,12 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment val launchers = allApps.distinctBy { it.packageName } as ArrayList context.launchersDB.insertAll(launchers) gotLaunchers(launchers) + + cachedLaunchers.map { it.packageName }.forEach { packageName -> + if (!launchers.map { it.packageName }.contains(packageName)) { + context.launchersDB.deleteApp(packageName) + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt index 32f602b..d2b7b6c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt @@ -13,4 +13,7 @@ interface AppLaunchersDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(appLaunchers: List) + + @Query("DELETE FROM apps WHERE package_name = :packageName") + fun deleteApp(packageName: String) }