refactor(settings): use MVI intents instead of lambdas

#117
This commit is contained in:
Nishant Mishra
2025-11-07 17:50:07 +05:30
parent d441289e72
commit 42582545bf
6 changed files with 83 additions and 73 deletions

View File

@@ -19,8 +19,6 @@ package org.nsh07.pomodoro.ui.settingsScreen
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.LocaleManager import android.app.LocaleManager
import android.content.Intent
import android.net.Uri
import android.os.Build import android.os.Build
import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut import androidx.compose.animation.fadeOut
@@ -55,7 +53,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
@@ -68,7 +65,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation3.runtime.entryProvider import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.ui.NavDisplay import androidx.navigation3.ui.NavDisplay
import org.nsh07.pomodoro.R import org.nsh07.pomodoro.R
import org.nsh07.pomodoro.service.TimerService
import org.nsh07.pomodoro.ui.Screen import org.nsh07.pomodoro.ui.Screen
import org.nsh07.pomodoro.ui.settingsScreen.components.AboutCard import org.nsh07.pomodoro.ui.settingsScreen.components.AboutCard
import org.nsh07.pomodoro.ui.settingsScreen.components.ClickableListItem import org.nsh07.pomodoro.ui.settingsScreen.components.ClickableListItem
@@ -78,6 +74,7 @@ import org.nsh07.pomodoro.ui.settingsScreen.screens.AlarmSettings
import org.nsh07.pomodoro.ui.settingsScreen.screens.AppearanceSettings import org.nsh07.pomodoro.ui.settingsScreen.screens.AppearanceSettings
import org.nsh07.pomodoro.ui.settingsScreen.screens.TimerSettings import org.nsh07.pomodoro.ui.settingsScreen.screens.TimerSettings
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsViewModel import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsViewModel
import org.nsh07.pomodoro.ui.settingsScreens import org.nsh07.pomodoro.ui.settingsScreens
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
@@ -92,8 +89,6 @@ fun SettingsScreenRoot(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.Factory) viewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.Factory)
) { ) {
val context = LocalContext.current
val backStack = viewModel.backStack val backStack = viewModel.backStack
DisposableEffect(Unit) { DisposableEffect(Unit) {
@@ -134,20 +129,7 @@ fun SettingsScreenRoot(
vibrateEnabled = vibrateEnabled, vibrateEnabled = vibrateEnabled,
dndEnabled = dndEnabled, dndEnabled = dndEnabled,
alarmSound = alarmSound, alarmSound = alarmSound,
onAlarmEnabledChange = viewModel::saveAlarmEnabled, onAction = viewModel::onAction,
onVibrateEnabledChange = viewModel::saveVibrateEnabled,
onBlackThemeChange = viewModel::saveBlackTheme,
onAodEnabledChange = viewModel::saveAodEnabled,
onDndEnabledChange = viewModel::saveDndEnabled,
onAlarmSoundChanged = {
viewModel.saveAlarmSound(it)
Intent(context, TimerService::class.java).apply {
action = TimerService.Actions.RESET.toString()
context.startService(this)
}
},
onThemeChange = viewModel::saveTheme,
onColorSchemeChange = viewModel::saveColorScheme,
setShowPaywall = setShowPaywall, setShowPaywall = setShowPaywall,
modifier = modifier modifier = modifier
) )
@@ -168,14 +150,7 @@ private fun SettingsScreen(
vibrateEnabled: Boolean, vibrateEnabled: Boolean,
dndEnabled: Boolean, dndEnabled: Boolean,
alarmSound: String, alarmSound: String,
onAlarmEnabledChange: (Boolean) -> Unit, onAction: (SettingsAction) -> Unit,
onVibrateEnabledChange: (Boolean) -> Unit,
onBlackThemeChange: (Boolean) -> Unit,
onAodEnabledChange: (Boolean) -> Unit,
onDndEnabledChange: (Boolean) -> Unit,
onAlarmSoundChanged: (Uri?) -> Unit,
onThemeChange: (String) -> Unit,
onColorSchemeChange: (Color) -> Unit,
setShowPaywall: (Boolean) -> Unit, setShowPaywall: (Boolean) -> Unit,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
@@ -316,9 +291,7 @@ private fun SettingsScreen(
alarmEnabled = alarmEnabled, alarmEnabled = alarmEnabled,
vibrateEnabled = vibrateEnabled, vibrateEnabled = vibrateEnabled,
alarmSound = alarmSound, alarmSound = alarmSound,
onAlarmEnabledChange = onAlarmEnabledChange, onAction = onAction,
onVibrateEnabledChange = onVibrateEnabledChange,
onAlarmSoundChanged = onAlarmSoundChanged,
onBack = backStack::removeLastOrNull onBack = backStack::removeLastOrNull
) )
} }
@@ -326,9 +299,7 @@ private fun SettingsScreen(
AppearanceSettings( AppearanceSettings(
preferencesState = preferencesState, preferencesState = preferencesState,
isPlus = isPlus, isPlus = isPlus,
onBlackThemeChange = onBlackThemeChange, onAction = onAction,
onThemeChange = onThemeChange,
onColorSchemeChange = onColorSchemeChange,
setShowPaywall = setShowPaywall, setShowPaywall = setShowPaywall,
onBack = backStack::removeLastOrNull onBack = backStack::removeLastOrNull
) )
@@ -342,8 +313,7 @@ private fun SettingsScreen(
shortBreakTimeInputFieldState = shortBreakTimeInputFieldState, shortBreakTimeInputFieldState = shortBreakTimeInputFieldState,
longBreakTimeInputFieldState = longBreakTimeInputFieldState, longBreakTimeInputFieldState = longBreakTimeInputFieldState,
sessionsSliderState = sessionsSliderState, sessionsSliderState = sessionsSliderState,
onAodEnabledChange = onAodEnabledChange, onAction = onAction,
onDndEnabledChange = onDndEnabledChange,
setShowPaywall = setShowPaywall, setShowPaywall = setShowPaywall,
onBack = backStack::removeLastOrNull, onBack = backStack::removeLastOrNull,
) )

