refactor: rename "preferences" to "settings" to maintain consistency

This commit is contained in:
Nishant Mishra
2025-11-09 09:17:55 +05:30
parent f4fa16b5df
commit 538c984d40
7 changed files with 62 additions and 52 deletions

View File

@@ -50,15 +50,15 @@ class MainActivity : ComponentActivity() {
}
setContent {
val preferencesState by settingsViewModel.preferencesState.collectAsStateWithLifecycle()
val settingsState by settingsViewModel.settingsState.collectAsStateWithLifecycle()
val darkTheme = when (preferencesState.theme) {
val darkTheme = when (settingsState.theme) {
"dark" -> true
"light" -> false
else -> isSystemInDarkTheme()
}
val seed = preferencesState.colorScheme.toColor()
val seed = settingsState.colorScheme.toColor()
val isPlus by settingsViewModel.isPlus.collectAsStateWithLifecycle()
val isPurchaseStateLoaded by settingsViewModel.isPurchaseStateLoaded.collectAsStateWithLifecycle()
@@ -77,7 +77,7 @@ class MainActivity : ComponentActivity() {
TomatoTheme(
darkTheme = darkTheme,
seedColor = seed,
blackTheme = preferencesState.blackTheme
blackTheme = settingsState.blackTheme
) {
val colorScheme = colorScheme
LaunchedEffect(colorScheme) {
@@ -86,7 +86,7 @@ class MainActivity : ComponentActivity() {
AppScreen(
isPlus = isPlus,
isAODEnabled = preferencesState.aodEnabled,
isAODEnabled = settingsState.aodEnabled,
setTimerFrequency = {
appContainer.appTimerRepository.timerFrequency = it
}

View File

@@ -73,8 +73,8 @@ import org.nsh07.pomodoro.ui.settingsScreen.components.PlusPromo
import org.nsh07.pomodoro.ui.settingsScreen.screens.AlarmSettings
import org.nsh07.pomodoro.ui.settingsScreen.screens.AppearanceSettings
import org.nsh07.pomodoro.ui.settingsScreen.screens.TimerSettings
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsViewModel
import org.nsh07.pomodoro.ui.settingsScreens
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
@@ -106,7 +106,7 @@ fun SettingsScreenRoot(
val dndEnabled by viewModel.dndEnabled.collectAsStateWithLifecycle(false)
val alarmSound by viewModel.alarmSound.collectAsStateWithLifecycle(viewModel.currentAlarmSound)
val preferencesState by viewModel.preferencesState.collectAsStateWithLifecycle()
val settingsState by viewModel.settingsState.collectAsStateWithLifecycle()
val sessionsSliderState = rememberSaveable(
saver = SliderState.Saver(
@@ -119,7 +119,7 @@ fun SettingsScreenRoot(
SettingsScreen(
isPlus = isPlus,
preferencesState = preferencesState,
settingsState = settingsState,
backStack = backStack,
focusTimeInputFieldState = focusTimeInputFieldState,
shortBreakTimeInputFieldState = shortBreakTimeInputFieldState,
@@ -140,7 +140,7 @@ fun SettingsScreenRoot(
@Composable
private fun SettingsScreen(
isPlus: Boolean,
preferencesState: PreferencesState,
settingsState: SettingsState,
backStack: SnapshotStateList<Screen.Settings>,
focusTimeInputFieldState: TextFieldState,
shortBreakTimeInputFieldState: TextFieldState,
@@ -287,7 +287,7 @@ private fun SettingsScreen(
entry<Screen.Settings.Alarm> {
AlarmSettings(
preferencesState = preferencesState,
settingsState = settingsState,
alarmEnabled = alarmEnabled,
vibrateEnabled = vibrateEnabled,
alarmSound = alarmSound,
@@ -297,7 +297,7 @@ private fun SettingsScreen(
}
entry<Screen.Settings.Appearance> {
AppearanceSettings(
preferencesState = preferencesState,
settingsState = settingsState,
isPlus = isPlus,
onAction = onAction,
setShowPaywall = setShowPaywall,
@@ -307,7 +307,7 @@ private fun SettingsScreen(
entry<Screen.Settings.Timer> {
TimerSettings(
isPlus = isPlus,
aodEnabled = preferencesState.aodEnabled,
aodEnabled = settingsState.aodEnabled,
dndEnabled = dndEnabled,
focusTimeInputFieldState = focusTimeInputFieldState,
shortBreakTimeInputFieldState = shortBreakTimeInputFieldState,

View File

@@ -65,8 +65,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.nsh07.pomodoro.R
import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors
@@ -78,7 +78,7 @@ import org.nsh07.pomodoro.ui.theme.TomatoShapeDefaults.topListItemShape
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun AlarmSettings(
preferencesState: PreferencesState,
settingsState: SettingsState,
alarmEnabled: Boolean,
vibrateEnabled: Boolean,
alarmSound: String,
@@ -126,8 +126,8 @@ fun AlarmSettings(
}
val switchItems = remember(
preferencesState.blackTheme,
preferencesState.aodEnabled,
settingsState.blackTheme,
settingsState.aodEnabled,
alarmEnabled,
vibrateEnabled
) {
@@ -242,9 +242,9 @@ fun AlarmSettings(
@Preview
@Composable
fun AlarmSettingsPreview() {
val preferencesState = PreferencesState()
val settingsState = SettingsState()
AlarmSettings(
preferencesState = preferencesState,
settingsState = settingsState,
alarmEnabled = true,
vibrateEnabled = false,
alarmSound = "",

View File

@@ -49,8 +49,8 @@ import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
import org.nsh07.pomodoro.ui.settingsScreen.components.ColorSchemePickerListItem
import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider
import org.nsh07.pomodoro.ui.settingsScreen.components.ThemePickerListItem
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors
@@ -62,7 +62,7 @@ import org.nsh07.pomodoro.utils.toColor
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun AppearanceSettings(
preferencesState: PreferencesState,
settingsState: SettingsState,
isPlus: Boolean,
onAction: (SettingsAction) -> Unit,
setShowPaywall: (Boolean) -> Unit,
@@ -103,7 +103,7 @@ fun AppearanceSettings(
}
item {
ThemePickerListItem(
theme = preferencesState.theme,
theme = settingsState.theme,
onThemeChange = { onAction(SettingsAction.SaveTheme(it)) },
items = if (isPlus) 3 else 1,
index = 0
@@ -116,7 +116,7 @@ fun AppearanceSettings(
item {
ColorSchemePickerListItem(
color = preferencesState.colorScheme.toColor(),
color = settingsState.colorScheme.toColor(),
items = 3,
index = if (isPlus) 1 else 0,
isPlus = isPlus,
@@ -125,7 +125,7 @@ fun AppearanceSettings(
}
item {
val item = SettingsSwitchItem(
checked = preferencesState.blackTheme,
checked = settingsState.blackTheme,
icon = R.drawable.contrast,
label = R.string.black_theme,
description = R.string.black_theme_desc,
@@ -173,10 +173,10 @@ fun AppearanceSettings(
@Preview
@Composable
fun AppearanceSettingsPreview() {
val preferencesState = PreferencesState()
val settingsState = SettingsState()
TomatoTheme(dynamicColor = false) {
AppearanceSettings(
preferencesState = preferencesState,
settingsState = settingsState,
isPlus = false,
onAction = {},
setShowPaywall = {},

View File

@@ -1,19 +0,0 @@
/*
* Copyright (c) 2025 Nishant Mishra
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.nsh07.pomodoro.ui.settingsScreen.viewModel
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
@Immutable
data class PreferencesState(
val theme: String = "auto",
val colorScheme: String = Color.White.toString(),
val blackTheme: Boolean = false,
val aodEnabled: Boolean = false
)

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 Nishant Mishra
*
* This file is part of Tomato - a minimalist pomodoro timer for Android.
*
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tomato.
* If not, see <https://www.gnu.org/licenses/>.
*/
package org.nsh07.pomodoro.ui.settingsScreen.viewModel
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
@Immutable
data class SettingsState(
val theme: String = "auto",
val colorScheme: String = Color.White.toString(),
val blackTheme: Boolean = false,
val aodEnabled: Boolean = false
)

View File

@@ -59,8 +59,8 @@ class SettingsViewModel(
private val _isSettingsLoaded = MutableStateFlow(false)
val isSettingsLoaded = _isSettingsLoaded.asStateFlow()
private val _preferencesState = MutableStateFlow(PreferencesState())
val preferencesState = _preferencesState.asStateFlow()
private val _settingsState = MutableStateFlow(SettingsState())
val settingsState = _settingsState.asStateFlow()
val focusTimeTextFieldState by lazy {
TextFieldState((timerRepository.focusTime / 60000).toString())
@@ -203,7 +203,7 @@ class SettingsViewModel(
private fun saveColorScheme(colorScheme: Color) {
viewModelScope.launch {
_preferencesState.update { currentState ->
_settingsState.update { currentState ->
currentState.copy(colorScheme = colorScheme.toString())
}
preferenceRepository.saveStringPreference("color_scheme", colorScheme.toString())
@@ -212,7 +212,7 @@ class SettingsViewModel(
private fun saveTheme(theme: String) {
viewModelScope.launch {
_preferencesState.update { currentState ->
_settingsState.update { currentState ->
currentState.copy(theme = theme)
}
preferenceRepository.saveStringPreference("theme", theme)
@@ -221,7 +221,7 @@ class SettingsViewModel(
private fun saveBlackTheme(blackTheme: Boolean) {
viewModelScope.launch {
_preferencesState.update { currentState ->
_settingsState.update { currentState ->
currentState.copy(blackTheme = blackTheme)
}
preferenceRepository.saveBooleanPreference("black_theme", blackTheme)
@@ -230,7 +230,7 @@ class SettingsViewModel(
private fun saveAodEnabled(aodEnabled: Boolean) {
viewModelScope.launch {
_preferencesState.update { currentState ->
_settingsState.update { currentState ->
currentState.copy(aodEnabled = aodEnabled)
}
preferenceRepository.saveBooleanPreference("aod_enabled", aodEnabled)
@@ -238,7 +238,7 @@ class SettingsViewModel(
}
fun resetPaywalledSettings() {
_preferencesState.update { currentState ->
_settingsState.update { currentState ->
currentState.copy(
aodEnabled = false,
blackTheme = false,
@@ -257,7 +257,7 @@ class SettingsViewModel(
val aodEnabled = preferenceRepository.getBooleanPreference("aod_enabled")
?: preferenceRepository.saveBooleanPreference("aod_enabled", false)
_preferencesState.update { currentState ->
_settingsState.update { currentState ->
currentState.copy(
theme = theme,
colorScheme = colorScheme,