From e821f26ad95c6123d7485e0936879dcb99315fbd Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Tue, 26 Sep 2023 09:29:43 +0300 Subject: [PATCH] Fix system font option closes #81 --- .../java/com/sadellie/unitto/UnittoApp.kt | 6 +- .../ui/common/textfield/InputTextField.kt | 6 +- .../com/sadellie/unitto/core/ui/theme/Type.kt | 362 +++++++----------- .../calculator/components/HistoryList.kt | 6 +- .../settings/formatting/FormattingScreen.kt | 4 +- .../unitto/timezone/TimeZoneScreen.kt | 4 +- 6 files changed, 151 insertions(+), 237 deletions(-) diff --git a/app/src/main/java/com/sadellie/unitto/UnittoApp.kt b/app/src/main/java/com/sadellie/unitto/UnittoApp.kt index af8957c6..93d72b12 100644 --- a/app/src/main/java/com/sadellie/unitto/UnittoApp.kt +++ b/app/src/main/java/com/sadellie/unitto/UnittoApp.kt @@ -47,8 +47,8 @@ import com.sadellie.unitto.core.ui.common.open import com.sadellie.unitto.core.ui.common.rememberUnittoDrawerState import com.sadellie.unitto.core.ui.model.DrawerItems import com.sadellie.unitto.core.ui.pushDynamicShortcut -import com.sadellie.unitto.core.ui.theme.AppTypographySystem -import com.sadellie.unitto.core.ui.theme.AppTypographyUnitto +import com.sadellie.unitto.core.ui.theme.TypographySystem +import com.sadellie.unitto.core.ui.theme.TypographyUnitto import com.sadellie.unitto.core.ui.theme.DarkThemeColors import com.sadellie.unitto.core.ui.theme.LightThemeColors import com.sadellie.unitto.data.userprefs.AppPreferences @@ -107,7 +107,7 @@ internal fun UnittoApp(prefs: AppPreferences) { Themmo( themmoController = themmoController, - typography = if (prefs.systemFont) AppTypographySystem else AppTypographyUnitto, + typography = if (prefs.systemFont) TypographySystem else TypographyUnitto, animationSpec = tween(250) ) { val backgroundColor = MaterialTheme.colorScheme.background diff --git a/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/InputTextField.kt b/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/InputTextField.kt index e07348c5..50892c21 100644 --- a/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/InputTextField.kt +++ b/core/ui/src/main/java/com/sadellie/unitto/core/ui/common/textfield/InputTextField.kt @@ -59,7 +59,7 @@ import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.sp -import com.sadellie.unitto.core.ui.theme.NumbersTextStyleDisplayLarge +import com.sadellie.unitto.core.ui.theme.numbersDisplayLarge import kotlin.math.ceil import kotlin.math.roundToInt @@ -105,7 +105,7 @@ fun ExpressionTextField( modifier = modifier, value = value, formattedValue = value.text.formatExpression(formatterSymbols), - textStyle = NumbersTextStyleDisplayLarge.copy(color = textColor), + textStyle = MaterialTheme.typography.numbersDisplayLarge.copy(color = textColor), minRatio = minRatio, onValueChange = { onCursorChange(it.selection) }, readOnly = readOnly, @@ -157,7 +157,7 @@ fun UnformattedTextField( AutoSizableTextField( modifier = modifier, value = value, - textStyle = NumbersTextStyleDisplayLarge.copy(color = textColor), + textStyle = MaterialTheme.typography.numbersDisplayLarge.copy(color = textColor), minRatio = minRatio, onValueChange = { onCursorChange(it.selection) }, readOnly = readOnly, diff --git a/core/ui/src/main/java/com/sadellie/unitto/core/ui/theme/Type.kt b/core/ui/src/main/java/com/sadellie/unitto/core/ui/theme/Type.kt index 1ad0935e..a825dde5 100644 --- a/core/ui/src/main/java/com/sadellie/unitto/core/ui/theme/Type.kt +++ b/core/ui/src/main/java/com/sadellie/unitto/core/ui/theme/Type.kt @@ -27,232 +27,146 @@ import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp import com.sadellie.unitto.core.base.R -val Montserrat = FontFamily( - Font(R.font.montserrat_light, weight = FontWeight.Light), - Font(R.font.montserrat_regular, weight = FontWeight.Normal), - Font(R.font.montserrat_medium, weight = FontWeight.Medium), - Font(R.font.montserrat_semibold, weight = FontWeight.SemiBold), -) - -val Lato = FontFamily( - Font(R.font.lato_regular) -) - // This text style is used for text field -val NumbersTextStyleDisplayLarge = TextStyle( - fontFamily = Lato, - fontWeight = FontWeight.W400, - fontSize = 57.sp, - lineHeight = (1.4).em, - letterSpacing = (-0.25).sp, -) +val Typography.numbersDisplayLarge by lazy { + TextStyle( + fontFamily = latoFamily, + fontWeight = FontWeight.W400, + fontSize = 57.sp, + lineHeight = (1.4).em, + letterSpacing = (-0.25).sp, + ) +} // This text style is used for secondary text field -val NumbersTextStyleDisplayMedium = TextStyle( - fontFamily = Lato, - fontWeight = FontWeight.W400, - fontSize = 38.sp, - lineHeight = 42.sp, - letterSpacing = (-0.25).sp, -) - -val AppTypographyUnitto = Typography( - displayLarge = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 57.sp, - lineHeight = 64.sp, +val Typography.numbersDisplayMedium by lazy { + TextStyle( + fontFamily = latoFamily, + fontWeight = FontWeight.W400, + fontSize = 38.sp, + lineHeight = 42.sp, letterSpacing = (-0.25).sp, - ), - displayMedium = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 45.sp, - lineHeight = 52.sp, - letterSpacing = 0.sp, - ), - displaySmall = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 36.sp, - lineHeight = 44.sp, - letterSpacing = 0.sp, - ), - headlineLarge = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 32.sp, - lineHeight = 40.sp, - letterSpacing = 0.sp, - ), - headlineMedium = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 28.sp, - lineHeight = 36.sp, - letterSpacing = 0.sp, - ), - headlineSmall = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 24.sp, - lineHeight = 32.sp, - letterSpacing = 0.sp, - ), - titleLarge = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Medium, - fontSize = 22.sp, - lineHeight = 28.sp, - letterSpacing = 0.sp, - ), - titleMedium = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Bold, - fontSize = 18.sp, - lineHeight = 24.sp, - letterSpacing = 0.1.sp, - ), - titleSmall = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Medium, - fontSize = 14.sp, - lineHeight = 20.sp, - letterSpacing = 0.1.sp, - ), - bodyLarge = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 16.sp, - lineHeight = 24.sp, - letterSpacing = 0.5.sp, - ), - bodyMedium = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 14.sp, - lineHeight = 20.sp, - letterSpacing = 0.25.sp, - ), - bodySmall = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Normal, - fontSize = 12.sp, - lineHeight = 16.sp, - letterSpacing = 0.4.sp, - ), - labelLarge = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Medium, - fontSize = 14.sp, - lineHeight = 20.sp, - letterSpacing = 0.1.sp, - ), - labelMedium = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Medium, - fontSize = 12.sp, - lineHeight = 16.sp, - letterSpacing = 0.5.sp, - ), - labelSmall = TextStyle( - fontFamily = Montserrat, - fontWeight = FontWeight.Medium, - fontSize = 10.sp, - lineHeight = 16.sp, - letterSpacing = 0.sp, - ), -) + ) +} + +val TypographyUnitto by lazy { + Typography( + displayLarge = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 57.sp, + lineHeight = 64.sp, + letterSpacing = (-0.25).sp, + ), + displayMedium = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 45.sp, + lineHeight = 52.sp, + letterSpacing = 0.sp, + ), + displaySmall = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 36.sp, + lineHeight = 44.sp, + letterSpacing = 0.sp, + ), + headlineLarge = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 32.sp, + lineHeight = 40.sp, + letterSpacing = 0.sp, + ), + headlineMedium = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 28.sp, + lineHeight = 36.sp, + letterSpacing = 0.sp, + ), + headlineSmall = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 24.sp, + lineHeight = 32.sp, + letterSpacing = 0.sp, + ), + titleLarge = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Medium, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp, + ), + titleMedium = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Bold, + fontSize = 18.sp, + lineHeight = 24.sp, + letterSpacing = 0.1.sp, + ), + titleSmall = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.1.sp, + ), + bodyLarge = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp, + ), + bodyMedium = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.25.sp, + ), + bodySmall = TextStyle( + fontFamily = montserratFamily, + fontWeight = FontWeight.Normal, + fontSize = 12.sp, + lineHeight = 16.sp, + letterSpacing = 0.4.sp, + ), + labelLarge = TextStyle( + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.1.sp, + ), + labelMedium = TextStyle( + fontWeight = FontWeight.Medium, + fontSize = 12.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp, + ), + labelSmall = TextStyle( + fontWeight = FontWeight.Medium, + fontSize = 10.sp, + lineHeight = 16.sp, + letterSpacing = 0.sp, + ), + ) +} -val AppTypographySystem = Typography( - displayLarge = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 57.sp, - lineHeight = 64.sp, - letterSpacing = (-0.25).sp, - ), - displayMedium = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 45.sp, - lineHeight = 52.sp, - letterSpacing = 0.sp, - ), - displaySmall = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 36.sp, - lineHeight = 44.sp, - letterSpacing = 0.sp, - ), - headlineLarge = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 32.sp, - lineHeight = 40.sp, - letterSpacing = 0.sp, - ), - headlineMedium = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 28.sp, - lineHeight = 36.sp, - letterSpacing = 0.sp, - ), - headlineSmall = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 24.sp, - lineHeight = 32.sp, - letterSpacing = 0.sp, - ), - titleLarge = TextStyle( - fontWeight = FontWeight.Medium, - fontSize = 22.sp, - lineHeight = 28.sp, - letterSpacing = 0.sp, - ), - titleMedium = TextStyle( - fontWeight = FontWeight.Bold, - fontSize = 18.sp, - lineHeight = 24.sp, - letterSpacing = 0.1.sp, - ), - titleSmall = TextStyle( - fontWeight = FontWeight.Medium, - fontSize = 14.sp, - lineHeight = 20.sp, - letterSpacing = 0.1.sp, - ), - bodyLarge = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 16.sp, - lineHeight = 24.sp, - letterSpacing = 0.5.sp, - ), - bodyMedium = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 14.sp, - lineHeight = 20.sp, - letterSpacing = 0.25.sp, - ), - bodySmall = TextStyle( - fontWeight = FontWeight.Normal, - fontSize = 12.sp, - lineHeight = 16.sp, - letterSpacing = 0.4.sp, - ), - labelLarge = TextStyle( - fontWeight = FontWeight.Medium, - fontSize = 14.sp, - lineHeight = 20.sp, - letterSpacing = 0.1.sp, - ), - labelMedium = TextStyle( - fontWeight = FontWeight.Medium, - fontSize = 12.sp, - lineHeight = 16.sp, - letterSpacing = 0.5.sp, - ), - labelSmall = TextStyle( - fontWeight = FontWeight.Medium, - fontSize = 10.sp, - lineHeight = 16.sp, - letterSpacing = 0.sp, - ), -) +val TypographySystem by lazy { Typography() } + +private val montserratFamily by lazy { + FontFamily( + Font(R.font.montserrat_light, weight = FontWeight.Light), + Font(R.font.montserrat_regular, weight = FontWeight.Normal), + Font(R.font.montserrat_medium, weight = FontWeight.Medium), + Font(R.font.montserrat_semibold, weight = FontWeight.SemiBold), + ) +} + +private val latoFamily by lazy { + FontFamily(Font(R.font.lato_regular)) +} diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt index edd01a34..79f6c37b 100644 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt +++ b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt @@ -66,7 +66,7 @@ import com.sadellie.unitto.core.ui.common.textfield.FormatterSymbols import com.sadellie.unitto.core.ui.common.textfield.UnittoTextToolbar import com.sadellie.unitto.core.ui.common.textfield.clearAndFilterExpression import com.sadellie.unitto.core.ui.common.textfield.copyWithoutGrouping -import com.sadellie.unitto.core.ui.theme.NumbersTextStyleDisplayMedium +import com.sadellie.unitto.core.ui.theme.numbersDisplayMedium import com.sadellie.unitto.data.model.HistoryItem import java.text.SimpleDateFormat import java.util.Locale @@ -212,7 +212,7 @@ private fun HistoryListItem( .fillMaxWidth() .padding(horizontal = 8.dp) .horizontalScroll(rememberScrollState(), reverseScrolling = true), - textStyle = NumbersTextStyleDisplayMedium.copy(color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.End), + textStyle = MaterialTheme.typography.numbersDisplayMedium.copy(color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.End), readOnly = true, visualTransformation = ExpressionTransformer(formatterSymbols), interactionSource = expressionInteractionSource @@ -237,7 +237,7 @@ private fun HistoryListItem( .fillMaxWidth() .padding(horizontal = 8.dp) .horizontalScroll(rememberScrollState(), reverseScrolling = true), - textStyle = NumbersTextStyleDisplayMedium.copy(color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f), textAlign = TextAlign.End), + textStyle = MaterialTheme.typography.numbersDisplayMedium.copy(color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f), textAlign = TextAlign.End), readOnly = true, visualTransformation = ExpressionTransformer(formatterSymbols), interactionSource = resultInteractionSource diff --git a/feature/settings/src/main/java/com/sadellie/unitto/feature/settings/formatting/FormattingScreen.kt b/feature/settings/src/main/java/com/sadellie/unitto/feature/settings/formatting/FormattingScreen.kt index 6fb80879..cce34705 100644 --- a/feature/settings/src/main/java/com/sadellie/unitto/feature/settings/formatting/FormattingScreen.kt +++ b/feature/settings/src/main/java/com/sadellie/unitto/feature/settings/formatting/FormattingScreen.kt @@ -62,7 +62,7 @@ import com.sadellie.unitto.core.ui.common.UnittoScreenWithLargeTopBar import com.sadellie.unitto.core.ui.common.UnittoSlider import com.sadellie.unitto.core.ui.common.squashable import com.sadellie.unitto.core.ui.common.textfield.formatExpression -import com.sadellie.unitto.core.ui.theme.NumbersTextStyleDisplayMedium +import com.sadellie.unitto.core.ui.theme.numbersDisplayMedium import kotlin.math.roundToInt @Composable @@ -135,7 +135,7 @@ fun FormattingScreen( ) Text( text = uiState.preview, - style = NumbersTextStyleDisplayMedium, + style = MaterialTheme.typography.numbersDisplayMedium, maxLines = 1, modifier = Modifier .fillMaxWidth() diff --git a/feature/timezone/src/main/java/com/sadellie/unitto/timezone/TimeZoneScreen.kt b/feature/timezone/src/main/java/com/sadellie/unitto/timezone/TimeZoneScreen.kt index 628d0100..55ae0560 100644 --- a/feature/timezone/src/main/java/com/sadellie/unitto/timezone/TimeZoneScreen.kt +++ b/feature/timezone/src/main/java/com/sadellie/unitto/timezone/TimeZoneScreen.kt @@ -85,7 +85,7 @@ import com.sadellie.unitto.core.ui.common.UnittoScreenWithTopBar import com.sadellie.unitto.core.ui.common.squashable import com.sadellie.unitto.core.ui.datetime.UnittoDateTimeFormatter import com.sadellie.unitto.core.ui.datetime.formatLocal -import com.sadellie.unitto.core.ui.theme.AppTypographyUnitto +import com.sadellie.unitto.core.ui.theme.TypographyUnitto import com.sadellie.unitto.core.ui.theme.DarkThemeColors import com.sadellie.unitto.core.ui.theme.LightThemeColors import com.sadellie.unitto.data.model.UnittoTimeZone @@ -355,7 +355,7 @@ fun PreviewTimeZoneScreen() { lightColorScheme = LightThemeColors, darkColorScheme = DarkThemeColors, ), - typography = AppTypographyUnitto, + typography = TypographyUnitto, ) { TimeZoneScreen( uiState = TimeZoneUIState(