@@ -80,29 +80,31 @@ class CourseOfflineViewModel(
8080
8181 fun downloadAllBlocks (fragmentManager : FragmentManager ) {
8282 viewModelScope.launch {
83- val courseStructure = courseInteractor.getCourseStructureFromCache(courseId)
84- val downloadModels = courseInteractor.getAllDownloadModels()
85- val subSectionsBlocks = allBlocks.values.filter { it.type == BlockType .SEQUENTIAL }
86- val notDownloadedSubSectionBlocks = subSectionsBlocks.mapNotNull { subSection ->
87- val verticalBlocks = allBlocks.values.filter { it.id in subSection.descendants }
88- val notDownloadedBlocks = courseStructure.blockData.filter { block ->
89- block.id in verticalBlocks.flatMap { it.descendants } &&
90- block.isDownloadable &&
91- downloadModels.none { it.id == block.id }
83+ runCatching {
84+ val courseStructure = courseInteractor.getCourseStructureFromCache(courseId)
85+ val downloadModels = courseInteractor.getAllDownloadModels()
86+ val subSectionsBlocks = allBlocks.values.filter { it.type == BlockType .SEQUENTIAL }
87+ val notDownloadedSubSectionBlocks = subSectionsBlocks.mapNotNull { subSection ->
88+ val verticalBlocks = allBlocks.values.filter { it.id in subSection.descendants }
89+ val notDownloadedBlocks = courseStructure.blockData.filter { block ->
90+ block.id in verticalBlocks.flatMap { it.descendants } &&
91+ block.isDownloadable &&
92+ downloadModels.none { it.id == block.id }
93+ }
94+ if (notDownloadedBlocks.isNotEmpty()) subSection else null
9295 }
93- if (notDownloadedBlocks.isNotEmpty()) subSection else null
94- }
9596
96- downloadDialogManager.showPopup(
97- subSectionsBlocks = notDownloadedSubSectionBlocks,
98- courseId = courseId,
99- isBlocksDownloaded = false ,
100- fragmentManager = fragmentManager,
101- removeDownloadModels = ::removeDownloadModels,
102- saveDownloadModels = { blockId ->
103- saveDownloadModels(fileUtil.getExternalAppDir().path, courseId, blockId)
104- }
105- )
97+ downloadDialogManager.showPopup(
98+ subSectionsBlocks = notDownloadedSubSectionBlocks,
99+ courseId = courseId,
100+ isBlocksDownloaded = false ,
101+ fragmentManager = fragmentManager,
102+ removeDownloadModels = ::removeDownloadModels,
103+ saveDownloadModels = { blockId ->
104+ saveDownloadModels(fileUtil.getExternalAppDir().path, courseId, blockId)
105+ }
106+ )
107+ }
106108 }
107109 }
108110
@@ -153,11 +155,11 @@ class CourseOfflineViewModel(
153155 }
154156
155157 private suspend fun initDownloadFragment () {
156- val courseStructure = courseInteractor.getCourseStructureFromCache(courseId)
157- setBlocks(courseStructure.blockData)
158- allBlocks.values
159- .filter { it.type == BlockType .SEQUENTIAL }
160- .forEach { addDownloadableChildrenForSequentialBlock(it) }
158+ val courseStructure = courseInteractor.getCourseStructureFromCache(courseId)
159+ setBlocks(courseStructure.blockData)
160+ allBlocks.values
161+ .filter { it.type == BlockType .SEQUENTIAL }
162+ .forEach { addDownloadableChildrenForSequentialBlock(it) }
161163 }
162164
163165 private fun getOfflineData () {
0 commit comments