Skip to content

Commit 52f3d59

Browse files
feat: show course item on dialog
1 parent b03927c commit 52f3d59

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

core/src/main/java/org/openedx/core/presentation/dialog/downloaddialog/DownloadDialogManager.kt

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class DownloadDialogManager(
109109
subSectionsBlocks: List<Block>,
110110
courseId: String,
111111
isBlocksDownloaded: Boolean,
112+
showCourseItem: Boolean = false,
113+
courseName: String = "",
112114
onlyVideoBlocks: Boolean = false,
113115
fragmentManager: FragmentManager,
114116
removeDownloadModels: (blockId: String, courseId: String) -> Unit,
@@ -121,6 +123,8 @@ class DownloadDialogManager(
121123
courseId = courseId,
122124
fragmentManager = fragmentManager,
123125
isBlocksDownloaded = isBlocksDownloaded,
126+
showCourseItem = showCourseItem,
127+
courseName = courseName,
124128
onlyVideoBlocks = onlyVideoBlocks,
125129
removeDownloadModels = removeDownloadModels,
126130
saveDownloadModels = saveDownloadModels,
@@ -217,6 +221,8 @@ class DownloadDialogManager(
217221
courseId: String,
218222
fragmentManager: FragmentManager,
219223
isBlocksDownloaded: Boolean,
224+
showCourseItem: Boolean,
225+
courseName: String,
220226
onlyVideoBlocks: Boolean,
221227
removeDownloadModels: (blockId: String, courseId: String) -> Unit,
222228
saveDownloadModels: (blockId: String) -> Unit,
@@ -227,24 +233,45 @@ class DownloadDialogManager(
227233
val courseStructure = interactor.getCourseStructure(courseId, false)
228234
val downloadModelIds = interactor.getAllDownloadModels().map { it.id }
229235

230-
val downloadDialogItems = subSectionsBlocks.mapNotNull { subSectionBlock ->
231-
val verticalBlocks =
232-
courseStructure.blockData.filter { it.id in subSectionBlock.descendants }
233-
val blocks = verticalBlocks.flatMap { verticalBlock ->
234-
courseStructure.blockData.filter {
235-
it.id in verticalBlock.descendants &&
236-
(isBlocksDownloaded == (it.id in downloadModelIds)) &&
237-
(!onlyVideoBlocks || it.type == BlockType.VIDEO)
236+
val downloadDialogItems = if (showCourseItem) {
237+
val courseSize = subSectionsBlocks.map { subSectionBlock ->
238+
val verticalBlocks =
239+
courseStructure.blockData.filter { it.id in subSectionBlock.descendants }
240+
val blocks = verticalBlocks.flatMap { verticalBlock ->
241+
courseStructure.blockData.filter {
242+
it.id in verticalBlock.descendants &&
243+
(isBlocksDownloaded == (it.id in downloadModelIds)) &&
244+
(!onlyVideoBlocks || it.type == BlockType.VIDEO)
245+
}
238246
}
247+
blocks.sumOf { it.getFileSize() }
239248
}
240-
val size = blocks.sumOf { it.getFileSize() }
241-
if (size > 0) {
249+
listOf(
242250
DownloadDialogItem(
243-
title = subSectionBlock.displayName,
244-
size = size
251+
title = courseName,
252+
size = courseSize.sum()
245253
)
246-
} else {
247-
null
254+
)
255+
} else {
256+
subSectionsBlocks.mapNotNull { subSectionBlock ->
257+
val verticalBlocks =
258+
courseStructure.blockData.filter { it.id in subSectionBlock.descendants }
259+
val blocks = verticalBlocks.flatMap { verticalBlock ->
260+
courseStructure.blockData.filter {
261+
it.id in verticalBlock.descendants &&
262+
(isBlocksDownloaded == (it.id in downloadModelIds)) &&
263+
(!onlyVideoBlocks || it.type == BlockType.VIDEO)
264+
}
265+
}
266+
val size = blocks.sumOf { it.getFileSize() }
267+
if (size > 0) {
268+
DownloadDialogItem(
269+
title = subSectionBlock.displayName,
270+
size = size
271+
)
272+
} else {
273+
null
274+
}
248275
}
249276
}
250277

downloads/src/main/java/org/openedx/downloads/presentation/download/DownloadsViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ class DownloadsViewModel(
315315
subSectionsBlocks = notDownloadedSubSectionBlocks,
316316
courseId = courseId,
317317
isBlocksDownloaded = false,
318+
showCourseItem = true,
319+
courseName = courseStructure.name,
318320
fragmentManager = fragmentManager,
319321
removeDownloadModels = ::removeDownloadModels,
320322
saveDownloadModels = { blockId ->

0 commit comments

Comments
 (0)