diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsViewModel.kt index bd66f0b39..732d2ce31 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsViewModel.kt @@ -25,7 +25,6 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.Theme import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod import com.infomaniak.multiplatform_swisstransfer.managers.AppSettingsManager import com.infomaniak.swisstransfer.di.IoDispatcher -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.PasswordTransferOption import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.launch @@ -54,11 +53,4 @@ class SettingsViewModel @Inject constructor( fun setEmailLanguage(emailLanguage: EmailLanguage) = viewModelScope.launch(ioDispatcher) { appSettingsManager.setEmailLanguage(emailLanguage) } - - data class AppSettingsData( - val validityPeriod: ValidityPeriod, - val downloadLimit: DownloadLimit, - val passwordOption: PasswordTransferOption, - val emailLanguage: EmailLanguage, - ) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt index 28772f586..de50527b4 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt @@ -18,10 +18,7 @@ package com.infomaniak.swisstransfer.ui.screen.newtransfer import android.net.Uri -import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue +import androidx.compose.runtime.* import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -151,52 +148,47 @@ class NewTransferViewModel @Inject constructor( } //region Transfer Type - private val _selectedTransferType = MutableStateFlow(savedStateHandle[SELECTED_TRANSFER_TYPE] ?: TransferType.LINK) - val selectedTransferType: StateFlow = _selectedTransferType + val selectedTransferType = savedStateHandle.getStateFlow(SELECTED_TRANSFER_TYPE, TransferType.LINK) fun selectTransferType(type: TransferType) { - _selectedTransferType.value = type savedStateHandle[SELECTED_TRANSFER_TYPE] = type } //endregion //region Transfer Advanced Options - - private val _selectedValidityPeriodOption = MutableStateFlow( - savedStateHandle[SELECTED_VALIDITY_PERIOD_KEY] + val selectedValidityPeriodOption = savedStateHandle.getStateFlow( + key = SELECTED_VALIDITY_PERIOD_KEY, + initialValue = ValidityPeriodOption.THIRTY ) - val selectedValidityPeriodOption: StateFlow = _selectedValidityPeriodOption.asStateFlow() - private val _selectedDownloadLimitOption = MutableStateFlow( - savedStateHandle[SELECTED_DOWNLOAD_LIMIT_KEY] + val selectedDownloadLimitOption = savedStateHandle.getStateFlow( + key = SELECTED_DOWNLOAD_LIMIT_KEY, + initialValue = DownloadLimitOption.TWO_HUNDRED_FIFTY, ) - val selectedDownloadLimitOption: StateFlow = _selectedDownloadLimitOption.asStateFlow() - private val _selectedPasswordOption = MutableStateFlow( - savedStateHandle[SELECTED_PASSWORD_OPTION_KEY] ?: PasswordTransferOption.NONE + val selectedPasswordOption = savedStateHandle.getStateFlow( + key = SELECTED_PASSWORD_OPTION_KEY, + initialValue = PasswordTransferOption.NONE, ) - val selectedPasswordOption: StateFlow = _selectedPasswordOption.asStateFlow() - private val _selectedLanguageOption = MutableStateFlow(savedStateHandle[SELECTED_LANGUAGE_KEY]) - val selectedLanguageOption: StateFlow = _selectedLanguageOption.asStateFlow() + val selectedLanguageOption = savedStateHandle.getStateFlow( + key = SELECTED_LANGUAGE_KEY, + initialValue = EmailLanguageOption.FRENCH, + ) private fun selectTransferValidityPeriod(validityPeriodOption: ValidityPeriodOption) { - _selectedValidityPeriodOption.value = validityPeriodOption savedStateHandle[SELECTED_VALIDITY_PERIOD_KEY] = validityPeriodOption } private fun selectTransferDownloadLimit(downloadLimit: DownloadLimitOption) { - _selectedDownloadLimitOption.value = downloadLimit savedStateHandle[SELECTED_DOWNLOAD_LIMIT_KEY] = downloadLimit } private fun selectTransferPasswordOption(passwordOption: PasswordTransferOption) { - _selectedPasswordOption.value = passwordOption savedStateHandle[SELECTED_PASSWORD_OPTION_KEY] = passwordOption } private fun selectTransferLanguage(language: EmailLanguageOption) { - _selectedLanguageOption.value = language savedStateHandle[SELECTED_LANGUAGE_KEY] = language }