Store themed attribute per icon pack icon

This commit is contained in:
MM20 2023-02-15 20:59:13 +01:00
parent f4c1bcf5aa
commit c71fec59ac
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
7 changed files with 18 additions and 7 deletions

View File

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 20,
"identityHash": "0e23c747bfe32759849ee85dcd5d23cb",
"identityHash": "5b1104c3916482efde9b715c1f3c1273",
"entities": [
{
"tableName": "forecasts",
@ -222,7 +222,7 @@
},
{
"tableName": "Icons",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`type` TEXT NOT NULL, `componentName` TEXT, `drawable` TEXT, `iconPack` TEXT NOT NULL, `name` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`type` TEXT NOT NULL, `componentName` TEXT, `drawable` TEXT, `iconPack` TEXT NOT NULL, `name` TEXT, `themed` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT)",
"fields": [
{
"fieldPath": "type",
@ -254,6 +254,12 @@
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "themed",
"columnName": "themed",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
@ -468,7 +474,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0e23c747bfe32759849ee85dcd5d23cb')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5b1104c3916482efde9b715c1f3c1273')"
]
}
}

View File

@ -11,5 +11,6 @@ data class IconEntity(
val drawable: String?,
val iconPack: String,
val name: String?,
val themed: Boolean = false,
@PrimaryKey(autoGenerate = true) val id : Long? = null
)

View File

@ -13,6 +13,7 @@ class Migration_19_20: Migration(19, 20) {
`drawable` TEXT,
`iconPack` TEXT NOT NULL,
`name` TEXT,
`themed` INTEGER NOT NULL DEFAULT 0,
`id` INTEGER PRIMARY KEY AUTOINCREMENT)
""")
database.execSQL("INSERT INTO `Icons` (`type`, `componentName`, `drawable`, `iconPack`, `themed`, `name`) SELECT `type`, `componentName`, `drawable`, `iconPack`, null FROM `Icons_old`")

View File

@ -8,6 +8,7 @@ data class IconPackIcon(
val componentName: ComponentName?,
val drawable: String?,
val iconPack: String,
val themed: Boolean = false,
val name: String? = null,
) {
constructor(entity: IconEntity) : this(
@ -16,6 +17,7 @@ data class IconPackIcon(
drawable = entity.drawable,
iconPack = entity.iconPack,
name = entity.name,
themed = entity.themed,
)
fun toDatabaseEntity(): IconEntity {
@ -25,6 +27,7 @@ data class IconPackIcon(
drawable = drawable,
iconPack = iconPack,
name = name,
themed = themed,
)
}
}

View File

@ -60,7 +60,6 @@ class IconPackManager(
suspend fun getIcon(
iconPack: String,
componentName: ComponentName,
themed: Boolean = false
): LauncherIcon? {
val res = try {
context.packageManager.getResourcesForApplication(iconPack)
@ -75,7 +74,7 @@ class IconPackManager(
val drawableName = icon.drawable ?: return null
if (icon.type == "calendar") {
return getIconPackCalendarIcon(context, iconPack, drawableName, themed)
return getIconPackCalendarIcon(context, iconPack, drawableName, icon.themed)
}
val resId = res.getIdentifier(drawableName, "drawable", iconPack).takeIf { it != 0 }
?: return null
@ -85,7 +84,7 @@ class IconPackManager(
return null
}
return when {
themed && drawable is AdaptiveIconDrawable -> {
icon.themed && drawable is AdaptiveIconDrawable -> {
if (isAtLeastApiLevel(33) && drawable.monochrome != null) {
return StaticLauncherIcon(
foregroundLayer = StaticIconLayer(

View File

@ -122,6 +122,7 @@ class IconPackInstaller(
drawable = drawable,
iconPack = pkgName,
name = name,
themed = iconPack.themed,
type = "app"
)
icons.add(icon)

View File

@ -17,7 +17,7 @@ class IconPackIconProvider(
if (searchable !is LauncherApp) return null
val component = ComponentName(searchable.`package`, searchable.activity)
return iconPackManager.getIcon(iconPack.packageName, component, iconPack.themed)
return iconPackManager.getIcon(iconPack.packageName, component)
?: iconPackManager.generateIcon(
context,
iconPack.packageName,