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 3525ce5c5..1875d0c79 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 @@ -146,6 +146,10 @@ class ImportFilesViewModel @Inject constructor( } } + fun resetSendActionResult() { + _sendActionResult.value = SendActionResult.NotStarted + } + private suspend fun removeOldData() { importationFilesManager.removeLocalCopyFolder() uploadManager.removeAllUploadSession() 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 1d7b7ecba..2f715a259 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 @@ -25,11 +25,13 @@ import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.PreviewParameter @@ -73,7 +75,9 @@ fun ImportFilesScreen( val sendActionResult by importFilesViewModel.sendActionResult.collectAsStateWithLifecycle() - HandleSendActionResult({ sendActionResult }, { selectedTransferType }, navigateToUploadProgress) + val snackbarHostState = remember { SnackbarHostState() } + + HandleSendActionResult(snackbarHostState, { sendActionResult }, { selectedTransferType }, navigateToUploadProgress) LaunchedEffect(Unit) { importFilesViewModel.initTransferOptionsValues() } @@ -126,20 +130,24 @@ fun ImportFilesScreen( closeActivity = closeActivity, shouldStartByPromptingUserForFiles = true, sendTransfer = importFilesViewModel::sendTransfer, - isTransferStarted = { sendActionResult != SendActionResult.NotStarted }, + isTransferStarted = { sendActionResult != SendActionResult.NotStarted && sendActionResult != SendActionResult.Failure }, + snackbarHostState = snackbarHostState, ) } @Composable private fun HandleSendActionResult( + snackbarHostState: SnackbarHostState, getSendActionResult: () -> SendActionResult?, transferType: () -> TransferTypeUi, navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long) -> Unit, ) { + val context = LocalContext.current + LaunchedEffect(getSendActionResult()) { when (val actionResult = getSendActionResult()) { is SendActionResult.Success -> navigateToUploadProgress(transferType(), actionResult.totalSize) - is SendActionResult.Failure -> Unit // TODO: Show error + is SendActionResult.Failure -> snackbarHostState.showSnackbar(context.getString(R.string.errorUnknown)) else -> Unit } } @@ -159,6 +167,7 @@ private fun ImportFilesScreen( shouldStartByPromptingUserForFiles: Boolean, sendTransfer: () -> Unit, isTransferStarted: () -> Boolean, + snackbarHostState: SnackbarHostState? = null, ) { val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.MAIL } } @@ -197,7 +206,8 @@ private fun ImportFilesScreen( ) TransferOptions(modifier, transferOptionsCallbacks) } - } + }, + snackbarHostState = snackbarHostState, ) } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index ff253573c..d5faf95bb 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -33,6 +33,7 @@ Neuer Transfer Heruntergeladene Übertragung: %d/%d Das Passwort muss zwischen 6 und 25 Zeichen lang sein + Ein Fehler ist aufgetreten Verfällt in %d Tagen %d Datei diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index e27538bac..7e1d88827 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -33,6 +33,7 @@ Nueva transferencia Transferencia descargada: %d/%d La contraseña debe tener entre 6 y 25 caracteres + Se ha producido un error Caduca en %d días %d archivo diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index b656177a6..5c7661b50 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -33,6 +33,7 @@ Nouveau transfert Transfert téléchargé : %d/%d\u0020 Le mot de passe doit comporter entre 6 et 25 caractères + Une erreur est survenue Expire dans %d jours %d fichier diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index df680a40f..71c00a75c 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -33,6 +33,7 @@ Nuovo trasferimento Trasferimento scaricato: %d/%d La password deve essere compresa tra 6 e 24 caratteri + Si è verificato un errore Scade tra %d giorni %d file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 00c300514..17b259870 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,6 +37,7 @@ New transfer Downloaded transfer: %d/%d\u0020 The password must be between 6 and 25 characters + An error has occurred Expires in %d days %d file