Revert "Remove System font option"

This reverts commit 24f03b9d3d218c4fb01c8b900c3413fc9d203bfa.
This commit is contained in:
Sad Ellie 2023-12-06 22:34:15 +03:00
parent 66c10744c2
commit 92953d1c99
14 changed files with 85 additions and 22 deletions

View File

@ -35,6 +35,9 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.sadellie.unitto.core.ui.LocalLocale
import com.sadellie.unitto.core.ui.LocalWindowSize
import com.sadellie.unitto.core.ui.calculateWindowSizeClass
import com.sadellie.unitto.core.ui.theme.LocalNumberTypography
import com.sadellie.unitto.core.ui.theme.NumberTypographySystem
import com.sadellie.unitto.core.ui.theme.NumberTypographyUnitto
import com.sadellie.unitto.data.model.repository.UserPreferencesRepository
import dagger.hilt.android.AndroidEntryPoint
import java.util.Locale
@ -59,9 +62,14 @@ internal class MainActivity : AppCompatActivity() {
ConfigurationCompat.getLocales(configuration).get(0) ?: Locale.getDefault()
}
val numbersTypography = remember(prefs?.systemFont) {
if (prefs?.systemFont == true) NumberTypographySystem else NumberTypographyUnitto
}
CompositionLocalProvider(
LocalLocale provides locale,
LocalWindowSize provides calculateWindowSizeClass(this@MainActivity)
LocalWindowSize provides calculateWindowSizeClass(this@MainActivity),
LocalNumberTypography provides numbersTypography
) {
UnittoApp(prefs)
}

View File

