Add force themed icon to icon suggestions

This commit is contained in:
MM20 2022-08-01 20:28:21 +02:00
parent 6b33d4fcd7
commit 56e8471373
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 38 additions and 19 deletions

View File

@ -93,6 +93,7 @@ sealed class CustomIcon : CustomAttribute {
bgColor = payload.getInt("bg_color")
)
}
"force_themed_icon" -> ForceThemedIcon
else -> null
}
}
@ -152,6 +153,14 @@ data class CustomThemedIcon(
}
}
object ForceThemedIcon : CustomIcon() {
override fun toDatabaseValue(): String {
return jsonObjectOf(
"type" to "force_themed_icon"
).toString()
}
}
/**
* Use default icon, ignore any icon pack, themed icon or force adaptive settings.
*/

View File

@ -163,6 +163,11 @@ class IconRepository(
)
)
}
if (customIcon is ForceThemedIcon) {
return listOf(
ForceThemedIconTransformation()
)
}
if (customIcon is UnmodifiedSystemDefaultIcon) {
return emptyList()
}
@ -190,11 +195,11 @@ class IconRepository(
val defaultTransformations = transformations.first()
val customIcons = mutableListOf<CustomIcon>(UnmodifiedSystemDefaultIcon)
val transformationOptions = mutableListOf<CustomIcon>(UnmodifiedSystemDefaultIcon)
if (rawIcon is StaticLauncherIcon && rawIcon.backgroundLayer is TransparentLayer) {
// Legacy icons that simply fill the entire canvas
customIcons.add(
transformationOptions.add(
AdaptifiedLegacyIcon(
fgScale = 1f,
bgColor = 1
@ -203,39 +208,25 @@ class IconRepository(
// 48x48 with 5px padding used to be the default icon size for icons generated by
// the Android Studio asset generator. Upscale these icons to remove that padding.
customIcons.add(
transformationOptions.add(
AdaptifiedLegacyIcon(
fgScale = 48f / 38f,
bgColor = 1
)
)
customIcons.add(
transformationOptions.add(
AdaptifiedLegacyIcon(
fgScale = 0.7f,
bgColor = 0
)
)
customIcons.add(
transformationOptions.add(
AdaptifiedLegacyIcon(
fgScale = 0.7f,
bgColor = Color.WHITE,
)
)
}
suggestions.addAll(
customIcons.map {
val transformations = getTransformations(it) ?: defaultTransformations
val providers = getProviders(it)
val icon = providers.getFirstIcon(searchable, size) ?: rawIcon
CustomIconWithPreview(
preview = icon.transform(transformations),
customIcon = it,
)
}
)
val providerOptions = mutableListOf<CustomIcon>()
@ -261,9 +252,28 @@ class IconRepository(
iconPackageName = themedIcon.componentName.packageName,
)
)
} else {
transformationOptions.add(
ForceThemedIcon
)
}
}
suggestions.addAll(
transformationOptions.map {
val transformations = getTransformations(it) ?: defaultTransformations
val providers = getProviders(it)
val icon = providers.getFirstIcon(searchable, size) ?: rawIcon
CustomIconWithPreview(
preview = icon.transform(transformations),
customIcon = it,
)
}
)
suggestions.addAll(
providerOptions.mapNotNull {
val providers = getProviders(it)