diff --git a/customattrs/src/main/java/de/mm20/launcher2/customattrs/CustomAttribute.kt b/customattrs/src/main/java/de/mm20/launcher2/customattrs/CustomAttribute.kt index f1bd6e8e..759dfefe 100644 --- a/customattrs/src/main/java/de/mm20/launcher2/customattrs/CustomAttribute.kt +++ b/customattrs/src/main/java/de/mm20/launcher2/customattrs/CustomAttribute.kt @@ -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. */ diff --git a/icons/src/main/java/de/mm20/launcher2/icons/IconRepository.kt b/icons/src/main/java/de/mm20/launcher2/icons/IconRepository.kt index b24bdd2b..94fffd55 100644 --- a/icons/src/main/java/de/mm20/launcher2/icons/IconRepository.kt +++ b/icons/src/main/java/de/mm20/launcher2/icons/IconRepository.kt @@ -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(UnmodifiedSystemDefaultIcon) + val transformationOptions = mutableListOf(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() @@ -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)