Skip to content

Commit 538c984

Browse files
committed
refactor: rename "preferences" to "settings" to maintain consistency
1 parent f4fa16b commit 538c984

File tree

7 files changed

+62
-52
lines changed

7 files changed

+62
-52
lines changed

app/src/main/java/org/nsh07/pomodoro/MainActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ class MainActivity : ComponentActivity() {
5050
}
5151

5252
setContent {
53-
val preferencesState by settingsViewModel.preferencesState.collectAsStateWithLifecycle()
53+
val settingsState by settingsViewModel.settingsState.collectAsStateWithLifecycle()
5454

55-
val darkTheme = when (preferencesState.theme) {
55+
val darkTheme = when (settingsState.theme) {
5656
"dark" -> true
5757
"light" -> false
5858
else -> isSystemInDarkTheme()
5959
}
6060

61-
val seed = preferencesState.colorScheme.toColor()
61+
val seed = settingsState.colorScheme.toColor()
6262

6363
val isPlus by settingsViewModel.isPlus.collectAsStateWithLifecycle()
6464
val isPurchaseStateLoaded by settingsViewModel.isPurchaseStateLoaded.collectAsStateWithLifecycle()
@@ -77,7 +77,7 @@ class MainActivity : ComponentActivity() {
7777
TomatoTheme(
7878
darkTheme = darkTheme,
7979
seedColor = seed,
80-
blackTheme = preferencesState.blackTheme
80+
blackTheme = settingsState.blackTheme
8181
) {
8282
val colorScheme = colorScheme
8383
LaunchedEffect(colorScheme) {
@@ -86,7 +86,7 @@ class MainActivity : ComponentActivity() {
8686

8787
AppScreen(
8888
isPlus = isPlus,
89-
isAODEnabled = preferencesState.aodEnabled,
89+
isAODEnabled = settingsState.aodEnabled,
9090
setTimerFrequency = {
9191
appContainer.appTimerRepository.timerFrequency = it
9292
}

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/SettingsScreen.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ import org.nsh07.pomodoro.ui.settingsScreen.components.PlusPromo
7373
import org.nsh07.pomodoro.ui.settingsScreen.screens.AlarmSettings
7474
import org.nsh07.pomodoro.ui.settingsScreen.screens.AppearanceSettings
7575
import org.nsh07.pomodoro.ui.settingsScreen.screens.TimerSettings
76-
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
7776
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
77+
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
7878
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsViewModel
7979
import org.nsh07.pomodoro.ui.settingsScreens
8080
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
@@ -106,7 +106,7 @@ fun SettingsScreenRoot(
106106
val dndEnabled by viewModel.dndEnabled.collectAsStateWithLifecycle(false)
107107
val alarmSound by viewModel.alarmSound.collectAsStateWithLifecycle(viewModel.currentAlarmSound)
108108

109-
val preferencesState by viewModel.preferencesState.collectAsStateWithLifecycle()
109+
val settingsState by viewModel.settingsState.collectAsStateWithLifecycle()
110110

111111
val sessionsSliderState = rememberSaveable(
112112
saver = SliderState.Saver(
@@ -119,7 +119,7 @@ fun SettingsScreenRoot(
119119

120120
SettingsScreen(
121121
isPlus = isPlus,
122-
preferencesState = preferencesState,
122+
settingsState = settingsState,
123123
backStack = backStack,
124124
focusTimeInputFieldState = focusTimeInputFieldState,
125125
shortBreakTimeInputFieldState = shortBreakTimeInputFieldState,
@@ -140,7 +140,7 @@ fun SettingsScreenRoot(
140140
@Composable
141141
private fun SettingsScreen(
142142
isPlus: Boolean,
143-
preferencesState: PreferencesState,
143+
settingsState: SettingsState,
144144
backStack: SnapshotStateList<Screen.Settings>,
145145
focusTimeInputFieldState: TextFieldState,
146146
shortBreakTimeInputFieldState: TextFieldState,
@@ -287,7 +287,7 @@ private fun SettingsScreen(
287287

288288
entry<Screen.Settings.Alarm> {
289289
AlarmSettings(
290-
preferencesState = preferencesState,
290+
settingsState = settingsState,
291291
alarmEnabled = alarmEnabled,
292292
vibrateEnabled = vibrateEnabled,
293293
alarmSound = alarmSound,
@@ -297,7 +297,7 @@ private fun SettingsScreen(
297297
}
298298
entry<Screen.Settings.Appearance> {
299299
AppearanceSettings(
300-
preferencesState = preferencesState,
300+
settingsState = settingsState,
301301
isPlus = isPlus,
302302
onAction = onAction,
303303
setShowPaywall = setShowPaywall,
@@ -307,7 +307,7 @@ private fun SettingsScreen(
307307
entry<Screen.Settings.Timer> {
308308
TimerSettings(
309309
isPlus = isPlus,
310-
aodEnabled = preferencesState.aodEnabled,
310+
aodEnabled = settingsState.aodEnabled,
311311
dndEnabled = dndEnabled,
312312
focusTimeInputFieldState = focusTimeInputFieldState,
313313
shortBreakTimeInputFieldState = shortBreakTimeInputFieldState,

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/screens/AlarmSettings.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ import kotlinx.coroutines.Dispatchers
6565
import kotlinx.coroutines.withContext
6666
import org.nsh07.pomodoro.R
6767
import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
68-
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
6968
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
69+
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
7070
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
7171
import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
7272
import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors
@@ -78,7 +78,7 @@ import org.nsh07.pomodoro.ui.theme.TomatoShapeDefaults.topListItemShape
7878
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
7979
@Composable
8080
fun AlarmSettings(
81-
preferencesState: PreferencesState,
81+
settingsState: SettingsState,
8282
alarmEnabled: Boolean,
8383
vibrateEnabled: Boolean,
8484
alarmSound: String,
@@ -126,8 +126,8 @@ fun AlarmSettings(
126126
}
127127

128128
val switchItems = remember(
129-
preferencesState.blackTheme,
130-
preferencesState.aodEnabled,
129+
settingsState.blackTheme,
130+
settingsState.aodEnabled,
131131
alarmEnabled,
132132
vibrateEnabled
133133
) {
@@ -242,9 +242,9 @@ fun AlarmSettings(
242242
@Preview
243243
@Composable
244244
fun AlarmSettingsPreview() {
245-
val preferencesState = PreferencesState()
245+
val settingsState = SettingsState()
246246
AlarmSettings(
247-
preferencesState = preferencesState,
247+
settingsState = settingsState,
248248
alarmEnabled = true,
249249
vibrateEnabled = false,
250250
alarmSound = "",

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/screens/AppearanceSettings.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
4949
import org.nsh07.pomodoro.ui.settingsScreen.components.ColorSchemePickerListItem
5050
import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider
5151
import org.nsh07.pomodoro.ui.settingsScreen.components.ThemePickerListItem
52-
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
5352
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
53+
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
5454
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
5555
import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
5656
import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors
@@ -62,7 +62,7 @@ import org.nsh07.pomodoro.utils.toColor
6262
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
6363
@Composable
6464
fun AppearanceSettings(
65-
preferencesState: PreferencesState,
65+
settingsState: SettingsState,
6666
isPlus: Boolean,
6767
onAction: (SettingsAction) -> Unit,
6868
setShowPaywall: (Boolean) -> Unit,
@@ -103,7 +103,7 @@ fun AppearanceSettings(
103103
}
104104
item {
105105
ThemePickerListItem(
106-
theme = preferencesState.theme,
106+
theme = settingsState.theme,
107107
onThemeChange = { onAction(SettingsAction.SaveTheme(it)) },
108108
items = if (isPlus) 3 else 1,
109109
index = 0
@@ -116,7 +116,7 @@ fun AppearanceSettings(
116116

117117
item {
118118
ColorSchemePickerListItem(
119-
color = preferencesState.colorScheme.toColor(),
119+
color = settingsState.colorScheme.toColor(),
120120
items = 3,
121121
index = if (isPlus) 1 else 0,
122122
isPlus = isPlus,
@@ -125,7 +125,7 @@ fun AppearanceSettings(
125125
}
126126
item {
127127
val item = SettingsSwitchItem(
128-
checked = preferencesState.blackTheme,
128+
checked = settingsState.blackTheme,
129129
icon = R.drawable.contrast,
130130
label = R.string.black_theme,
131131
description = R.string.black_theme_desc,
@@ -173,10 +173,10 @@ fun AppearanceSettings(
173173
@Preview
174174
@Composable
175175
fun AppearanceSettingsPreview() {
176-
val preferencesState = PreferencesState()
176+
val settingsState = SettingsState()
177177
TomatoTheme(dynamicColor = false) {
178178
AppearanceSettings(
179-
preferencesState = preferencesState,
179+
settingsState = settingsState,
180180
isPlus = false,
181181
onAction = {},
182182
setShowPaywall = {},

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/viewModel/PreferencesState.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Nishant Mishra
3+
*
4+
* This file is part of Tomato - a minimalist pomodoro timer for Android.
5+
*
6+
* Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
7+
* General Public License as published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
11+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12+
* Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with Tomato.
15+
* If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package org.nsh07.pomodoro.ui.settingsScreen.viewModel
19+
20+
import androidx.compose.runtime.Immutable
21+
import androidx.compose.ui.graphics.Color
22+
23+
@Immutable
24+
data class SettingsState(
25+
val theme: String = "auto",
26+
val colorScheme: String = Color.White.toString(),
27+
val blackTheme: Boolean = false,
28+
val aodEnabled: Boolean = false
29+
)

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/viewModel/SettingsViewModel.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class SettingsViewModel(
5959
private val _isSettingsLoaded = MutableStateFlow(false)
6060
val isSettingsLoaded = _isSettingsLoaded.asStateFlow()
6161

62-
private val _preferencesState = MutableStateFlow(PreferencesState())
63-
val preferencesState = _preferencesState.asStateFlow()
62+
private val _settingsState = MutableStateFlow(SettingsState())
63+
val settingsState = _settingsState.asStateFlow()
6464

6565
val focusTimeTextFieldState by lazy {
6666
TextFieldState((timerRepository.focusTime / 60000).toString())
@@ -203,7 +203,7 @@ class SettingsViewModel(
203203

204204
private fun saveColorScheme(colorScheme: Color) {
205205
viewModelScope.launch {
206-
_preferencesState.update { currentState ->
206+
_settingsState.update { currentState ->
207207
currentState.copy(colorScheme = colorScheme.toString())
208208
}
209209
preferenceRepository.saveStringPreference("color_scheme", colorScheme.toString())
@@ -212,7 +212,7 @@ class SettingsViewModel(
212212

213213
private fun saveTheme(theme: String) {
214214
viewModelScope.launch {
215-
_preferencesState.update { currentState ->
215+
_settingsState.update { currentState ->
216216
currentState.copy(theme = theme)
217217
}
218218
preferenceRepository.saveStringPreference("theme", theme)
@@ -221,7 +221,7 @@ class SettingsViewModel(
221221

222222
private fun saveBlackTheme(blackTheme: Boolean) {
223223
viewModelScope.launch {
224-
_preferencesState.update { currentState ->
224+
_settingsState.update { currentState ->
225225
currentState.copy(blackTheme = blackTheme)
226226
}
227227
preferenceRepository.saveBooleanPreference("black_theme", blackTheme)
@@ -230,15 +230,15 @@ class SettingsViewModel(
230230

231231
private fun saveAodEnabled(aodEnabled: Boolean) {
232232
viewModelScope.launch {
233-
_preferencesState.update { currentState ->
233+
_settingsState.update { currentState ->
234234
currentState.copy(aodEnabled = aodEnabled)
235235
}
236236
preferenceRepository.saveBooleanPreference("aod_enabled", aodEnabled)
237237
}
238238
}
239239

240240
fun resetPaywalledSettings() {
241-
_preferencesState.update { currentState ->
241+
_settingsState.update { currentState ->
242242
currentState.copy(
243243
aodEnabled = false,
244244
blackTheme = false,
@@ -257,7 +257,7 @@ class SettingsViewModel(
257257
val aodEnabled = preferenceRepository.getBooleanPreference("aod_enabled")
258258
?: preferenceRepository.saveBooleanPreference("aod_enabled", false)
259259

260-
_preferencesState.update { currentState ->
260+
_settingsState.update { currentState ->
261261
currentState.copy(
262262
theme = theme,
263263
colorScheme = colorScheme,

0 commit comments

Comments
 (0)