Skip to content

Commit c0fe884

Browse files
fix: download all button (#468)
1 parent 74b79cf commit c0fe884

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import org.openedx.core.extension.safeDivBy
1818
import org.openedx.core.module.DownloadWorkerController
1919
import org.openedx.core.module.db.DownloadDao
2020
import org.openedx.core.module.db.DownloadModel
21-
import org.openedx.core.module.db.DownloadedState
2221
import org.openedx.core.module.db.FileType
2322
import org.openedx.core.module.download.BaseDownloadViewModel
2423
import org.openedx.core.module.download.DownloadHelper
@@ -171,10 +170,13 @@ class CourseOfflineViewModel(
171170
val downloadedBlocks = courseStructure.blockData.filter {
172171
it.id in completedDownloads.map { it.id }
173172
}
174-
val isAllDownloaded =
175-
courseDownloadModels.all { it.downloadedState == DownloadedState.DOWNLOADED } &&
176-
courseDownloadModels.isNotEmpty()
177-
val isHaveDownloadableBlocks = courseStructure.blockData.any { it.isDownloadable }
173+
val allDownloadableBlocks = courseStructure.blockData.filter { it.isDownloadable }
174+
val courseDownloadModelsMap = courseDownloadModels.associateBy { it.id }
175+
val isAllDownloaded = allDownloadableBlocks.isNotEmpty() &&
176+
allDownloadableBlocks.all { block ->
177+
courseDownloadModelsMap[block.id]?.downloadedState?.isDownloaded == true
178+
}
179+
val isHaveDownloadableBlocks = allDownloadableBlocks.isNotEmpty()
178180

179181
updateUIState(
180182
totalDownloadableSize,

0 commit comments

Comments
 (0)