Disable all icons other than the active one.

This commit is contained in:
Nicholas Tinsley
2023-05-24 11:29:37 -04:00
committed by Nicholas
parent fd826749e4
commit 52060b65be

View File

@@ -21,14 +21,20 @@ class AppIconUtility(context: Context) {
}
fun currentAppIconComponentName(): ComponentName {
return currentAppIcon.getComponentName(applicationContext) ?: AppIconPreset.DEFAULT.getComponentName(applicationContext)
return currentAppIcon.getComponentName(applicationContext)
}
fun setNewAppIcon(desiredAppIcon: AppIconPreset) {
currentAppIcon.let {
pm.setComponentEnabledSetting(it.getComponentName(applicationContext), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
}
Log.d(TAG, "Setting new app icon.")
pm.setComponentEnabledSetting(desiredAppIcon.getComponentName(applicationContext), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
Log.d(TAG, "${desiredAppIcon.name} enabled.")
val previousAppIcon = currentAppIcon
pm.setComponentEnabledSetting(previousAppIcon.getComponentName(applicationContext), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
Log.d(TAG, "${previousAppIcon.name} disabled.")
enumValues<AppIconPreset>().filterNot { it == desiredAppIcon || it == previousAppIcon }.forEach {
pm.setComponentEnabledSetting(it.getComponentName(applicationContext), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
Log.d(TAG, "${it.name} disabled.")
}
}
private fun readCurrentAppIconFromPackageManager(): AppIconPreset {