From c43949109dc50f6d88bd62b2b70e78ff3f70ce4c Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Thu, 7 Nov 2024 10:05:49 +0100 Subject: [PATCH] refactor: Apply suggestions --- .../ui/screen/newtransfer/NewTransferNavHost.kt | 5 ++--- .../newtransfer/importfiles/ImportFilesScreen.kt | 6 +++--- .../screen/newtransfer/upload/UploadProgressScreen.kt | 11 ++++------- .../swisstransfer/workers/UploadFileTask.kt | 2 +- 4 files changed, 10 insertions(+), 14 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 f7d6d005d..bd4e571cf 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 @@ -51,10 +51,9 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un composable { val args = it.toRoute() UploadProgressScreen( - transferType = args.transferType, totalSizeInBytes = args.totalSize, - navigateToUploadSuccess = { transferType, transferLink -> - navController.navigate(UploadSuccessDestination(transferType, transferLink)) + navigateToUploadSuccess = { transferLink -> + navController.navigate(UploadSuccessDestination(args.transferType, transferLink)) }, closeActivity = closeActivity ) 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 4102a46b9..98d2474ad 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 @@ -67,7 +67,7 @@ fun ImportFilesScreen( val selectedTransferType by newTransferViewModel.selectedTransferType.collectAsStateWithLifecycle() val sendActionResult by newTransferViewModel.sendActionResult.collectAsStateWithLifecycle() - HandleSendActionResult({ sendActionResult }, selectedTransferType, navigateToUploadProgress) + HandleSendActionResult({ sendActionResult }, { selectedTransferType }, navigateToUploadProgress) ImportFilesScreen( files = { files }, @@ -88,12 +88,12 @@ fun ImportFilesScreen( @Composable private fun HandleSendActionResult( getSendActionResult: () -> SendActionResult?, - transferType: TransferType, + transferType: () -> TransferType, navigateToUploadProgress: (transferType: TransferType, totalSize: Long) -> Unit, ) { LaunchedEffect(getSendActionResult()) { when (val actionResult = getSendActionResult()) { - is SendActionResult.Success -> navigateToUploadProgress(transferType, actionResult.totalSize) + is SendActionResult.Success -> navigateToUploadProgress(transferType(), actionResult.totalSize) is SendActionResult.Failure -> Unit //TODO: Show error else -> Unit } 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 6410be349..40bc4b312 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 @@ -34,7 +34,6 @@ import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus import com.infomaniak.swisstransfer.ui.images.illus.uploadCancelBottomSheet.RedCrossPaperPlanes -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.components.AdHeader import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.components.Progress import com.infomaniak.swisstransfer.ui.theme.Margin @@ -46,9 +45,8 @@ import com.infomaniak.swisstransfer.workers.UploadWorker.UploadProgressUiState @Composable fun UploadProgressScreen( uploadProgressViewModel: UploadProgressViewModel = hiltViewModel(), - transferType: TransferType, totalSizeInBytes: Long, - navigateToUploadSuccess: (TransferType, String) -> Unit, + navigateToUploadSuccess: (String) -> Unit, closeActivity: () -> Unit, ) { val uiState by uploadProgressViewModel.transferProgressUiState.collectAsStateWithLifecycle() @@ -64,7 +62,7 @@ fun UploadProgressScreen( uploadProgressViewModel.trackUploadProgress() } - HandleProgressState({ uiState }, transferType, navigateToUploadSuccess) + HandleProgressState({ uiState }, navigateToUploadSuccess) UploadProgressScreen( progressState = { uiState }, @@ -81,14 +79,13 @@ fun UploadProgressScreen( @Composable private fun HandleProgressState( uiState: () -> UploadProgressUiState, - transferType: TransferType, - navigateToUploadSuccess: (TransferType, String) -> Unit + navigateToUploadSuccess: (String) -> Unit ) { val currentUiState = uiState() LaunchedEffect(uiState()) { when (currentUiState) { is UploadProgressUiState.Success -> { - navigateToUploadSuccess(transferType, currentUiState.transferLink) + navigateToUploadSuccess(currentUiState.transferLink) } is UploadProgressUiState.Cancelled -> { // TODO: navigate to failure screen diff --git a/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadFileTask.kt b/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadFileTask.kt index 2c938a862..9c6fdca38 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadFileTask.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadFileTask.kt @@ -126,7 +126,7 @@ class UploadFileTask( data = data, onUpload = { bytesSentTotal, _ -> mutex.withLock { - ensureActive() + ensureActive() // Cancel when this chunk is resumed while parent scope is cancelled onUploadBytes(bytesSentTotal - oldBytesSentTotal) oldBytesSentTotal = bytesSentTotal }