@ -42,7 +42,7 @@ import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.sadellie.unitto.core.ui.theme.NumberTypographyUnitto
import com.sadellie.unitto.core.ui.theme.LocalNumberTypography
@Composable
fun FixedInputTextField(
@ -83,7 +83,7 @@ fun FixedInputTextField(
.fillMaxWidth()
.padding(horizontal = 8.dp)
.horizontalScroll(rememberScrollState(), reverseScrolling = true),
textStyle = NumberTypographyUnitto.displaySmall.copy(color = textColor, textAlign = TextAlign.End),
textStyle = LocalNumberTypography.current.displaySmall.copy(color = textColor, textAlign = TextAlign.End),
readOnly = true,
visualTransformation = ExpressionTransformer(formatterSymbols),
interactionSource = expressionInteractionSource

View File

@ -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.NumberTypographyUnitto
import com.sadellie.unitto.core.ui.theme.LocalNumberTypography
import kotlin.math.ceil
import kotlin.math.roundToInt
@ -110,7 +110,7 @@ fun ExpressionTextField(
modifier = modifier,
value = value,
formattedValue = value.text.formatExpression(formatterSymbols),
textStyle = NumberTypographyUnitto.displayLarge.copy(color = textColor),
textStyle = LocalNumberTypography.current.displayLarge.copy(color = textColor),
minRatio = minRatio,
onValueChange = { onCursorChange(it.selection) },
readOnly = readOnly,
@ -165,7 +165,7 @@ fun UnformattedTextField(
AutoSizableTextField(
modifier = modifier,
value = value,
textStyle = NumberTypographyUnitto.displayLarge.copy(color = textColor),
textStyle = LocalNumberTypography.current.displayLarge.copy(color = textColor),
minRatio = minRatio,
onValueChange = { onCursorChange(it.selection) },
readOnly = readOnly,

View File

@ -24,7 +24,9 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
@ -41,6 +43,14 @@ data class NumberTypography(
val displaySmall: TextStyle,
)
val NumberTypographySystem by lazy {
NumberTypography(
displayLarge = TypographySystem.displayLarge,
displayMedium = TypographySystem.displayMedium,
displaySmall = TypographySystem.displaySmall,
)
}
val NumberTypographyUnitto by lazy {
NumberTypography(
displayLarge = TextStyle(
@ -67,6 +77,8 @@ val NumberTypographyUnitto by lazy {
)
}
val LocalNumberTypography = staticCompositionLocalOf { NumberTypographySystem }
val TypographySystem by lazy { Typography() }
private val FontFamily.Companion.lato: FontFamily
@ -111,10 +123,13 @@ private fun PreviewSystemTypography() {
@Preview(widthDp = 480)
@Composable
private fun PreviewNumberTypography() {
CompositionLocalProvider(
LocalNumberTypography provides NumberTypographyUnitto
) {
val textStyles = mapOf(
"displayLarge" to NumberTypographyUnitto.displayLarge,
"displayMedium" to NumberTypographyUnitto.displayMedium,
"displaySmall" to NumberTypographyUnitto.displaySmall,
"displayLarge" to LocalNumberTypography.current.displayLarge,
"displayMedium" to LocalNumberTypography.current.displayMedium,
"displaySmall" to LocalNumberTypography.current.displaySmall,
)
LazyColumn(Modifier.background(MaterialTheme.colorScheme.background)) {
@ -128,4 +143,5 @@ private fun PreviewNumberTypography() {
}
}
}
}
}

View File

@ -81,6 +81,8 @@ interface UserPreferencesRepository {
suspend fun updateUnitConverterSorting(sorting: UnitsListSorting)
suspend fun updateSystemFont(enabled: Boolean)
suspend fun updatePartialHistoryView(enabled: Boolean)
suspend fun updateAcButton(enabled: Boolean)

View File

@ -26,5 +26,6 @@ interface AppPreferences {
val monetMode: String
val startingScreen: String
val enableToolsExperiment: Boolean
val systemFont: Boolean
val rpnMode: Boolean
}

View File

@ -19,6 +19,7 @@
package com.sadellie.unitto.data.model.userprefs
interface DisplayPreferences {
val systemFont: Boolean
val middleZero: Boolean
val acButton: Boolean
}

View File

@ -55,6 +55,10 @@ fun Preferences.getEnableToolsExperiment(): Boolean {
return this[PrefsKeys.ENABLE_TOOLS_EXPERIMENT] ?: false
}
fun Preferences.getSystemFont(): Boolean {
return this[PrefsKeys.SYSTEM_FONT] ?: false
}
fun Preferences.getEnableVibrations(): Boolean {
return this[PrefsKeys.ENABLE_VIBRATIONS] ?: true
}

View File

@ -40,6 +40,7 @@ data class AppPreferencesImpl(
override val monetMode: String,
override val startingScreen: String,
override val enableToolsExperiment: Boolean,
override val systemFont: Boolean,
override val rpnMode: Boolean,
) : AppPreferences
@ -76,6 +77,7 @@ data class ConverterPreferencesImpl(
) : ConverterPreferences
data class DisplayPreferencesImpl(
override val systemFont: Boolean,
override val middleZero: Boolean,
override val acButton: Boolean,
) : DisplayPreferences

View File

@ -32,7 +32,7 @@ object PrefsKeys {
val MONET_MODE = stringPreferencesKey("MONET_MODE_PREF_KEY")
val STARTING_SCREEN = stringPreferencesKey("STARTING_SCREEN_PREF_KEY")
val ENABLE_TOOLS_EXPERIMENT = booleanPreferencesKey("ENABLE_TOOLS_EXPERIMENT_PREF_KEY")
// val SYSTEM_FONT = booleanPreferencesKey("SYSTEM_FONT_PREF_KEY")
val SYSTEM_FONT = booleanPreferencesKey("SYSTEM_FONT_PREF_KEY")
val ENABLE_VIBRATIONS = booleanPreferencesKey("ENABLE_VIBRATIONS_PREF_KEY")
val MIDDLE_ZERO = booleanPreferencesKey("MIDDLE_ZERO_PREF_KEY")
val AC_BUTTON = booleanPreferencesKey("AC_BUTTON_PREF_KEY")

View File

@ -58,6 +58,7 @@ class UserPreferencesRepositoryImpl @Inject constructor(
monetMode = preferences.getMonetMode(),
startingScreen = preferences.getStartingScreen(),
enableToolsExperiment = preferences.getEnableToolsExperiment(),
systemFont = preferences.getSystemFont(),
rpnMode = preferences.getRpnMode(),
)
}
@ -106,6 +107,7 @@ class UserPreferencesRepositoryImpl @Inject constructor(
override val displayPrefs: Flow<DisplayPreferences> = data
.map { preferences ->
DisplayPreferencesImpl(
systemFont = preferences.getSystemFont(),
middleZero = preferences.getMiddleZero(),
acButton = preferences.getAcButton(),
)
@ -258,6 +260,12 @@ class UserPreferencesRepositoryImpl @Inject constructor(
}
}
override suspend fun updateSystemFont(enabled: Boolean) {
dataStore.edit { preferences ->
preferences[PrefsKeys.SYSTEM_FONT] = enabled
}
}
override suspend fun updatePartialHistoryView(enabled: Boolean) {
dataStore.edit { preferences ->
preferences[PrefsKeys.PARTIAL_HISTORY_VIEW] = enabled

View File

@ -37,6 +37,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Colorize
import androidx.compose.material.icons.filled.DarkMode
import androidx.compose.material.icons.filled.ExposureZero
import androidx.compose.material.icons.filled.FontDownload
import androidx.compose.material.icons.filled.Language
import androidx.compose.material.icons.filled.Palette
import androidx.compose.material.icons.outlined.DarkMode
@ -112,6 +113,8 @@ internal fun DisplayRoute(
themmoController.setMonetMode(newValue)
viewModel.updateMonetMode(newValue)
},
systemFont = prefs.systemFont,
updateSystemFont = viewModel::updateSystemFont,
acButton = prefs.acButton,
updateAcButton = viewModel::updateAcButton,
middleZero = prefs.middleZero,
@ -135,6 +138,8 @@ private fun DisplayScreen(
onColorChange: (Color) -> Unit,
monetMode: MonetMode,
onMonetModeChange: (MonetMode) -> Unit,
systemFont: Boolean,
updateSystemFont: (Boolean) -> Unit,
acButton: Boolean,
updateAcButton: (Boolean) -> Unit,
middleZero: Boolean,
@ -256,6 +261,14 @@ private fun DisplayScreen(
Header(stringResource(R.string.settings_additional))
UnittoListItem(
icon = Icons.Default.FontDownload,
headlineText = stringResource(R.string.settings_system_font),
supportingText = stringResource(R.string.settings_system_font_support),
switchState = systemFont,
onSwitchChange = updateSystemFont
)
UnittoListItem(
icon = UnittoIcons.Clear,
headlineText = stringResource(R.string.settings_ac_button),
@ -298,6 +311,8 @@ private fun Preview() {
onColorChange = themmoController::setCustomColor,
monetMode = themmoController.currentMonetMode,
onMonetModeChange = themmoController::setMonetMode,
systemFont = false,
updateSystemFont = {},
acButton = false,
updateAcButton = {},
middleZero = false,

View File

@ -67,6 +67,12 @@ class DisplayViewModel @Inject constructor(
}
}
fun updateSystemFont(enabled: Boolean) {
viewModelScope.launch {
userPrefsRepository.updateSystemFont(enabled)
}
}
fun updateAcButton(enabled: Boolean) {
viewModelScope.launch {
userPrefsRepository.updateAcButton(enabled)

View File

@ -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.textfield.FormatterSymbols
import com.sadellie.unitto.core.ui.common.textfield.formatExpression
import com.sadellie.unitto.core.ui.theme.NumberTypographyUnitto
import com.sadellie.unitto.core.ui.theme.LocalNumberTypography
import com.sadellie.unitto.data.common.format
import kotlin.math.ceil
import kotlin.math.roundToInt
@ -137,7 +137,7 @@ fun FormattingScreen(
Text(
text = preview,
style = NumberTypographyUnitto.displayMedium,
style = LocalNumberTypography.current.displayMedium,
maxLines = 1,
modifier = Modifier
.fillMaxWidth()