From 6cb5112a724d0d44a03ce7e46c3a14de517e6aa8 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Tue, 24 Dec 2024 09:44:42 +0100 Subject: [PATCH 1/2] fix: Correctly remove previous UploadSession when trying again to send a new transfer --- .../swisstransfer/ui/screen/newtransfer/TransferSendManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt index 96987cf13..a581c8133 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt @@ -48,6 +48,7 @@ class TransferSendManager @Inject constructor( val sendStatus = _sendStatus.asStateFlow() suspend fun sendNewTransfer(newUploadSession: NewUploadSession) { + uploadManager.removeAllUploadSession() val uploadSession = uploadManager.createAndGetUpload(newUploadSession) sendTransfer(uploadSession.uuid) } From b743eb1efc09f29db81291a11f961c9ec65d2ce9 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Tue, 24 Dec 2024 14:05:52 +0100 Subject: [PATCH 2/2] docs: Add explanatory comment --- .../ui/screen/newtransfer/TransferSendManager.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt index a581c8133..4fbd3a210 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferSendManager.kt @@ -43,12 +43,18 @@ class TransferSendManager @Inject constructor( private val uploadWorkerScheduler: UploadWorker.Scheduler, ) { - // TODO: Merge these two UI states in a single one for the whole flow of logic private val _sendStatus = MutableStateFlow(SendStatus.Initial) val sendStatus = _sendStatus.asStateFlow() suspend fun sendNewTransfer(newUploadSession: NewUploadSession) { + + // When clicking the "Send" button, a new session is created. + // If there is an error before reaching the UploadProgressScreen, we stay in ImportFilesScreen. + // Every time we'll click the "Send" button again, a new session will be created. + // So we'll have multiple UploadSession in Realm. We don't want that. We only want the last session. + // So before creating the new session, we need to remove the previous failed ones. uploadManager.removeAllUploadSession() + val uploadSession = uploadManager.createAndGetUpload(newUploadSession) sendTransfer(uploadSession.uuid) }