Remove System font option

closes #128
This commit is contained in:
Sad Ellie 2023-11-23 22:45:53 +03:00
parent ff81b2e79c
commit 24f03b9d3d
14 changed files with 47 additions and 118 deletions

View File

@ -32,9 +32,6 @@ import androidx.core.os.ConfigurationCompat
import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.sadellie.unitto.core.ui.LocalLocale
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
@ -58,13 +55,8 @@ 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,
LocalNumberTypography provides numbersTypography
LocalLocale provides locale
) {
UnittoApp(prefs)
}

View File

@ -20,7 +20,6 @@ package com.sadellie.unitto
import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@ -53,7 +52,6 @@ import io.github.sadellie.themmo.Themmo
import io.github.sadellie.themmo.ThemmoController
import kotlinx.coroutines.launch
@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun UnittoApp(prefs: AppPreferences?) {

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.LocalNumberTypography
import com.sadellie.unitto.core.ui.theme.NumberTypographyUnitto
@Composable
fun FixedInputTextField(
@ -83,7 +83,7 @@ fun FixedInputTextField(
.fillMaxWidth()
.padding(horizontal = 8.dp)
.horizontalScroll(rememberScrollState(), reverseScrolling = true),
textStyle = LocalNumberTypography.current.displaySmall.copy(color = textColor, textAlign = TextAlign.End),
textStyle = NumberTypographyUnitto.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.LocalNumberTypography
import com.sadellie.unitto.core.ui.theme.NumberTypographyUnitto
import kotlin.math.ceil
import kotlin.math.roundToInt
@ -105,7 +105,7 @@ fun ExpressionTextField(
modifier = modifier,
value = value,
formattedValue = value.text.formatExpression(formatterSymbols),
textStyle = LocalNumberTypography.current.displayLarge.copy(color = textColor),
textStyle = NumberTypographyUnitto.displayLarge.copy(color = textColor),
minRatio = minRatio,
onValueChange = { onCursorChange(it.selection) },
readOnly = readOnly,
@ -157,7 +157,7 @@ fun UnformattedTextField(
AutoSizableTextField(
modifier = modifier,
value = value,
textStyle = LocalNumberTypography.current.displayLarge.copy(color = textColor),
textStyle = NumberTypographyUnitto.displayLarge.copy(color = textColor),
minRatio = minRatio,
onValueChange = { onCursorChange(it.selection) },
readOnly = readOnly,

View File

@ -24,9 +24,7 @@ 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
@ -71,16 +69,6 @@ val NumberTypographyUnitto by lazy {
val TypographySystem by lazy { Typography() }
val NumberTypographySystem by lazy {
NumberTypography(
displayLarge = TypographySystem.displayLarge,
displayMedium = TypographySystem.displayMedium,
displaySmall = TypographySystem.displaySmall,
)
}
val LocalNumberTypography = staticCompositionLocalOf { NumberTypographySystem }
private val FontFamily.Companion.lato: FontFamily
get() = FontFamily(
Font(R.font.lato_regular, weight = FontWeight.Normal)
@ -89,9 +77,6 @@ private val FontFamily.Companion.lato: FontFamily
@Preview(widthDp = 480)
@Composable
private fun PreviewSystemTypography() {
MaterialTheme(
typography = TypographySystem
) {
val textStyles = mapOf(
"displayLarge" to MaterialTheme.typography.displayLarge,
"displayMedium" to MaterialTheme.typography.displayMedium,
@ -111,7 +96,6 @@ private fun PreviewSystemTypography() {
)
LazyColumn(Modifier.background(MaterialTheme.colorScheme.background)) {
textStyles.forEach { (label, style) ->
item {
Text(
@ -123,22 +107,17 @@ private fun PreviewSystemTypography() {
}
}
}
}
@Preview(widthDp = 480)
@Composable
private fun PreviewNumberTypography() {
CompositionLocalProvider(
LocalNumberTypography provides NumberTypographyUnitto
) {
val textStyles = mapOf(
"displayLarge" to LocalNumberTypography.current.displayLarge,
"displayMedium" to LocalNumberTypography.current.displayMedium,
"displaySmall" to LocalNumberTypography.current.displaySmall,
"displayLarge" to NumberTypographyUnitto.displayLarge,
"displayMedium" to NumberTypographyUnitto.displayMedium,
"displaySmall" to NumberTypographyUnitto.displaySmall,
)
LazyColumn(Modifier.background(MaterialTheme.colorScheme.background)) {
textStyles.forEach { (label, style) ->
item {
Text(
@ -150,4 +129,3 @@ private fun PreviewNumberTypography() {
}
}
}
}

View File

@ -81,8 +81,6 @@ 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,6 +26,5 @@ interface AppPreferences {
val monetMode: String
val startingScreen: String
val enableToolsExperiment: Boolean
val systemFont: Boolean
val rpnMode: Boolean
}

View File

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

View File

@ -40,7 +40,6 @@ data class AppPreferencesImpl(
override val monetMode: String,
override val startingScreen: String,
override val enableToolsExperiment: Boolean,
override val systemFont: Boolean,
override val rpnMode: Boolean,
) : AppPreferences
@ -77,7 +76,6 @@ 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 @@ internal 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

@ -63,7 +63,6 @@ class UserPreferencesRepositoryImpl @Inject constructor(
monetMode = preferences.getMonetMode(),
startingScreen = preferences.getStartingScreen(),
enableToolsExperiment = preferences.getEnableToolsExperiment(),
systemFont = preferences.getSystemFont(),
rpnMode = preferences.getRpnMode(),
)
}
@ -112,7 +111,6 @@ class UserPreferencesRepositoryImpl @Inject constructor(
override val displayPrefs: Flow<DisplayPreferences> = data
.map { preferences ->
DisplayPreferencesImpl(
systemFont = preferences.getSystemFont(),
middleZero = preferences.getMiddleZero(),
acButton = preferences.getAcButton(),
)
@ -265,12 +263,6 @@ 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
@ -325,10 +317,6 @@ private fun Preferences.getEnableToolsExperiment(): Boolean {
return this[PrefsKeys.ENABLE_TOOLS_EXPERIMENT] ?: false
}
private fun Preferences.getSystemFont(): Boolean {
return this[PrefsKeys.SYSTEM_FONT] ?: false
}
private fun Preferences.getEnableVibrations(): Boolean {
return this[PrefsKeys.ENABLE_VIBRATIONS] ?: true
}

View File

@ -37,7 +37,6 @@ 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
@ -113,8 +112,6 @@ internal fun DisplayRoute(
themmoController.setMonetMode(newValue)
viewModel.updateMonetMode(newValue)
},
systemFont = prefs.systemFont,
updateSystemFont = viewModel::updateSystemFont,
acButton = prefs.acButton,
updateAcButton = viewModel::updateAcButton,
middleZero = prefs.middleZero,
@ -138,8 +135,6 @@ private fun DisplayScreen(
onColorChange: (Color) -> Unit,
monetMode: MonetMode,
onMonetModeChange: (MonetMode) -> Unit,
systemFont: Boolean,
updateSystemFont: (Boolean) -> Unit,
acButton: Boolean,
updateAcButton: (Boolean) -> Unit,
middleZero: Boolean,
@ -261,14 +256,6 @@ 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),
@ -311,8 +298,6 @@ private fun Preview() {
onColorChange = themmoController::setCustomColor,
monetMode = themmoController.currentMonetMode,
onMonetModeChange = themmoController::setMonetMode,
systemFont = false,
updateSystemFont = {},
acButton = false,
updateAcButton = {},
middleZero = false,

View File

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

View File

@ -63,7 +63,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.LocalNumberTypography
import com.sadellie.unitto.core.ui.theme.NumberTypographyUnitto
import kotlin.math.roundToInt
@Composable
@ -139,7 +139,7 @@ fun FormattingScreen(
)
Text(
text = uiState.preview,
style = LocalNumberTypography.current.displayMedium,
style = NumberTypographyUnitto.displayMedium,
maxLines = 1,
modifier = Modifier
.fillMaxWidth()