Skip to content

Commit

Permalink
Merge pull request #210 from Infomaniak/fix-network-resume
Browse files Browse the repository at this point in the history
fix: Resume network with old uploaded size
  • Loading branch information
tevincent authored Nov 26, 2024
2 parents a4239ba + 032984d commit 5d13003
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UploadProgressViewModel @Inject constructor(
}.stateIn(
scope = viewModelScope,
started = SharingStarted.Eagerly,
initialValue = UploadWorker.UploadProgressUiState.Default,
initialValue = UploadWorker.UploadProgressUiState.Default(),
)

fun trackUploadProgress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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) {
Expand Down

0 comments on commit 5d13003

Please sign in to comment.