mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
parent
e06bb76b02
commit
99a91be8ca
@ -94,6 +94,8 @@ Used in this dialog window. Should be short -->
|
|||||||
<string name="settings_auto">Auto</string>
|
<string name="settings_auto">Auto</string>
|
||||||
<string name="settings_calculator_support">History view</string>
|
<string name="settings_calculator_support">History view</string>
|
||||||
<string name="settings_clear_cache">Clear cache</string>
|
<string name="settings_clear_cache">Clear cache</string>
|
||||||
|
<string name="settings_clear_input">Clear input</string>
|
||||||
|
<string name="settings_clear_input_support">Start new expression when clicking \"=\" and clicking any button</string>
|
||||||
<string name="settings_color_scheme">Color scheme</string>
|
<string name="settings_color_scheme">Color scheme</string>
|
||||||
<string name="settings_color_theme">Color theme</string>
|
<string name="settings_color_theme">Color theme</string>
|
||||||
<string name="settings_color_theme_support">Pick a theming mode</string>
|
<string name="settings_color_theme_support">Pick a theming mode</string>
|
||||||
|
@ -86,4 +86,6 @@ interface UserPreferencesRepository {
|
|||||||
suspend fun updatePartialHistoryView(enabled: Boolean)
|
suspend fun updatePartialHistoryView(enabled: Boolean)
|
||||||
|
|
||||||
suspend fun updateAcButton(enabled: Boolean)
|
suspend fun updateAcButton(enabled: Boolean)
|
||||||
|
|
||||||
|
suspend fun updateClearInputAfterEquals(enabled: Boolean)
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,5 @@ interface CalculatorPreferences {
|
|||||||
val partialHistoryView: Boolean
|
val partialHistoryView: Boolean
|
||||||
val precision: Int
|
val precision: Int
|
||||||
val outputFormat: Int
|
val outputFormat: Int
|
||||||
|
val clearInputAfterEquals: Boolean
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,6 @@ data class AppPreferencesImpl(
|
|||||||
override val systemFont: Boolean,
|
override val systemFont: Boolean,
|
||||||
) : AppPreferences
|
) : AppPreferences
|
||||||
|
|
||||||
|
|
||||||
data class GeneralPreferencesImpl(
|
data class GeneralPreferencesImpl(
|
||||||
override val enableVibrations: Boolean,
|
override val enableVibrations: Boolean,
|
||||||
) : GeneralPreferences
|
) : GeneralPreferences
|
||||||
@ -57,6 +56,7 @@ data class CalculatorPreferencesImpl(
|
|||||||
override val partialHistoryView: Boolean,
|
override val partialHistoryView: Boolean,
|
||||||
override val precision: Int,
|
override val precision: Int,
|
||||||
override val outputFormat: Int,
|
override val outputFormat: Int,
|
||||||
|
override val clearInputAfterEquals: Boolean,
|
||||||
) : CalculatorPreferences
|
) : CalculatorPreferences
|
||||||
|
|
||||||
data class ConverterPreferencesImpl(
|
data class ConverterPreferencesImpl(
|
||||||
|
@ -47,4 +47,5 @@ internal object PrefsKeys {
|
|||||||
val SYSTEM_FONT = booleanPreferencesKey("SYSTEM_FONT_PREF_KEY")
|
val SYSTEM_FONT = booleanPreferencesKey("SYSTEM_FONT_PREF_KEY")
|
||||||
val PARTIAL_HISTORY_VIEW = booleanPreferencesKey("PARTIAL_HISTORY_VIEW_PREF_KEY")
|
val PARTIAL_HISTORY_VIEW = booleanPreferencesKey("PARTIAL_HISTORY_VIEW_PREF_KEY")
|
||||||
val AC_BUTTON = booleanPreferencesKey("AC_BUTTON_PREF_KEY")
|
val AC_BUTTON = booleanPreferencesKey("AC_BUTTON_PREF_KEY")
|
||||||
|
val CLEAR_INPUT_AFTER_EQUALS = booleanPreferencesKey("CLEAR_INPUT_AFTER_EQUALS_PREF_KEY")
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ class UserPreferencesRepositoryImpl @Inject constructor(
|
|||||||
precision = preferences.getDigitsPrecision(),
|
precision = preferences.getDigitsPrecision(),
|
||||||
outputFormat = preferences.getOutputFormat(),
|
outputFormat = preferences.getOutputFormat(),
|
||||||
acButton = preferences.getAcButton(),
|
acButton = preferences.getAcButton(),
|
||||||
|
clearInputAfterEquals = preferences.getClearInputAfterEquals()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,6 +281,12 @@ class UserPreferencesRepositoryImpl @Inject constructor(
|
|||||||
preferences[PrefsKeys.AC_BUTTON] = enabled
|
preferences[PrefsKeys.AC_BUTTON] = enabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateClearInputAfterEquals(enabled: Boolean) {
|
||||||
|
dataStore.edit { preferences ->
|
||||||
|
preferences[PrefsKeys.CLEAR_INPUT_AFTER_EQUALS] = enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Preferences.getEnableDynamicTheme(): Boolean {
|
private fun Preferences.getEnableDynamicTheme(): Boolean {
|
||||||
@ -376,6 +383,10 @@ private fun Preferences.getAcButton(): Boolean {
|
|||||||
return this[PrefsKeys.AC_BUTTON] ?: false
|
return this[PrefsKeys.AC_BUTTON] ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Preferences.getClearInputAfterEquals(): Boolean {
|
||||||
|
return this[PrefsKeys.CLEAR_INPUT_AFTER_EQUALS] ?: true
|
||||||
|
}
|
||||||
|
|
||||||
private inline fun <T, R> T.letTryOrNull(block: (T) -> R): R? = try {
|
private inline fun <T, R> T.letTryOrNull(block: (T) -> R): R? = try {
|
||||||
this?.let(block)
|
this?.let(block)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -120,36 +120,39 @@ internal class CalculatorViewModel @Inject constructor(
|
|||||||
.stateIn(viewModelScope, CalculatorUIState.Loading)
|
.stateIn(viewModelScope, CalculatorUIState.Loading)
|
||||||
|
|
||||||
fun addTokens(tokens: String) = _input.update {
|
fun addTokens(tokens: String) = _input.update {
|
||||||
val newValue = if (_equalClicked.value) {
|
val clearInputAfterEquals = _prefs.value?.clearInputAfterEquals ?: true
|
||||||
_equalClicked.update { false }
|
val newValue = if (_equalClicked.value and clearInputAfterEquals) {
|
||||||
TextFieldValue().addTokens(tokens)
|
TextFieldValue().addTokens(tokens)
|
||||||
} else {
|
} else {
|
||||||
it.addTokens(tokens)
|
it.addTokens(tokens)
|
||||||
}
|
}
|
||||||
|
_equalClicked.update { false }
|
||||||
_fractionJob?.cancel()
|
_fractionJob?.cancel()
|
||||||
savedStateHandle[_inputKey] = newValue.text
|
savedStateHandle[_inputKey] = newValue.text
|
||||||
newValue
|
newValue
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addBracket() = _input.update {
|
fun addBracket() = _input.update {
|
||||||
val newValue = if (_equalClicked.value) {
|
val clearInputAfterEquals = _prefs.value?.clearInputAfterEquals ?: true
|
||||||
_equalClicked.update { false }
|
val newValue = if (_equalClicked.value and clearInputAfterEquals) {
|
||||||
TextFieldValue().addBracket()
|
TextFieldValue().addBracket()
|
||||||
} else {
|
} else {
|
||||||
it.addBracket()
|
it.addBracket()
|
||||||
}
|
}
|
||||||
|
_equalClicked.update { false }
|
||||||
_fractionJob?.cancel()
|
_fractionJob?.cancel()
|
||||||
savedStateHandle[_inputKey] = newValue.text
|
savedStateHandle[_inputKey] = newValue.text
|
||||||
newValue
|
newValue
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteTokens() = _input.update {
|
fun deleteTokens() = _input.update {
|
||||||
val newValue = if (_equalClicked.value) {
|
val clearInputAfterEquals = _prefs.value?.clearInputAfterEquals ?: true
|
||||||
_equalClicked.update { false }
|
val newValue = if (_equalClicked.value and clearInputAfterEquals) {
|
||||||
TextFieldValue().deleteTokens()
|
TextFieldValue().deleteTokens()
|
||||||
} else {
|
} else {
|
||||||
it.deleteTokens()
|
it.deleteTokens()
|
||||||
}
|
}
|
||||||
|
_equalClicked.update { false }
|
||||||
_fractionJob?.cancel()
|
_fractionJob?.cancel()
|
||||||
savedStateHandle[_inputKey] = newValue.text
|
savedStateHandle[_inputKey] = newValue.text
|
||||||
newValue
|
newValue
|
||||||
|
@ -20,6 +20,7 @@ package com.sadellie.unitto.feature.settings.calculator
|
|||||||
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.Backspace
|
||||||
import androidx.compose.material.icons.filled.Timer
|
import androidx.compose.material.icons.filled.Timer
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@ -47,7 +48,8 @@ internal fun CalculatorSettingsRoute(
|
|||||||
CalculatorSettingsScreen(
|
CalculatorSettingsScreen(
|
||||||
prefs = prefs,
|
prefs = prefs,
|
||||||
navigateUpAction = navigateUpAction,
|
navigateUpAction = navigateUpAction,
|
||||||
updatePartialHistoryView = viewModel::updatePartialHistoryView
|
updatePartialHistoryView = viewModel::updatePartialHistoryView,
|
||||||
|
updateClearInputAfterEquals = viewModel::updateClearInputAfterEquals,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,6 +60,7 @@ private fun CalculatorSettingsScreen(
|
|||||||
prefs: CalculatorPreferences,
|
prefs: CalculatorPreferences,
|
||||||
navigateUpAction: () -> Unit,
|
navigateUpAction: () -> Unit,
|
||||||
updatePartialHistoryView: (Boolean) -> Unit,
|
updatePartialHistoryView: (Boolean) -> Unit,
|
||||||
|
updateClearInputAfterEquals: (Boolean) -> Unit,
|
||||||
) {
|
) {
|
||||||
UnittoScreenWithLargeTopBar(
|
UnittoScreenWithLargeTopBar(
|
||||||
title = stringResource(R.string.calculator_title),
|
title = stringResource(R.string.calculator_title),
|
||||||
@ -73,6 +76,16 @@ private fun CalculatorSettingsScreen(
|
|||||||
onSwitchChange = updatePartialHistoryView
|
onSwitchChange = updatePartialHistoryView
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item("clear input") {
|
||||||
|
UnittoListItem(
|
||||||
|
headlineText = stringResource(R.string.settings_clear_input),
|
||||||
|
icon = Icons.AutoMirrored.Filled.Backspace,
|
||||||
|
supportingText = stringResource(R.string.settings_clear_input_support),
|
||||||
|
switchState = prefs.clearInputAfterEquals,
|
||||||
|
onSwitchChange = updateClearInputAfterEquals
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,8 +103,10 @@ private fun PreviewCalculatorSettingsScreen() {
|
|||||||
precision = 3,
|
precision = 3,
|
||||||
outputFormat = OutputFormat.PLAIN,
|
outputFormat = OutputFormat.PLAIN,
|
||||||
acButton = true,
|
acButton = true,
|
||||||
|
clearInputAfterEquals = true,
|
||||||
),
|
),
|
||||||
navigateUpAction = {},
|
navigateUpAction = {},
|
||||||
updatePartialHistoryView = {}
|
updatePartialHistoryView = {},
|
||||||
|
updateClearInputAfterEquals = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -36,4 +36,8 @@ class CalculatorViewModel @Inject constructor(
|
|||||||
fun updatePartialHistoryView(enabled: Boolean) = viewModelScope.launch {
|
fun updatePartialHistoryView(enabled: Boolean) = viewModelScope.launch {
|
||||||
userPrefsRepository.updatePartialHistoryView(enabled)
|
userPrefsRepository.updatePartialHistoryView(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateClearInputAfterEquals(enabled: Boolean) = viewModelScope.launch {
|
||||||
|
userPrefsRepository.updateClearInputAfterEquals(enabled)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user