From 960c3b70f56049bc0e66fe0f5c7b07bffb2caf3d Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sat, 5 Nov 2022 14:58:11 +0100 Subject: [PATCH] Add custom icon transformation for legacy round icons --- .../de/mm20/launcher2/icons/IconRepository.kt | 54 ++++++++++++++++--- .../preferences/migrations/Migration_11_12.kt | 20 ------- 2 files changed, 46 insertions(+), 28 deletions(-) delete mode 100644 preferences/src/main/java/de/mm20/launcher2/preferences/migrations/Migration_11_12.kt 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 c444fec6..adbfa6e6 100644 --- a/icons/src/main/java/de/mm20/launcher2/icons/IconRepository.kt +++ b/icons/src/main/java/de/mm20/launcher2/icons/IconRepository.kt @@ -6,8 +6,25 @@ import android.content.Intent import android.content.IntentFilter import android.graphics.Color import android.util.LruCache -import de.mm20.launcher2.customattrs.* -import de.mm20.launcher2.icons.providers.* +import de.mm20.launcher2.customattrs.AdaptifiedLegacyIcon +import de.mm20.launcher2.customattrs.CustomAttributesRepository +import de.mm20.launcher2.customattrs.CustomIcon +import de.mm20.launcher2.customattrs.CustomIconPackIcon +import de.mm20.launcher2.customattrs.CustomThemedIcon +import de.mm20.launcher2.customattrs.DefaultPlaceholderIcon +import de.mm20.launcher2.customattrs.ForceThemedIcon +import de.mm20.launcher2.customattrs.UnmodifiedSystemDefaultIcon +import de.mm20.launcher2.icons.providers.CalendarIconProvider +import de.mm20.launcher2.icons.providers.CustomIconPackIconProvider +import de.mm20.launcher2.icons.providers.CustomThemedIconProvider +import de.mm20.launcher2.icons.providers.GoogleClockIconProvider +import de.mm20.launcher2.icons.providers.IconPackIconProvider +import de.mm20.launcher2.icons.providers.IconProvider +import de.mm20.launcher2.icons.providers.PlaceholderIconProvider +import de.mm20.launcher2.icons.providers.SystemIconProvider +import de.mm20.launcher2.icons.providers.ThemedIconProvider +import de.mm20.launcher2.icons.providers.ThemedPlaceholderIconProvider +import de.mm20.launcher2.icons.providers.getFirstIcon import de.mm20.launcher2.icons.transformations.ForceThemedIconTransformation import de.mm20.launcher2.icons.transformations.LauncherIconTransformation import de.mm20.launcher2.icons.transformations.LegacyToAdaptiveTransformation @@ -18,7 +35,13 @@ import de.mm20.launcher2.search.data.LauncherApp import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.channelFlow +import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch class IconRepository( @@ -88,7 +111,9 @@ class IconRepository( val transformations = mutableListOf() if (settings.adaptify) transformations.add(LegacyToAdaptiveTransformation()) - if (settings.themedIcons && settings.forceThemed) transformations.add(ForceThemedIconTransformation()) + if (settings.themedIcons && settings.forceThemed) transformations.add( + ForceThemedIconTransformation() + ) this@IconRepository.placeholderProvider = placeholderProvider iconProviders.value = providers @@ -217,6 +242,14 @@ class IconRepository( bgColor = 1 ) ) + + // Android 7.1 round icons (48x48 circle with 1px padding) + transformationOptions.add( + AdaptifiedLegacyIcon( + fgScale = 48f / 44f, + bgColor = 1 + ) + ) transformationOptions.add( AdaptifiedLegacyIcon( fgScale = 0.7f, @@ -301,7 +334,10 @@ class IconRepository( } - suspend fun getUncustomizedDefaultIcon(searchable: SavableSearchable, size: Int): CustomIconWithPreview? { + suspend fun getUncustomizedDefaultIcon( + searchable: SavableSearchable, + size: Int + ): CustomIconWithPreview? { val icon = iconProviders.first().getFirstIcon(searchable, size) ?.transform(transformations.first()) ?: return null return CustomIconWithPreview( @@ -312,7 +348,7 @@ class IconRepository( suspend fun searchCustomIcons(query: String): List { val transformations = this.transformations.first() - val iconPackIcons = iconPackManager.searchIconPackIcon(query).mapNotNull { + val iconPackIcons = iconPackManager.searchIconPackIcon(query).mapNotNull { val componentName = it.componentName ?: return@mapNotNull null CustomIconWithPreview( @@ -320,7 +356,8 @@ class IconRepository( iconPackPackage = it.iconPack, iconComponentName = componentName.flattenToString(), ), - preview = iconPackManager.getIcon(it.iconPack, componentName)?.transform(transformations) ?: return@mapNotNull null + preview = iconPackManager.getIcon(it.iconPack, componentName) + ?.transform(transformations) ?: return@mapNotNull null ) } @@ -331,7 +368,8 @@ class IconRepository( customIcon = CustomThemedIcon( iconPackageName = componentName.packageName, ), - preview = iconPackManager.getThemedIcon(componentName.packageName)?.transform(transformations) ?: return@mapNotNull null + preview = iconPackManager.getThemedIcon(componentName.packageName) + ?.transform(transformations) ?: return@mapNotNull null ) } diff --git a/preferences/src/main/java/de/mm20/launcher2/preferences/migrations/Migration_11_12.kt b/preferences/src/main/java/de/mm20/launcher2/preferences/migrations/Migration_11_12.kt deleted file mode 100644 index f15c012e..00000000 --- a/preferences/src/main/java/de/mm20/launcher2/preferences/migrations/Migration_11_12.kt +++ /dev/null @@ -1,20 +0,0 @@ -package de.mm20.launcher2.preferences.migrations - -import de.mm20.launcher2.preferences.Settings - -class Migration_11_12: VersionedMigration(11, 12) { - override suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder { - return builder - .setSearchActions( - Settings.SearchActionSettings.newBuilder() - .setCall(true) - .setContact(true) - .setEmail(true) - .setMessage(true) - .setOpenUrl(true) - .setScheduleEvent(true) - .setSetAlarm(true) - .setStartTimer(true) - ) - } -} \ No newline at end of file