Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resume network with old uploaded size #210

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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