From c35387a9fb3afe41d9b7702e1bd363ca5935be44 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Mon, 11 Jul 2022 23:17:35 +0200 Subject: [PATCH] Fix crash when device headline font family is blank --- .../typography/fontfamily/DeviceDefault.kt | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/ui/src/main/java/de/mm20/launcher2/ui/theme/typography/fontfamily/DeviceDefault.kt b/ui/src/main/java/de/mm20/launcher2/ui/theme/typography/fontfamily/DeviceDefault.kt index 8cbb348a..d6c72765 100644 --- a/ui/src/main/java/de/mm20/launcher2/ui/theme/typography/fontfamily/DeviceDefault.kt +++ b/ui/src/main/java/de/mm20/launcher2/ui/theme/typography/fontfamily/DeviceDefault.kt @@ -11,26 +11,33 @@ fun getDeviceHeadlineFontFamily(context: Context): FontFamily { if (configResId != 0) { val fontFamily = context.resources.getString(configResId) - return FontFamily( - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Thin, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraLight, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Light, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Normal, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Medium, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.SemiBold, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Bold, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraBold, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Black, style = FontStyle.Normal), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Thin, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraLight, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Light, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Normal, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Medium, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.SemiBold, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Bold, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraBold, style = FontStyle.Italic), - Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Black, style = FontStyle.Italic), - ) + + if (fontFamily.isBlank()) return FontFamily.SansSerif + + return try { + FontFamily( + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Thin, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraLight, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Light, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Normal, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Medium, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.SemiBold, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Bold, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraBold, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Black, style = FontStyle.Normal), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Thin, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraLight, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Light, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Normal, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Medium, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.SemiBold, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Bold, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.ExtraBold, style = FontStyle.Italic), + Font(DeviceFontFamilyName(fontFamily), weight = FontWeight.Black, style = FontStyle.Italic), + ) + } catch (e: IllegalArgumentException) { + FontFamily.SansSerif + } } return FontFamily.SansSerif