diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/typography/TypographySettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/typography/TypographySettingsScreen.kt index 6a2b294ab..ae6f00bfd 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/typography/TypographySettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/typography/TypographySettingsScreen.kt @@ -26,6 +26,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.FilledTonalButton import androidx.compose.material3.FilterChip import androidx.compose.material3.FilterChipDefaults import androidx.compose.material3.HorizontalDivider @@ -56,6 +57,7 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.capitalize import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.intl.Locale import androidx.compose.ui.text.intl.LocaleList import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -162,6 +164,52 @@ fun TypographySettingsScreen(themeId: UUID) { ) } ) + for (key in theme!!.fonts.keys.sorted()) { + if (key == "plain" || key == "brand") continue + FontPreference( + title = key.capitalize(Locale.current), + theme!!.fonts[key], + removable = true, + onValueChange = { + viewModel.updateTypography( + theme!!.copy( + fonts = theme!!.fonts.toMutableMap().apply { + if (it == null) { + remove(key) + } else { + put(key, it) + } + } + ) + ) + } + ) + } + } + } + if (theme!!.fonts.size < 8) { + item { + FilledTonalButton( + contentPadding = ButtonDefaults.ButtonWithIconContentPadding, + onClick = { + val firstFreeIndex = (1 .. 8).firstOrNull { + !theme!!.fonts.containsKey("custom $it") + } + if (firstFreeIndex != null) { + viewModel.updateTypography( + theme!!.copy( + fonts = theme!!.fonts.toMutableMap() + .apply { put("custom $firstFreeIndex", ThemeFontFamily.SansSerif) }) + ) + } + }) { + Icon( + painterResource(R.drawable.add_20px), + null, + modifier = Modifier.padding(end = ButtonDefaults.IconSpacing).size(ButtonDefaults.IconSize) + ) + Text(stringResource(R.string.add_font_style)) + } } } item { @@ -709,6 +757,7 @@ fun TypographySettingsScreen(themeId: UUID) { private fun FontPreference( title: String, value: ThemeFontFamily?, + removable: Boolean = false, onValueChange: (ThemeFontFamily?) -> Unit = {}, ) { val context = LocalContext.current @@ -765,7 +814,7 @@ private fun FontPreference( modifier = Modifier.padding(horizontal = 12.dp), onClick = { showFontSettings = true } ) { - Icon(painterResource(R.drawable.tune_24px), null) + Icon(painterResource(R.drawable.custom_typography_24px), null) } } } @@ -821,6 +870,27 @@ private fun FontPreference( }) } } + + if (removable) { + item { + PreferenceCategory() { + Preference( + title = stringResource(R.string.remove_font_style), + icon = { + Icon( + painterResource(R.drawable.delete_24px), + null, + tint = MaterialTheme.colorScheme.error, + ) + }, + onClick = { + onValueChange(null) + showDialog = false + } + ) + } + } + } } } diff --git a/core/base/src/main/res/drawable/custom_typography_24px.xml b/core/base/src/main/res/drawable/custom_typography_24px.xml new file mode 100644 index 000000000..ee7a009c6 --- /dev/null +++ b/core/base/src/main/res/drawable/custom_typography_24px.xml @@ -0,0 +1,10 @@ + + + diff --git a/core/i18n/src/main/res/values/strings.xml b/core/i18n/src/main/res/values/strings.xml index 3b736b39f..16a960d96 100644 --- a/core/i18n/src/main/res/values/strings.xml +++ b/core/i18n/src/main/res/values/strings.xml @@ -1067,7 +1067,9 @@ Import theme Name Author - Fonts + Font styles + Add font style + Remove this font style Device default Default headline font Device text font diff --git a/data/themes/build.gradle.kts b/data/themes/build.gradle.kts index d79068340..dfbec098e 100644 --- a/data/themes/build.gradle.kts +++ b/data/themes/build.gradle.kts @@ -48,6 +48,7 @@ dependencies { implementation(libs.koin.android) implementation(project(":core:base")) + implementation(project(":core:ktx")) implementation(project(":data:database")) implementation(project(":core:crashreporter")) implementation(project(":core:preferences"))