Skip to content

Commit 37eadb8

Browse files
fix: using real unarchived size instead bloc size
1 parent b029359 commit 37eadb8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

course/src/main/java/org/openedx/course/presentation/offline/CourseOfflineViewModel.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ class CourseOfflineViewModel(
126126

127127
fun deleteAll(fragmentManager: FragmentManager) {
128128
viewModelScope.launch {
129-
val downloadModels = courseInteractor.getAllDownloadModels().filter { it.courseId == courseId }
129+
val downloadModels =
130+
courseInteractor.getAllDownloadModels().filter { it.courseId == courseId }
130131
val totalSize = downloadModels.sumOf { it.size }
131132
val downloadDialogItem = DownloadDialogItem(
132133
title = courseTitle,
@@ -169,7 +170,8 @@ class CourseOfflineViewModel(
169170
val completedDownloads =
170171
downloadModels.filter { it.downloadedState.isDownloaded && it.courseId == courseId }
171172
val completedDownloadIds = completedDownloads.map { it.id }
172-
val downloadedBlocks = courseStructure.blockData.filter { it.id in completedDownloadIds }
173+
val downloadedBlocks =
174+
courseStructure.blockData.filter { it.id in completedDownloadIds }
173175

174176
updateUIState(
175177
totalDownloadableSize,
@@ -190,14 +192,19 @@ class CourseOfflineViewModel(
190192
val largestDownloads = completedDownloads
191193
.sortedByDescending { it.size }
192194
.take(n = 5)
193-
195+
val progressBarValue = downloadedSize.toFloat() / totalDownloadableSize.toFloat()
196+
val readyToDownloadSize = if (progressBarValue >= 1) {
197+
0
198+
} else {
199+
totalDownloadableSize - realDownloadedSize
200+
}
194201
_uiState.update {
195202
it.copy(
196203
isHaveDownloadableBlocks = true,
197204
largestDownloads = largestDownloads,
198-
readyToDownloadSize = (totalDownloadableSize - downloadedSize).toFileSize(1, false),
205+
readyToDownloadSize = readyToDownloadSize.toFileSize(1, false),
199206
downloadedSize = realDownloadedSize.toFileSize(1, false),
200-
progressBarValue = downloadedSize.toFloat() / totalDownloadableSize.toFloat()
207+
progressBarValue = progressBarValue
201208
)
202209
}
203210
}

0 commit comments

Comments
 (0)