From 5e4c419a824e13c03964d8670ccf5b0cb0c85c53 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Thu, 7 Nov 2024 14:38:42 +0100 Subject: [PATCH] chore(TransferPasswordAlertDialog): Apply suggestions --- .../ui/components/SwissTransferAlertDialog.kt | 2 +- .../ui/components/SwissTransferTextField.kt | 7 +++- .../screen/main/settings/SettingsViewModel.kt | 8 ---- .../newtransfer/ImportFilesViewModel.kt | 38 ++++++++----------- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferAlertDialog.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferAlertDialog.kt index bac92d569..e2462c187 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferAlertDialog.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferAlertDialog.kt @@ -73,6 +73,7 @@ private fun BasicAlertDialogContent( ) { Column(modifier.padding(Margin.Large)) { TitleAndDescription(titleRes, descriptionRes) + Spacer(Modifier.height(Margin.Large)) additionalContent?.let { it() Spacer(Modifier.height(Margin.Large)) @@ -94,7 +95,6 @@ private fun TitleAndDescription(titleRes: Int, descriptionRes: Int) { style = SwissTransferTheme.typography.bodyRegular, color = SwissTransferTheme.colors.secondaryTextColor, ) - Spacer(Modifier.height(Margin.Large)) } @Composable diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTextField.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTextField.kt index 1601ffa31..a38b97104 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTextField.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTextField.kt @@ -78,7 +78,12 @@ fun SwissTransferTextField( @Composable fun getSupportingText(): (@Composable () -> Unit)? { - val displayText = if (text.isEmpty()) supportingText else errorMessage() ?: supportingText + val displayText = if (text.isEmpty()) { + supportingText + } else { + errorMessage() ?: supportingText + } + return displayText?.let { @Composable { Text(it) } } } 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/ImportFilesViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt index 01fb9736b..7375b875f 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.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 ImportFilesViewModel @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 }