From 4ffd5a894b9e1d2ac9a591e06e0b0eb3c77a3193 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Thu, 19 Dec 2024 11:46:07 +0100 Subject: [PATCH] feat: When retrying the uploading transfer, we keep transfer data when going back to ImportFiles instead of resetting it --- .../screen/newtransfer/NewTransferNavHost.kt | 5 ++++- .../newtransfer/upload/UploadErrorScreen.kt | 21 ++++++++++++------- .../upload/UploadProgressScreen.kt | 14 ++++++++++++- .../upload/UploadProgressViewModel.kt | 4 ++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 39 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferNavHost.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferNavHost.kt index 8a25375cb..20499673d 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferNavHost.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferNavHost.kt @@ -65,7 +65,10 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un ) } composable { - UploadErrorScreen(navigateToImportFiles = { navController.navigate(ImportFilesDestination) }) + UploadErrorScreen( + retryTransfer = { /* TODO */ }, + navigateBackToImportFiles = { navController.popBackStack(route = ImportFilesDestination, inclusive = false) }, + ) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadErrorScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadErrorScreen.kt index bc22273aa..2c6889956 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadErrorScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadErrorScreen.kt @@ -21,10 +21,7 @@ import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import com.infomaniak.swisstransfer.R -import com.infomaniak.swisstransfer.ui.components.BottomStickyButtonScaffold -import com.infomaniak.swisstransfer.ui.components.BrandTopAppBar -import com.infomaniak.swisstransfer.ui.components.EmptyState -import com.infomaniak.swisstransfer.ui.components.LargeButton +import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus import com.infomaniak.swisstransfer.ui.images.illus.uploadError.GhostMagnifyingGlassQuestionMark import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme @@ -32,14 +29,22 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows import com.infomaniak.core2.R as RCore2 @Composable -fun UploadErrorScreen(navigateToImportFiles: () -> Unit) { +fun UploadErrorScreen(retryTransfer: () -> Unit, navigateBackToImportFiles: () -> Unit) { BottomStickyButtonScaffold( topBar = { BrandTopAppBar() }, - bottomButton = { + topButton = { LargeButton( modifier = it, title = stringResource(RCore2.string.buttonRetry), - onClick = navigateToImportFiles, + onClick = retryTransfer, + ) + }, + bottomButton = { + LargeButton( + modifier = it, + title = stringResource(R.string.buttonEditTransfer), + style = ButtonType.SECONDARY, + onClick = navigateBackToImportFiles, ) } ) { @@ -56,7 +61,7 @@ fun UploadErrorScreen(navigateToImportFiles: () -> Unit) { private fun UploadErrorScreenPreview() { SwissTransferTheme { Surface { - UploadErrorScreen({}) + UploadErrorScreen({}, {}) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressScreen.kt index 69ad7570d..b55ee9287 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressScreen.kt @@ -66,7 +66,19 @@ fun UploadProgressScreen( uploadProgressViewModel.trackUploadProgress() } - HandleProgressState({ uiState }, navigateToUploadSuccess, navigateToUploadError, navigateBackToImportFiles) + HandleProgressState( + uiState = { uiState }, + navigateToUploadSuccess = navigateToUploadSuccess, + navigateToUploadError = { + // If the transfer fails, we need to remove the upload session + // before going back to ImportFilesScreen to edit the transfer. + // TODO: This is possibly only mandatory for editing the transfer, and not retrying it. + // This needs to be checked when implementing the "Retry" feature. + uploadProgressViewModel.removeAllUploadSession() + navigateToUploadError() + }, + navigateBackToImportFiles = navigateBackToImportFiles, + ) UploadProgressScreen( progressState = { uiState }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressViewModel.kt index 10b8669f9..c42d230b9 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadProgressViewModel.kt @@ -91,6 +91,10 @@ class UploadProgressViewModel @Inject constructor( } } + fun removeAllUploadSession() { + viewModelScope.launch(ioDispatcher) { uploadManager.removeAllUploadSession() } + } + companion object { private val TAG = UploadProgressViewModel::class.java.simpleName } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index dfe6a5a2d..10e4db828 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -22,6 +22,7 @@ Link kopieren Download Auswahl herunterladen + Meine Übertragung bearbeiten Beenden Teilen Starten diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 6eab30e98..e10ce7b08 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -22,6 +22,7 @@ Copiar enlace Descargar Descargar la selección + Editar mi transferencia Acabado Compartir Inicio diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 3f9a84ef7..39e75600b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -22,6 +22,7 @@ Copier le lien Télécharger Télécharger la sélection + Modifier mon transfert Terminer Partager Démarrer diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 182e54071..43c2c8916 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -22,6 +22,7 @@ Copia link Scaricare Scarica la selezione + Modifica mio trasferimento Finisci Condividi Inizio diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 443a0e193..b55703dfa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,6 +26,7 @@ Copy link Download Download selection + Edit my transfer Finish Share Start