store the app title at home grid items too

This commit is contained in:
tibbi 2022-09-19 19:45:46 +02:00
parent 4bcda4ba95
commit e0a17f48b4
5 changed files with 27 additions and 6 deletions

View File

@ -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<HomeScreenGridItem>()
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) {
}

View File

@ -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()
}

View File

@ -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

View File

@ -14,6 +14,9 @@ interface HomeScreenGridItemsDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(items: List<HomeScreenGridItem>)
@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)
}

View File

@ -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
)