View File

@@ -17,6 +17,7 @@
package org.nsh07.pomodoro.ui.settingsScreen.screens package org.nsh07.pomodoro.ui.settingsScreen.screens
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.media.RingtoneManager import android.media.RingtoneManager
@@ -65,6 +66,7 @@ import kotlinx.coroutines.withContext
import org.nsh07.pomodoro.R import org.nsh07.pomodoro.R
import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors
@@ -80,9 +82,7 @@ fun AlarmSettings(
alarmEnabled: Boolean, alarmEnabled: Boolean,
vibrateEnabled: Boolean, vibrateEnabled: Boolean,
alarmSound: String, alarmSound: String,
onAlarmEnabledChange: (Boolean) -> Unit, onAction: (SettingsAction) -> Unit,
onVibrateEnabledChange: (Boolean) -> Unit,
onAlarmSoundChanged: (Uri?) -> Unit,
onBack: () -> Unit, onBack: () -> Unit,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
@@ -112,10 +112,11 @@ fun AlarmSettings(
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
result.data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) result.data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
} }
onAlarmSoundChanged(uri) onAction(SettingsAction.SaveAlarmSound(uri))
} }
} }
@SuppressLint("LocalContextGetResourceValueCall")
val ringtonePickerIntent = remember(alarmSound) { val ringtonePickerIntent = remember(alarmSound) {
Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply { Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM) putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM)
@@ -136,14 +137,14 @@ fun AlarmSettings(
icon = R.drawable.alarm_on, icon = R.drawable.alarm_on,
label = R.string.sound, label = R.string.sound,
description = R.string.alarm_desc, description = R.string.alarm_desc,
onClick = onAlarmEnabledChange onClick = { onAction(SettingsAction.SaveAlarmEnabled(it)) }
), ),
SettingsSwitchItem( SettingsSwitchItem(
checked = vibrateEnabled, checked = vibrateEnabled,
icon = R.drawable.mobile_vibrate, icon = R.drawable.mobile_vibrate,
label = R.string.vibrate, label = R.string.vibrate,
description = R.string.vibrate_desc, description = R.string.vibrate_desc,
onClick = onVibrateEnabledChange onClick = { onAction(SettingsAction.SaveVibrateEnabled(it)) }
) )
) )
} }
@@ -247,8 +248,6 @@ fun AlarmSettingsPreview() {
alarmEnabled = true, alarmEnabled = true,
vibrateEnabled = false, vibrateEnabled = false,
alarmSound = "", alarmSound = "",
onAlarmEnabledChange = {}, onAction = {},
onVibrateEnabledChange = {},
onAlarmSoundChanged = {},
onBack = {}) onBack = {})
} }

