From 0c953254d1bf6494671444b77f35593be4d1f7d3 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Fri, 20 Dec 2024 16:06:50 +0100 Subject: [PATCH] refactor: Code cleaning --- .../ui/screen/newtransfer/ImportFilesViewModel.kt | 2 +- .../newtransfer/importfiles/ImportFilesScreen.kt | 12 ++++++------ .../newtransfer/upload/UploadSuccessEmailScreen.kt | 3 +-- .../screen/newtransfer/upload/UploadSuccessScreen.kt | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) 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 14e208c38..de8a89f80 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 @@ -228,7 +228,7 @@ class ImportFilesViewModel @Inject constructor( isRecipientEmailInvalid = { isRecipientEmailInvalid }, validatedRecipientsEmails = GetSetCallbacks( get = { validatedRecipientsEmails }, - set = { validatedRecipientsEmails = it } + set = { validatedRecipientsEmails = it }, ), ) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt index 2791799e7..dd2bafa10 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt @@ -198,12 +198,12 @@ private fun ImportFilesScreen( ) { val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.MAIL } } - val areEmailsCorrect by remember { + val areEmailsCorrects by remember { derivedStateOf { with(emailTextFieldCallbacks) { - val areAuthorAndRecipientCorrect = transferAuthorEmail.get().isNotEmpty() && !isAuthorEmailInvalid() + val areAuthorAndRecipientsCorrects = transferAuthorEmail.get().isNotEmpty() && !isAuthorEmailInvalid() && validatedRecipientsEmails.get().isNotEmpty() - !shouldShowEmailAddressesFields || areAuthorAndRecipientCorrect + !shouldShowEmailAddressesFields || areAuthorAndRecipientsCorrects } } } @@ -222,7 +222,7 @@ private fun ImportFilesScreen( filesToImportCount = filesToImportCount, currentSessionFilesCount = currentSessionFilesCount, importedFiles = files, - areEmailsCorrect = { areEmailsCorrect }, + areEmailsCorrects = { areEmailsCorrects }, sendStatus = sendStatus, sendTransfer = sendTransfer, ) @@ -412,7 +412,7 @@ private fun SendButton( filesToImportCount: () -> Int, currentSessionFilesCount: () -> Int, importedFiles: () -> List, - areEmailsCorrect: () -> Boolean, + areEmailsCorrects: () -> Boolean, sendStatus: () -> SendStatus, sendTransfer: () -> Unit, ) { @@ -432,7 +432,7 @@ private fun SendButton( title = stringResource(R.string.transferSendButton), style = ButtonType.PRIMARY, showIndeterminateProgress = { sendStatus() == SendStatus.Pending }, - enabled = { importedFiles().isNotEmpty() && !isImporting && areEmailsCorrect() && sendStatus().canEnableButton() }, + enabled = { importedFiles().isNotEmpty() && !isImporting && areEmailsCorrects() && sendStatus().canEnableButton() }, progress = progress, onClick = { sendTransfer() }, ) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt index e87ffb7a9..e1f622b7d 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt @@ -33,7 +33,6 @@ import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus import com.infomaniak.swisstransfer.ui.images.illus.beers.Beers import com.infomaniak.swisstransfer.ui.previewparameter.EmailsPreviewParameter -import com.infomaniak.swisstransfer.ui.previewparameter.emailsPreviewData import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme @@ -82,7 +81,7 @@ fun UploadSuccessEmailScreen(emails: List, closeActivity: () -> Unit) { private fun UploadSuccessEmailScreenPreview(@PreviewParameter(EmailsPreviewParameter::class) emails: List) { SwissTransferTheme { Surface { - UploadSuccessEmailScreen(closeActivity = {}, emails = emails) + UploadSuccessEmailScreen(emails) {} } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt index 8c872c524..9294a8a79 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt @@ -28,13 +28,13 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows fun UploadSuccessScreen( transferType: TransferTypeUi, transferUrl: String, - closeActivity: () -> Unit, recipients: List, + closeActivity: () -> Unit, ) { BackHandler(onBack = closeActivity) if (transferType == TransferTypeUi.MAIL) { - UploadSuccessEmailScreen(closeActivity = closeActivity, emails = recipients) + UploadSuccessEmailScreen(emails = recipients, closeActivity = closeActivity) } else { UploadSuccessQrScreen(transferType, transferUrl, closeActivity) } @@ -48,8 +48,8 @@ private fun UploadSuccessScreenPreview() { UploadSuccessScreen( transferType = TransferTypeUi.QR_CODE, transferUrl = "https://chk.me/83azQOl", - closeActivity = {}, recipients = emptyList(), + closeActivity = {}, ) } }