Fix crash if adaptive icon foreground or background is null

This commit is contained in:
MM20 2022-06-19 19:39:35 +02:00
parent 3cf0038c70
commit a303703d9e
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
5 changed files with 63 additions and 46 deletions

View File

@ -53,14 +53,18 @@ class LauncherApp(
} ?: return null
if (icon is AdaptiveIconDrawable) {
return StaticLauncherIcon(
foregroundLayer = StaticIconLayer(
icon = icon.foreground,
scale = 1.5f,
),
backgroundLayer = StaticIconLayer(
icon = icon.background,
scale = 1.5f,
)
foregroundLayer = icon.foreground?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
backgroundLayer = icon.background?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
)
} else {
return StaticLauncherIcon(

View File

@ -75,14 +75,18 @@ class AppShortcut(
} ?: return null
if (icon is AdaptiveIconDrawable) {
return StaticLauncherIcon(
foregroundLayer = StaticIconLayer(
icon = icon.foreground,
scale = 1.5f,
),
backgroundLayer = StaticIconLayer(
icon = icon.background,
scale = 1.5f,
)
foregroundLayer = icon.foreground?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
backgroundLayer = icon.background?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
)
}
return StaticLauncherIcon(

View File

@ -15,10 +15,7 @@ import android.util.Size
import androidx.core.content.FileProvider
import androidx.exifinterface.media.ExifInterface
import de.mm20.launcher2.files.R
import de.mm20.launcher2.icons.ColorLayer
import de.mm20.launcher2.icons.LauncherIcon
import de.mm20.launcher2.icons.StaticIconLayer
import de.mm20.launcher2.icons.StaticLauncherIcon
import de.mm20.launcher2.icons.*
import de.mm20.launcher2.ktx.formatToString
import de.mm20.launcher2.media.ThumbnailUtilsCompat
import kotlinx.coroutines.Dispatchers
@ -120,14 +117,18 @@ open class LocalFile(
when {
icon is AdaptiveIconDrawable -> {
return StaticLauncherIcon(
foregroundLayer = StaticIconLayer(
icon = icon.foreground,
scale = 1.5f,
),
backgroundLayer = StaticIconLayer(
icon = icon.background,
scale = 1.5f,
)
foregroundLayer = icon.foreground?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
backgroundLayer = icon.background?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
)
}
else -> {

View File

@ -40,15 +40,19 @@ internal class DynamicCalendarIcon(
backgroundLayer = ColorLayer()
)
} else if (drawable is AdaptiveIconDrawable) {
StaticLauncherIcon(
foregroundLayer = StaticIconLayer(
icon = drawable.foreground,
scale = 1.5f
),
backgroundLayer = StaticIconLayer(
icon = drawable.background,
scale = 1.5f
)
return StaticLauncherIcon(
foregroundLayer = drawable.foreground?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
backgroundLayer = drawable.background?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
)
} else StaticLauncherIcon(
foregroundLayer = StaticIconLayer(

View File

@ -46,15 +46,19 @@ class IconPackIconProvider(
val drawable = ResourcesCompat.getDrawable(res, resId, context.theme) ?: return null
return when {
drawable is AdaptiveIconDrawable -> {
StaticLauncherIcon(
foregroundLayer = StaticIconLayer(
icon = drawable.foreground,
scale = 1.5f
),
backgroundLayer = StaticIconLayer(
icon = drawable.background,
scale = 1.5f
)
return StaticLauncherIcon(
foregroundLayer = drawable.foreground?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
backgroundLayer = drawable.background?.let {
StaticIconLayer(
icon = it,
scale = 1.5f,
)
} ?: TransparentLayer,
)
}
else -> {