View File

@@ -39,7 +39,6 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@@ -51,6 +50,7 @@ import org.nsh07.pomodoro.ui.settingsScreen.components.ColorSchemePickerListItem
import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider
import org.nsh07.pomodoro.ui.settingsScreen.components.ThemePickerListItem import org.nsh07.pomodoro.ui.settingsScreen.components.ThemePickerListItem
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState import org.nsh07.pomodoro.ui.settingsScreen.viewModel.PreferencesState
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors
@@ -64,9 +64,7 @@ import org.nsh07.pomodoro.utils.toColor
fun AppearanceSettings( fun AppearanceSettings(
preferencesState: PreferencesState, preferencesState: PreferencesState,
isPlus: Boolean, isPlus: Boolean,
onBlackThemeChange: (Boolean) -> Unit, onAction: (SettingsAction) -> Unit,
onThemeChange: (String) -> Unit,
onColorSchemeChange: (Color) -> Unit,
setShowPaywall: (Boolean) -> Unit, setShowPaywall: (Boolean) -> Unit,
onBack: () -> Unit, onBack: () -> Unit,
modifier: Modifier = Modifier modifier: Modifier = Modifier
@@ -106,7 +104,7 @@ fun AppearanceSettings(
item { item {
ThemePickerListItem( ThemePickerListItem(
theme = preferencesState.theme, theme = preferencesState.theme,
onThemeChange = onThemeChange, onThemeChange = { onAction(SettingsAction.SaveTheme(it)) },
items = if (isPlus) 3 else 1, items = if (isPlus) 3 else 1,
index = 0 index = 0
) )
@@ -122,7 +120,7 @@ fun AppearanceSettings(
items = 3, items = 3,
index = if (isPlus) 1 else 0, index = if (isPlus) 1 else 0,
isPlus = isPlus, isPlus = isPlus,
onColorChange = onColorSchemeChange, onColorChange = { onAction(SettingsAction.SaveColorScheme(it)) },
) )
} }
item { item {
@@ -131,7 +129,7 @@ fun AppearanceSettings(
icon = R.drawable.contrast, icon = R.drawable.contrast,
label = R.string.black_theme, label = R.string.black_theme,
description = R.string.black_theme_desc, description = R.string.black_theme_desc,
onClick = onBlackThemeChange onClick = { onAction(SettingsAction.SaveBlackTheme(it)) }
) )
ListItem( ListItem(
leadingContent = { leadingContent = {
@@ -180,9 +178,7 @@ fun AppearanceSettingsPreview() {
AppearanceSettings( AppearanceSettings(
preferencesState = preferencesState, preferencesState = preferencesState,
isPlus = false, isPlus = false,
onBlackThemeChange = {}, onAction = {},
onThemeChange = {},
onColorSchemeChange = {},
setShowPaywall = {}, setShowPaywall = {},
onBack = {} onBack = {}
) )

View File

@@ -36,6 +36,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
@@ -76,6 +77,7 @@ import org.nsh07.pomodoro.R
import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
import org.nsh07.pomodoro.ui.settingsScreen.components.MinuteInputField import org.nsh07.pomodoro.ui.settingsScreen.components.MinuteInputField
import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar import org.nsh07.pomodoro.ui.theme.AppFonts.robotoFlexTopBar
import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors import org.nsh07.pomodoro.ui.theme.CustomColors.switchColors
@@ -96,11 +98,10 @@ fun TimerSettings(
shortBreakTimeInputFieldState: TextFieldState, shortBreakTimeInputFieldState: TextFieldState,
longBreakTimeInputFieldState: TextFieldState, longBreakTimeInputFieldState: TextFieldState,
sessionsSliderState: SliderState, sessionsSliderState: SliderState,
onAodEnabledChange: (Boolean) -> Unit, setShowPaywall: (Boolean) -> Unit,
onDndEnabledChange: (Boolean) -> Unit, onAction: (SettingsAction) -> Unit,
onBack: () -> Unit, onBack: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier
setShowPaywall: (Boolean) -> Unit
) { ) {
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior() val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
val context = LocalContext.current val context = LocalContext.current
@@ -110,7 +111,7 @@ fun TimerSettings(
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
if (!notificationManagerService.isNotificationPolicyAccessGranted()) if (!notificationManagerService.isNotificationPolicyAccessGranted())
onDndEnabledChange(false) onAction(SettingsAction.SaveDndEnabled(false))
} }
val switchItems = listOf( val switchItems = listOf(
@@ -128,7 +129,7 @@ fun TimerSettings(
} else if (!it && notificationManagerService.isNotificationPolicyAccessGranted()) { } else if (!it && notificationManagerService.isNotificationPolicyAccessGranted()) {
notificationManagerService.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL) notificationManagerService.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL)
} }
onDndEnabledChange(it) onAction(SettingsAction.SaveDndEnabled(it))
} }
), ),
SettingsSwitchItem( SettingsSwitchItem(
@@ -136,7 +137,7 @@ fun TimerSettings(
icon = R.drawable.aod, icon = R.drawable.aod,
label = R.string.always_on_display, label = R.string.always_on_display,
description = R.string.always_on_display_desc, description = R.string.always_on_display_desc,
onClick = onAodEnabledChange onClick = { onAction(SettingsAction.SaveAodEnabled(it)) }
) )
) )
@@ -313,7 +314,7 @@ fun TimerSettings(
item { item {
PlusDivider(setShowPaywall) PlusDivider(setShowPaywall)
} }
itemsIndexed(switchItems.drop(1)) { index, item -> items(switchItems.drop(1)) { item ->
ListItem( ListItem(
leadingContent = { leadingContent = {
Icon( Icon(
@@ -408,8 +409,7 @@ private fun TimerSettingsPreview() {
shortBreakTimeInputFieldState = shortBreakTimeInputFieldState, shortBreakTimeInputFieldState = shortBreakTimeInputFieldState,
longBreakTimeInputFieldState = longBreakTimeInputFieldState, longBreakTimeInputFieldState = longBreakTimeInputFieldState,
sessionsSliderState = sessionsSliderState, sessionsSliderState = sessionsSliderState,
onAodEnabledChange = {}, onAction = {},
onDndEnabledChange = {},
setShowPaywall = {}, setShowPaywall = {},
onBack = {} onBack = {}
) )

View File

@@ -0,0 +1,32 @@
/*
* 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 android.net.Uri
import androidx.compose.ui.graphics.Color
sealed interface SettingsAction {
data class SaveAlarmEnabled(val enabled: Boolean) : SettingsAction
data class SaveVibrateEnabled(val enabled: Boolean) : SettingsAction
data class SaveBlackTheme(val enabled: Boolean) : SettingsAction
data class SaveAodEnabled(val enabled: Boolean) : SettingsAction
data class SaveDndEnabled(val enabled: Boolean) : SettingsAction
data class SaveAlarmSound(val uri: Uri?) : SettingsAction
data class SaveTheme(val theme: String) : SettingsAction
data class SaveColorScheme(val color: Color) : SettingsAction
}

View File

@@ -103,6 +103,19 @@ class SettingsViewModel(
} }
} }
fun onAction(action: SettingsAction) {
when (action) {
is SettingsAction.SaveAlarmSound -> saveAlarmSound(action.uri)
is SettingsAction.SaveAlarmEnabled -> saveAlarmEnabled(action.enabled)
is SettingsAction.SaveVibrateEnabled -> saveVibrateEnabled(action.enabled)
is SettingsAction.SaveDndEnabled -> saveDndEnabled(action.enabled)
is SettingsAction.SaveColorScheme -> saveColorScheme(action.color)
is SettingsAction.SaveTheme -> saveTheme(action.theme)
is SettingsAction.SaveBlackTheme -> saveBlackTheme(action.enabled)
is SettingsAction.SaveAodEnabled -> saveAodEnabled(action.enabled)
}
}
private fun updateSessionLength() { private fun updateSessionLength() {
viewModelScope.launch { viewModelScope.launch {
timerRepository.sessionLength = preferenceRepository.saveIntPreference( timerRepository.sessionLength = preferenceRepository.saveIntPreference(
@@ -160,35 +173,35 @@ class SettingsViewModel(
longBreakFlowCollectionJob?.cancel() longBreakFlowCollectionJob?.cancel()
} }
fun saveAlarmEnabled(enabled: Boolean) { private fun saveAlarmEnabled(enabled: Boolean) {
viewModelScope.launch { viewModelScope.launch {
timerRepository.alarmEnabled = enabled timerRepository.alarmEnabled = enabled
preferenceRepository.saveBooleanPreference("alarm_enabled", enabled) preferenceRepository.saveBooleanPreference("alarm_enabled", enabled)
} }
} }
fun saveVibrateEnabled(enabled: Boolean) { private fun saveVibrateEnabled(enabled: Boolean) {
viewModelScope.launch { viewModelScope.launch {
timerRepository.vibrateEnabled = enabled timerRepository.vibrateEnabled = enabled
preferenceRepository.saveBooleanPreference("vibrate_enabled", enabled) preferenceRepository.saveBooleanPreference("vibrate_enabled", enabled)
} }
} }
fun saveDndEnabled(enabled: Boolean) { private fun saveDndEnabled(enabled: Boolean) {
viewModelScope.launch { viewModelScope.launch {
timerRepository.dndEnabled = enabled timerRepository.dndEnabled = enabled
preferenceRepository.saveBooleanPreference("dnd_enabled", enabled) preferenceRepository.saveBooleanPreference("dnd_enabled", enabled)
} }
} }
fun saveAlarmSound(uri: Uri?) { private fun saveAlarmSound(uri: Uri?) {
viewModelScope.launch { viewModelScope.launch {
timerRepository.alarmSoundUri = uri timerRepository.alarmSoundUri = uri
preferenceRepository.saveStringPreference("alarm_sound", uri.toString()) preferenceRepository.saveStringPreference("alarm_sound", uri.toString())
} }
} }
fun saveColorScheme(colorScheme: Color) { private fun saveColorScheme(colorScheme: Color) {
viewModelScope.launch { viewModelScope.launch {
_preferencesState.update { currentState -> _preferencesState.update { currentState ->
currentState.copy(colorScheme = colorScheme.toString()) currentState.copy(colorScheme = colorScheme.toString())
@@ -197,7 +210,7 @@ class SettingsViewModel(
} }
} }
fun saveTheme(theme: String) { private fun saveTheme(theme: String) {
viewModelScope.launch { viewModelScope.launch {
_preferencesState.update { currentState -> _preferencesState.update { currentState ->
currentState.copy(theme = theme) currentState.copy(theme = theme)
@@ -206,7 +219,7 @@ class SettingsViewModel(
} }
} }
fun saveBlackTheme(blackTheme: Boolean) { private fun saveBlackTheme(blackTheme: Boolean) {
viewModelScope.launch { viewModelScope.launch {
_preferencesState.update { currentState -> _preferencesState.update { currentState ->
currentState.copy(blackTheme = blackTheme) currentState.copy(blackTheme = blackTheme)
@@ -215,7 +228,7 @@ class SettingsViewModel(
} }
} }
fun saveAodEnabled(aodEnabled: Boolean) { private fun saveAodEnabled(aodEnabled: Boolean) {
viewModelScope.launch { viewModelScope.launch {
_preferencesState.update { currentState -> _preferencesState.update { currentState ->
currentState.copy(aodEnabled = aodEnabled) currentState.copy(aodEnabled = aodEnabled)