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 b4fd8d9bf..3525ce5c5 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 @@ -64,7 +64,7 @@ class ImportFilesViewModel @Inject constructor( @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : ViewModel() { - private val _sendActionResult = MutableStateFlow(null) + private val _sendActionResult = MutableStateFlow(SendActionResult.NotStarted) val sendActionResult = _sendActionResult.asStateFlow() @OptIn(FlowPreview::class) @@ -129,11 +129,11 @@ class ImportFilesViewModel @Inject constructor( } fun sendTransfer() { - _sendActionResult.update{ SendActionResult.Pending } + _sendActionResult.update { SendActionResult.Pending } viewModelScope.launch(ioDispatcher) { runCatching { val uuid = uploadManager.createAndGetUpload(generateNewUploadSession()).uuid - uploadManager.initUploadSession(recaptcha = "Recaptcha")!! // TODO Handle ContainerErrorsException here + uploadManager.initUploadSession(recaptcha = "Recaptcha")!! // TODO: Handle ContainerErrorsException here uploadWorkerScheduler.scheduleWork(uuid) _sendActionResult.update { val totalSize = importationFilesManager.importedFiles.value.sumOf { it.fileSize } @@ -258,8 +258,9 @@ class ImportFilesViewModel @Inject constructor( //endregion sealed class SendActionResult { - data class Success(val totalSize: Long) : SendActionResult() + data object NotStarted : SendActionResult() data object Pending : SendActionResult() + data class Success(val totalSize: Long) : SendActionResult() data object Failure : SendActionResult() } 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 b973a829e..1d7b7ecba 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 @@ -126,7 +126,7 @@ fun ImportFilesScreen( closeActivity = closeActivity, shouldStartByPromptingUserForFiles = true, sendTransfer = importFilesViewModel::sendTransfer, - isTransferPending = { sendActionResult == SendActionResult.Pending }, + isTransferStarted = { sendActionResult != SendActionResult.NotStarted }, ) } @@ -158,7 +158,7 @@ private fun ImportFilesScreen( closeActivity: () -> Unit, shouldStartByPromptingUserForFiles: Boolean, sendTransfer: () -> Unit, - isTransferPending: () -> Boolean, + isTransferStarted: () -> Boolean, ) { val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.MAIL } } @@ -179,7 +179,7 @@ private fun ImportFilesScreen( importedFiles = files, shouldShowEmailAddressesFields = { shouldShowEmailAddressesFields }, transferAuthorEmail = transferAuthorEmail, - isTransferPending = isTransferPending, + isTransferStarted = isTransferStarted, navigateToUploadProgress = sendTransfer, ) }, @@ -357,7 +357,7 @@ private fun SendButton( importedFiles: () -> List, shouldShowEmailAddressesFields: () -> Boolean, transferAuthorEmail: GetSetCallbacks, - isTransferPending: () -> Boolean, + isTransferStarted: () -> Boolean, navigateToUploadProgress: () -> Unit, ) { val remainingFilesCount = filesToImportCount() @@ -379,7 +379,8 @@ private fun SendButton( modifier = modifier, title = stringResource(R.string.transferSendButton), style = ButtonType.PRIMARY, - enabled = { importedFiles().isNotEmpty() && !isImporting && isSenderEmailCorrect && !isTransferPending() }, + enabled = { importedFiles().isNotEmpty() && !isImporting && isSenderEmailCorrect && !isTransferStarted() }, + showIndeterminateProgress = { isTransferStarted() }, progress = progress, onClick = navigateToUploadProgress, ) @@ -447,7 +448,7 @@ private fun Preview(@PreviewParameter(FileUiListPreviewParameter::class) files: addFiles = {}, closeActivity = {}, shouldStartByPromptingUserForFiles = false, - isTransferPending = { false }, + isTransferStarted = { false }, sendTransfer = {}, ) }