Typography schemes: Add more font slots
This commit is contained in:
@@ -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
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
core/base/src/main/res/drawable/custom_typography_24px.xml
Normal file
10
core/base/src/main/res/drawable/custom_typography_24px.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M520,800L520,840Q520,857 508.5,868.5Q497,880 480,880Q463,880 451.5,868.5Q440,857 440,840L440,680Q440,663 451.5,651.5Q463,640 480,640Q497,640 508.5,651.5Q520,663 520,680L520,720L800,720Q817,720 828.5,731.5Q840,743 840,760Q840,777 828.5,788.5Q817,800 800,800L520,800ZM160,800Q143,800 131.5,788.5Q120,777 120,760Q120,743 131.5,731.5Q143,720 160,720L320,720Q337,720 348.5,731.5Q360,743 360,760Q360,777 348.5,788.5Q337,800 320,800L160,800ZM384,437L577,437L611,535Q615,546 625,553Q635,560 647,560Q667,560 679,543Q691,526 683,507L533,106Q528,94 518,87Q508,80 495,80L465,80Q452,80 442,87Q432,94 427,106L276,508Q269,527 280.5,543.5Q292,560 312,560Q325,560 334.5,553Q344,546 349,534L384,437ZM408,368L478,169L482,169L552,368L408,368Z"/>
|
||||
</vector>
|
||||
@@ -1067,7 +1067,9 @@
|
||||
<string name="theme_import_title">Import theme</string>
|
||||
<string name="theme_bundle_name">Name</string>
|
||||
<string name="theme_bundle_author">Author</string>
|
||||
<string name="preference_typography_fonts">Fonts</string>
|
||||
<string name="preference_typography_fonts">Font styles</string>
|
||||
<string name="add_font_style">Add font style</string>
|
||||
<string name="remove_font_style">Remove this font style</string>
|
||||
<string name="font_category_device_default">Device default</string>
|
||||
<string name="font_name_device_headline">Default headline font</string>
|
||||
<string name="font_name_device_body">Device text font</string>
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user