mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
Revert "Remove System font option"
This reverts commit 24f03b9d3d218c4fb01c8b900c3413fc9d203bfa.
This commit is contained in:
parent
66c10744c2
commit
92953d1c99
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,20 +123,24 @@ private fun PreviewSystemTypography() {
|
||||
@Preview(widthDp = 480)
|
||||
@Composable
|
||||
private fun PreviewNumberTypography() {
|
||||
val textStyles = mapOf(
|
||||
"displayLarge" to NumberTypographyUnitto.displayLarge,
|
||||
"displayMedium" to NumberTypographyUnitto.displayMedium,
|
||||
"displaySmall" to NumberTypographyUnitto.displaySmall,
|
||||
)
|
||||
CompositionLocalProvider(
|
||||
LocalNumberTypography provides NumberTypographyUnitto
|
||||
) {
|
||||
val textStyles = mapOf(
|
||||
"displayLarge" to LocalNumberTypography.current.displayLarge,
|
||||
"displayMedium" to LocalNumberTypography.current.displayMedium,
|
||||
"displaySmall" to LocalNumberTypography.current.displaySmall,
|
||||
)
|
||||
|
||||
LazyColumn(Modifier.background(MaterialTheme.colorScheme.background)) {
|
||||
textStyles.forEach { (label, style) ->
|
||||
item {
|
||||
Text(
|
||||
text = "$label 123 Error 7 1⁄2",
|
||||
style = style,
|
||||
color = MaterialTheme.colorScheme.onBackground
|
||||
)
|
||||
LazyColumn(Modifier.background(MaterialTheme.colorScheme.background)) {
|
||||
textStyles.forEach { (label, style) ->
|
||||
item {
|
||||
Text(
|
||||
text = "$label 123 Error 7 1⁄2",
|
||||
style = style,
|
||||
color = MaterialTheme.colorScheme.onBackground
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -26,5 +26,6 @@ interface AppPreferences {
|
||||
val monetMode: String
|
||||
val startingScreen: String
|
||||
val enableToolsExperiment: Boolean
|
||||
val systemFont: Boolean
|
||||
val rpnMode: Boolean
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.sadellie.unitto.data.model.userprefs
|
||||
|
||||
interface DisplayPreferences {
|
||||
val systemFont: Boolean
|
||||
val middleZero: Boolean
|
||||
val acButton: Boolean
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user