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 a49aee859..7c8bc9308 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 @@ -48,7 +48,7 @@ class UploadProgressViewModel @Inject constructor( }.stateIn( scope = viewModelScope, started = SharingStarted.Eagerly, - initialValue = UploadWorker.UploadProgressUiState.Default, + initialValue = UploadWorker.UploadProgressUiState.Default(), ) fun trackUploadProgress() { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadWorker.kt b/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadWorker.kt index 79fdb0ae7..b4b5ffa14 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadWorker.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/workers/UploadWorker.kt @@ -118,12 +118,12 @@ class UploadWorker @AssistedInject constructor( .build() return workManager.getWorkInfosFlow(workQuery).mapLatest { workInfoList -> - val workInfo = workInfoList.firstOrNull() ?: return@mapLatest UploadProgressUiState.Default + val workInfo = workInfoList.firstOrNull() ?: return@mapLatest UploadProgressUiState.Default() return@mapLatest when (workInfo.state) { State.RUNNING -> UploadProgressUiState.Progress(workInfo.progress).also { lastUploadedSize = it.uploadedSize } State.SUCCEEDED -> UploadProgressUiState.Success.create(workInfo.outputData, sharedApiUrlCreator) State.FAILED, State.CANCELLED -> UploadProgressUiState.Error(lastUploadedSize) - else -> UploadProgressUiState.Default + else -> UploadProgressUiState.Default(lastUploadedSize) } ?: UploadProgressUiState.Error(lastUploadedSize) }.filterNotNull() } @@ -134,8 +134,9 @@ class UploadWorker @AssistedInject constructor( } } - sealed class UploadProgressUiState(open val uploadedSize: Long = 0) { - data object Default : UploadProgressUiState() + sealed class UploadProgressUiState(open val uploadedSize: Long) { + @Immutable + data class Default(override val uploadedSize: Long = 0) : UploadProgressUiState(uploadedSize) @Immutable data class Progress(override val uploadedSize: Long) : UploadProgressUiState(uploadedSize) {