Skip to content

Commit

Permalink
chore(TransferPasswordAlertDialog): Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Nov 12, 2024
1 parent ec7c5fb commit 5e4c419
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) } }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,52 +148,47 @@ class ImportFilesViewModel @Inject constructor(
}

//region Transfer Type
private val _selectedTransferType = MutableStateFlow(savedStateHandle[SELECTED_TRANSFER_TYPE] ?: TransferType.LINK)
val selectedTransferType: StateFlow<TransferType> = _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<ValidityPeriodOption?>(
savedStateHandle[SELECTED_VALIDITY_PERIOD_KEY]
val selectedValidityPeriodOption = savedStateHandle.getStateFlow(
key = SELECTED_VALIDITY_PERIOD_KEY,
initialValue = ValidityPeriodOption.THIRTY
)
val selectedValidityPeriodOption: StateFlow<ValidityPeriodOption?> = _selectedValidityPeriodOption.asStateFlow()

private val _selectedDownloadLimitOption = MutableStateFlow<DownloadLimitOption?>(
savedStateHandle[SELECTED_DOWNLOAD_LIMIT_KEY]
val selectedDownloadLimitOption = savedStateHandle.getStateFlow(
key = SELECTED_DOWNLOAD_LIMIT_KEY,
initialValue = DownloadLimitOption.TWO_HUNDRED_FIFTY,
)
val selectedDownloadLimitOption: StateFlow<DownloadLimitOption?> = _selectedDownloadLimitOption.asStateFlow()

private val _selectedPasswordOption = MutableStateFlow<PasswordTransferOption?>(
savedStateHandle[SELECTED_PASSWORD_OPTION_KEY] ?: PasswordTransferOption.NONE
val selectedPasswordOption = savedStateHandle.getStateFlow(
key = SELECTED_PASSWORD_OPTION_KEY,
initialValue = PasswordTransferOption.NONE,
)
val selectedPasswordOption: StateFlow<PasswordTransferOption?> = _selectedPasswordOption.asStateFlow()

private val _selectedLanguageOption = MutableStateFlow<EmailLanguageOption?>(savedStateHandle[SELECTED_LANGUAGE_KEY])
val selectedLanguageOption: StateFlow<EmailLanguageOption?> = _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
}

Expand Down

0 comments on commit 5e4c419

Please sign in to comment.