mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
Dude gave 2 stars cause of this
Hopefully he gives the app at least 3 stars now
This commit is contained in:
parent
20d0310fd0
commit
ee5435dc7a
@ -1368,4 +1368,6 @@ Used in this dialog window. Should be short -->
|
||||
<string name="yesterday">Yesterday</string>
|
||||
<string name="search_text_field_placeholder">Search…</string>
|
||||
<string name="add_time_zone_title">Add time zone</string>
|
||||
<string name="middle_zero_option">Zero in the middle</string>
|
||||
<string name="middle_zero_option_support">Swap zero and decimal buttons</string>
|
||||
</resources>
|
@ -83,6 +83,7 @@ data class UserPreferences(
|
||||
val unitConverterFavoritesOnly: Boolean = false,
|
||||
val unitConverterFormatTime: Boolean = false,
|
||||
val unitConverterSorting: UnitsListSorting = UnitsListSorting.USAGE,
|
||||
val middleZero: Boolean = false,
|
||||
)
|
||||
|
||||
data class UIPreferences(
|
||||
@ -107,6 +108,7 @@ data class MainPreferences(
|
||||
val unitConverterFavoritesOnly: Boolean = false,
|
||||
val unitConverterFormatTime: Boolean = false,
|
||||
val unitConverterSorting: UnitsListSorting = UnitsListSorting.USAGE,
|
||||
val middleZero: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
@ -135,6 +137,7 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS
|
||||
val UNIT_CONVERTER_FAVORITES_ONLY = booleanPreferencesKey("UNIT_CONVERTER_FAVORITES_ONLY_PREF_KEY")
|
||||
val UNIT_CONVERTER_FORMAT_TIME = booleanPreferencesKey("UNIT_CONVERTER_FORMAT_TIME_PREF_KEY")
|
||||
val UNIT_CONVERTER_SORTING = stringPreferencesKey("UNIT_CONVERTER_SORTING_PREF_KEY")
|
||||
val MIDDLE_ZERO = booleanPreferencesKey("MIDDLE_ZERO_PREF_KEY")
|
||||
}
|
||||
|
||||
val uiPreferencesFlow: Flow<UIPreferences> = dataStore.data
|
||||
@ -199,6 +202,7 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS
|
||||
val unitConverterFavoritesOnly: Boolean = preferences[PrefsKeys.UNIT_CONVERTER_FAVORITES_ONLY] ?: false
|
||||
val unitConverterFormatTime: Boolean = preferences[PrefsKeys.UNIT_CONVERTER_FORMAT_TIME] ?: false
|
||||
val unitConverterSorting: UnitsListSorting = preferences[PrefsKeys.UNIT_CONVERTER_SORTING]?.let { UnitsListSorting.valueOf(it) } ?: UnitsListSorting.USAGE
|
||||
val middleZero: Boolean = preferences[PrefsKeys.MIDDLE_ZERO] ?: false
|
||||
|
||||
MainPreferences(
|
||||
digitsPrecision = digitsPrecision,
|
||||
@ -212,6 +216,7 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS
|
||||
unitConverterFavoritesOnly = unitConverterFavoritesOnly,
|
||||
unitConverterFormatTime = unitConverterFormatTime,
|
||||
unitConverterSorting = unitConverterSorting,
|
||||
middleZero = middleZero,
|
||||
)
|
||||
}
|
||||
|
||||
@ -237,6 +242,7 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS
|
||||
unitConverterFavoritesOnly = main.unitConverterFavoritesOnly,
|
||||
unitConverterFormatTime = main.unitConverterFormatTime,
|
||||
unitConverterSorting = main.unitConverterSorting,
|
||||
middleZero = main.middleZero,
|
||||
)
|
||||
}
|
||||
|
||||
@ -370,6 +376,17 @@ class UserPreferencesRepository @Inject constructor(private val dataStore: DataS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update preference on where zero should be.
|
||||
*
|
||||
* @param enabled True if user wants zero button to be in the middle.
|
||||
*/
|
||||
suspend fun updateMiddleZero(enabled: Boolean) {
|
||||
dataStore.edit { preferences ->
|
||||
preferences[PrefsKeys.MIDDLE_ZERO] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update preference on whether or not show tools screen.
|
||||
*
|
||||
|
@ -278,7 +278,8 @@ private fun CalculatorScreen(
|
||||
clearSymbols = clearSymbols,
|
||||
deleteSymbol = deleteSymbol,
|
||||
toggleAngleMode = toggleAngleMode,
|
||||
evaluate = evaluate
|
||||
evaluate = evaluate,
|
||||
middleZero = uiState.middleZero,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ data class CalculatorUIState(
|
||||
val radianMode: Boolean = true,
|
||||
val history: List<HistoryItem> = emptyList(),
|
||||
val allowVibration: Boolean = false,
|
||||
val formatterSymbols: FormatterSymbols = FormatterSymbols.Spaces
|
||||
val formatterSymbols: FormatterSymbols = FormatterSymbols.Spaces,
|
||||
val middleZero: Boolean = false,
|
||||
)
|
||||
|
||||
sealed class CalculationResult(@StringRes val label: Int? = null) {
|
||||
|
@ -75,7 +75,8 @@ internal class CalculatorViewModel @Inject constructor(
|
||||
radianMode = userPrefs.radianMode,
|
||||
history = history,
|
||||
allowVibration = userPrefs.enableVibrations,
|
||||
formatterSymbols = AllFormatterSymbols.getById(userPrefs.separator)
|
||||
formatterSymbols = AllFormatterSymbols.getById(userPrefs.separator),
|
||||
middleZero = userPrefs.middleZero,
|
||||
)
|
||||
}.stateIn(
|
||||
viewModelScope, SharingStarted.WhileSubscribed(5000L), CalculatorUIState()
|
||||
|
@ -104,6 +104,7 @@ internal fun CalculatorKeyboard(
|
||||
radianMode: Boolean,
|
||||
fractional: String,
|
||||
allowVibration: Boolean,
|
||||
middleZero: Boolean,
|
||||
addSymbol: (String) -> Unit,
|
||||
clearSymbols: () -> Unit,
|
||||
deleteSymbol: () -> Unit,
|
||||
@ -116,6 +117,7 @@ internal fun CalculatorKeyboard(
|
||||
radianMode = radianMode,
|
||||
fractional = fractional,
|
||||
allowVibration = allowVibration,
|
||||
middleZero = middleZero,
|
||||
addSymbol = addSymbol,
|
||||
toggleAngleMode = toggleAngleMode,
|
||||
deleteSymbol = deleteSymbol,
|
||||
@ -128,6 +130,7 @@ internal fun CalculatorKeyboard(
|
||||
radianMode = radianMode,
|
||||
fractional = fractional,
|
||||
allowVibration = allowVibration,
|
||||
middleZero = middleZero,
|
||||
addSymbol = addSymbol,
|
||||
toggleAngleMode = toggleAngleMode,
|
||||
deleteSymbol = deleteSymbol,
|
||||
@ -143,6 +146,7 @@ private fun PortraitKeyboard(
|
||||
radianMode: Boolean,
|
||||
fractional: String,
|
||||
allowVibration: Boolean,
|
||||
middleZero: Boolean,
|
||||
addSymbol: (String) -> Unit,
|
||||
toggleAngleMode: () -> Unit,
|
||||
deleteSymbol: () -> Unit,
|
||||
@ -257,8 +261,13 @@ private fun PortraitKeyboard(
|
||||
KeyboardButtonFilled(mainButtonModifier, UnittoIcons.Plus, allowVibration) { addSymbol(Token.Operator.plus) }
|
||||
}
|
||||
Row(weightModifier) {
|
||||
KeyboardButtonLight(mainButtonModifier, UnittoIcons.Key0, allowVibration) { addSymbol(Token.Digit._0) }
|
||||
KeyboardButtonLight(mainButtonModifier, fractionalIcon, allowVibration) { addSymbol(Token.Digit.dot) }
|
||||
if (middleZero) {
|
||||
KeyboardButtonLight(mainButtonModifier, fractionalIcon, allowVibration) { addSymbol(Token.Digit.dot) }
|
||||
KeyboardButtonLight(mainButtonModifier, UnittoIcons.Key0, allowVibration) { addSymbol(Token.Digit._0) }
|
||||
} else {
|
||||
KeyboardButtonLight(mainButtonModifier, UnittoIcons.Key0, allowVibration) { addSymbol(Token.Digit._0) }
|
||||
KeyboardButtonLight(mainButtonModifier, fractionalIcon, allowVibration) { addSymbol(Token.Digit.dot) }
|
||||
}
|
||||
KeyboardButtonLight(mainButtonModifier, UnittoIcons.Backspace, allowVibration, clearSymbols) { deleteSymbol() }
|
||||
KeyboardButtonFilled(mainButtonModifier, UnittoIcons.Equal, allowVibration) { evaluate() }
|
||||
}
|
||||
@ -345,6 +354,7 @@ private fun LandscapeKeyboard(
|
||||
radianMode: Boolean,
|
||||
fractional: String,
|
||||
allowVibration: Boolean,
|
||||
middleZero: Boolean,
|
||||
addSymbol: (String) -> Unit,
|
||||
toggleAngleMode: () -> Unit,
|
||||
deleteSymbol: () -> Unit,
|
||||
@ -390,13 +400,21 @@ private fun LandscapeKeyboard(
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key7, allowVibration) { addSymbol(Token.Digit._7) }
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key4, allowVibration) { addSymbol(Token.Digit._4) }
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key1, allowVibration) { addSymbol(Token.Digit._1) }
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key0, allowVibration) { addSymbol(Token.Digit._0) }
|
||||
if (middleZero) {
|
||||
KeyboardButtonLight(buttonModifier, fractionalIcon, allowVibration) { addSymbol(Token.Digit.dot) }
|
||||
} else {
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key0, allowVibration) { addSymbol(Token.Digit._0) }
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key8, allowVibration) { addSymbol(Token.Digit._8) }
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key5, allowVibration) { addSymbol(Token.Digit._5) }
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key2, allowVibration) { addSymbol(Token.Digit._2) }
|
||||
KeyboardButtonLight(buttonModifier, fractionalIcon, allowVibration) { addSymbol(Token.Digit.dot) }
|
||||
if (middleZero) {
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key0, allowVibration) { addSymbol(Token.Digit._0) }
|
||||
} else {
|
||||
KeyboardButtonLight(buttonModifier, fractionalIcon, allowVibration) { addSymbol(Token.Digit.dot) }
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardButtonLight(buttonModifier, UnittoIcons.Key9, allowVibration) { addSymbol(Token.Digit._9) }
|
||||
@ -496,6 +514,7 @@ private fun PreviewCalculatorKeyboard() {
|
||||
deleteSymbol = {},
|
||||
toggleAngleMode = {},
|
||||
evaluate = {},
|
||||
allowVibration = false
|
||||
allowVibration = false,
|
||||
middleZero = false,
|
||||
)
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ private fun ConverterScreen(
|
||||
converterMode = uiState.mode,
|
||||
allowVibration = uiState.allowVibration,
|
||||
fractional = uiState.formatterSymbols.fractional,
|
||||
middleZero = uiState.middleZero
|
||||
)
|
||||
}
|
||||
)
|
||||
|
@ -47,6 +47,7 @@ data class ConverterUIState(
|
||||
val unitTo: AbstractUnit? = null,
|
||||
val mode: ConverterMode = ConverterMode.DEFAULT,
|
||||
val allowVibration: Boolean = false,
|
||||
val middleZero: Boolean = false,
|
||||
val formatterSymbols: FormatterSymbols = FormatterSymbols.Spaces,
|
||||
)
|
||||
|
||||
|
@ -126,7 +126,8 @@ class ConverterViewModel @Inject constructor(
|
||||
unitTo = unitToValue,
|
||||
mode = if (_unitFrom.value is NumberBaseUnit) ConverterMode.BASE else ConverterMode.DEFAULT,
|
||||
allowVibration = prefs.enableVibrations,
|
||||
formatterSymbols = AllFormatterSymbols.getById(prefs.separator)
|
||||
formatterSymbols = AllFormatterSymbols.getById(prefs.separator),
|
||||
middleZero = prefs.middleZero,
|
||||
)
|
||||
}.stateIn(
|
||||
viewModelScope, SharingStarted.WhileSubscribed(5000), ConverterUIState()
|
||||
|
@ -78,10 +78,11 @@ internal fun ConverterKeyboard(
|
||||
converterMode: ConverterMode,
|
||||
allowVibration: Boolean,
|
||||
fractional: String,
|
||||
middleZero: Boolean,
|
||||
) {
|
||||
Crossfade(converterMode, modifier = modifier) {
|
||||
when (it) {
|
||||
ConverterMode.DEFAULT -> DefaultKeyboard(addDigit, clearInput, deleteDigit, allowVibration, fractional)
|
||||
ConverterMode.DEFAULT -> DefaultKeyboard(addDigit, clearInput, deleteDigit, allowVibration, fractional, middleZero)
|
||||
ConverterMode.BASE -> BaseKeyboard(addDigit, clearInput, deleteDigit, allowVibration)
|
||||
}
|
||||
}
|
||||
@ -94,6 +95,7 @@ private fun DefaultKeyboard(
|
||||
deleteDigit: () -> Unit,
|
||||
allowVibration: Boolean,
|
||||
fractional: String,
|
||||
middleZero: Boolean,
|
||||
) {
|
||||
val fractionalIcon = remember { if (fractional == Token.Digit.dot) UnittoIcons.Dot else UnittoIcons.Comma }
|
||||
ColumnWithConstraints {
|
||||
@ -129,8 +131,13 @@ private fun DefaultKeyboard(
|
||||
KeyboardButtonFilled(bModifier, UnittoIcons.Minus, allowVibration) { addDigit(Token.Operator.minus) }
|
||||
}
|
||||
Row(cModifier, horizontalArrangement) {
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key0, allowVibration) { addDigit(Token.Digit._0) }
|
||||
KeyboardButtonLight(bModifier, fractionalIcon, allowVibration) { addDigit(Token.Digit.dot) }
|
||||
if (middleZero) {
|
||||
KeyboardButtonLight(bModifier, fractionalIcon, allowVibration) { addDigit(Token.Digit.dot) }
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key0, allowVibration) { addDigit(Token.Digit._0) }
|
||||
} else {
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key0, allowVibration) { addDigit(Token.Digit._0) }
|
||||
KeyboardButtonLight(bModifier, fractionalIcon, allowVibration) { addDigit(Token.Digit.dot) }
|
||||
}
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Backspace, allowVibration, clearInput) { deleteDigit() }
|
||||
KeyboardButtonFilled(bModifier, UnittoIcons.Plus, allowVibration) { addDigit(Token.Operator.plus) }
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sadellie.unitto.feature.settings
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ExposureZero
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material.icons.filled.Palette
|
||||
@ -173,6 +174,22 @@ internal fun SettingsScreen(
|
||||
// ADDITIONAL GROUP
|
||||
item { Header(stringResource(R.string.additional_settings_group)) }
|
||||
|
||||
// MIDDLE ZERO
|
||||
item {
|
||||
UnittoListItem(
|
||||
label = stringResource(R.string.middle_zero_option),
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Default.ExposureZero,
|
||||
stringResource(R.string.middle_zero_option)
|
||||
)
|
||||
},
|
||||
supportContent = stringResource(R.string.middle_zero_option_support),
|
||||
switchState = userPrefs.value.middleZero,
|
||||
onSwitchChange = viewModel::updateMiddleZero
|
||||
)
|
||||
}
|
||||
|
||||
// VIBRATIONS
|
||||
item {
|
||||
UnittoListItem(
|
||||
|
@ -49,6 +49,15 @@ class SettingsViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserPreferencesRepository.updateMiddleZero
|
||||
*/
|
||||
fun updateMiddleZero(enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
userPrefsRepository.updateMiddleZero(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserPreferencesRepository.updateStartingScreen
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user