diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt index 6ab835fcb..61b5fda08 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt @@ -22,6 +22,10 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.RemoteUploadFile +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadFileSession +import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage +import com.infomaniak.multiplatform_swisstransfer.common.utils.mapToList import com.infomaniak.multiplatform_swisstransfer.data.NewUploadSession import com.infomaniak.swisstransfer.di.IoDispatcher import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType @@ -94,10 +98,10 @@ class NewTransferViewModel @Inject constructor( } } - fun sendTransfer(newUploadSession: NewUploadSession) { + fun sendTransfer() { viewModelScope.launch(ioDispatcher) { runCatching { - uploadManager.createAndGetUpload(newUploadSession) + uploadManager.createAndGetUpload(generateNewUploadSession()) uploadWorkerScheduler.scheduleWork() }.onFailure { exception -> // TODO: Handle user feedback @@ -106,6 +110,27 @@ class NewTransferViewModel @Inject constructor( } } + private fun generateNewUploadSession(): NewUploadSession { + return NewUploadSession( + duration = "30", + authorEmail = "", + password = "", + message = "sisi test", + numberOfDownload = 20, + language = EmailLanguage.ENGLISH, + recipientsEmails = emptyList(), + files = importationFilesManager.importedFiles.value.mapToList { fileUi -> + object : UploadFileSession { + override val localPath: String = fileUi.localPath ?: "" + override val mimeType: String = fileUi.mimeType ?: "" + override val name: String = fileUi.fileName + override val remoteUploadFile: RemoteUploadFile? = null + override val size: Long = fileUi.fileSize + } + } + ) + } + companion object { private const val IS_VIEW_MODEL_RESTORED_KEY = "IS_VIEW_MODEL_RESTORED_KEY" } 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 635317ebc..834330bd9 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 @@ -35,11 +35,6 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.RemoteUploadFile -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadFileSession -import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage -import com.infomaniak.multiplatform_swisstransfer.common.utils.mapToList -import com.infomaniak.multiplatform_swisstransfer.data.NewUploadSession import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParameter @@ -81,8 +76,8 @@ fun ImportFilesScreen( removeFileByUid = newTransferViewModel::removeFileByUid, addFiles = newTransferViewModel::importFiles, closeActivity = closeActivity, - navigateToUploadProgress = { newUploadSession -> - newTransferViewModel.sendTransfer(newUploadSession) + navigateToUploadProgress = { + newTransferViewModel.sendTransfer() navigateToUploadProgress() }, initialShowUploadSourceChoiceBottomSheet = true, @@ -99,7 +94,7 @@ private fun ImportFilesScreen( addFiles: (List) -> Unit, closeActivity: () -> Unit, initialShowUploadSourceChoiceBottomSheet: Boolean, - navigateToUploadProgress: (NewUploadSession) -> Unit, + navigateToUploadProgress: () -> Unit, ) { val context = LocalContext.current var showUploadSourceChoiceBottomSheet by rememberSaveable { mutableStateOf(initialShowUploadSourceChoiceBottomSheet) } @@ -127,7 +122,7 @@ private fun ImportFilesScreen( }, topButton = { modifier -> SendButton(filesToImportCount, currentSessionFilesCount, files, modifier) { - navigateToUploadProgress(generateNewUploadSession(importedFiles)) + navigateToUploadProgress() } }, content = { @@ -170,27 +165,6 @@ private fun ImportFilesScreen( ) } -private fun generateNewUploadSession(importedFiles: List): NewUploadSession { - return NewUploadSession( - duration = "30", - authorEmail = "", - password = "", - message = "sisi test", - numberOfDownload = 20, - language = EmailLanguage.ENGLISH, - recipientsEmails = emptyList(), - files = importedFiles.mapToList { fileUi -> - object : UploadFileSession { - override val localPath: String = fileUi.localPath ?: "" - override val mimeType: String = fileUi.mimeType ?: "" - override val name: String = fileUi.fileName - override val remoteUploadFile: RemoteUploadFile? = null - override val size: Long = fileUi.fileSize - } - } - ) -} - @Composable private fun ColumnScope.ImportTextFields(selectedTransferType: () -> TransferType) {