From e0a17f48b442effe594230848c1c1f064cb0f0c5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 19 Sep 2022 19:45:46 +0200 Subject: [PATCH] store the app title at home grid items too --- .../launcher/activities/MainActivity.kt | 22 ++++++++++++++----- .../launcher/helpers/Config.kt | 4 ++++ .../launcher/helpers/Constants.kt | 1 + .../interfaces/HomeScreenGridItemsDao.kt | 3 +++ .../launcher/models/HomeScreenGridItem.kt | 3 ++- 5 files changed, 27 insertions(+), 6 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 a4b5b93..3a004fd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -174,6 +174,18 @@ class MainActivity : SimpleActivity(), FlingListener { } mCachedLaunchers = launchers + + if (!config.wereDefaultAppLabelsFilled) { + ensureBackgroundThread { + homeScreenGridItemsDB.getAllItems().forEach { gridItem -> + val launcher = launchers.firstOrNull { it.packageName.equals(gridItem.packageName, true) } + if (launcher != null) { + homeScreenGridItemsDB.updateAppTitle(launcher.title, gridItem.packageName) + } + } + config.wereDefaultAppLabelsFilled = true + } + } } fun startHandlingTouches(touchDownY: Int) { @@ -311,14 +323,14 @@ class MainActivity : SimpleActivity(), FlingListener { val homeScreenGridItems = ArrayList() try { val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage - val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, defaultDialerPackage) + val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, defaultDialerPackage, "") homeScreenGridItems.add(dialerIcon) } catch (e: Exception) { } try { val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this) - val SMSMessengerIcon = HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, defaultSMSMessengerPackage) + val SMSMessengerIcon = HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, defaultSMSMessengerPackage, "") homeScreenGridItems.add(SMSMessengerIcon) } catch (e: Exception) { } @@ -327,7 +339,7 @@ class MainActivity : SimpleActivity(), FlingListener { val browserIntent = Intent("android.intent.action.VIEW", Uri.parse("http://")) val resolveInfo = packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY) val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName - val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, defaultBrowserPackage) + val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, defaultBrowserPackage, "") homeScreenGridItems.add(browserIcon) } catch (e: Exception) { } @@ -336,7 +348,7 @@ class MainActivity : SimpleActivity(), FlingListener { val potentialStores = arrayListOf("com.android.vending", "org.fdroid.fdroid", "com.aurora.store") val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) } if (storePackage != null) { - val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, storePackage) + val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, storePackage, "") homeScreenGridItems.add(storeIcon) } } catch (e: Exception) { @@ -346,7 +358,7 @@ class MainActivity : SimpleActivity(), FlingListener { val cameraIntent = Intent("android.media.action.IMAGE_CAPTURE") val resolveInfo = packageManager.resolveActivity(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY) val defaultCameraPackage = resolveInfo!!.activityInfo.packageName - val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, defaultCameraPackage) + val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, defaultCameraPackage, "") homeScreenGridItems.add(cameraIcon) } catch (e: Exception) { } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt index 338a009..9fd0449 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Config.kt @@ -11,4 +11,8 @@ class Config(context: Context) : BaseConfig(context) { var wasHomeScreenInit: Boolean get() = prefs.getBoolean(WAS_HOME_SCREEN_INIT, false) set(wasHomeScreenInit) = prefs.edit().putBoolean(WAS_HOME_SCREEN_INIT, wasHomeScreenInit).apply() + + var wereDefaultAppLabelsFilled: Boolean + get() = prefs.getBoolean(WERE_DEFAULT_APP_LABELS_FILLED, false) + set(wereDefaultAppLabelsFilled) = prefs.edit().putBoolean(WERE_DEFAULT_APP_LABELS_FILLED, wereDefaultAppLabelsFilled).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt index 7862b83..c4a9671 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt @@ -5,6 +5,7 @@ const val WIDGET_LIST_ITEMS_HOLDER = 1 // shared prefs const val WAS_HOME_SCREEN_INIT = "was_home_screen_init" +const val WERE_DEFAULT_APP_LABELS_FILLED = "were_default_app_labels_filled" // default home screen grid size const val ROW_COUNT = 6 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 b2c1520..0897a33 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HomeScreenGridItemsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HomeScreenGridItemsDao.kt @@ -14,6 +14,9 @@ interface HomeScreenGridItemsDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(items: List) + @Query("UPDATE home_screen_grid_items SET title = :title WHERE package_name = :packageName") + fun updateAppTitle(title: String, packageName: String) + @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/models/HomeScreenGridItem.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt index 6e33334..3057657 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt @@ -13,5 +13,6 @@ data class HomeScreenGridItem( @ColumnInfo(name = "top") val top: Int, @ColumnInfo(name = "right") val right: Int, @ColumnInfo(name = "bottom") val bottom: Int, - @ColumnInfo(name = "package_name") val packageName: String + @ColumnInfo(name = "package_name") val packageName: String, + @ColumnInfo(name = "title") val title: String )