Skip to content
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
3 changes: 3 additions & 0 deletions core/src/main/java/org/openedx/core/BlockType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum class BlockType {
HTML {
override fun isContainer() = false
},
LIBRARY_CONTENT {
override fun isContainer() = false
},
LTI_CONSUMER {
override fun isContainer() = false
},
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/openedx/core/domain/model/Block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ data class Block(
val isWordCloudBlock get() = type == BlockType.WORD_CLOUD
val isLTIConsumerBlock get() = type == BlockType.LTI_CONSUMER
val isSurveyBlock get() = type == BlockType.SURVEY
val isLibraryContentBlock get() = type == BlockType.LIBRARY_CONTENT
}

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class CourseUnitContainerAdapter(
block.isDragAndDropBlock ||
block.isWordCloudBlock ||
block.isLTIConsumerBlock ||
block.isSurveyBlock
block.isSurveyBlock ||
block.isLibraryContentBlock
}

private fun isBlockGatedWithPrerequisite(block: Block): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,25 @@ class CourseUnitContainerViewModel(
}

if (block.descendants.isNotEmpty() || block.isGated()) {
_descendantsBlocks.value =
block.descendants.mapNotNull { descendant ->
blocks.firstOrNull { descendant == it.id }
}
val rawDescendants = block.descendants.mapNotNull { descendant ->
blocks.firstOrNull { descendant == it.id }
}

// The OpenEdX API flattens library_content's children into the parent
// vertical's descendants list but returns the library_content block itself
// with an empty descendants field. Since the library_content WebView
// already renders all its problems, remove the duplicate problem pages.
val hasLibraryContent = rawDescendants.any { it.isLibraryContentBlock }
_descendantsBlocks.value = if (hasLibraryContent) {
// Show each library problem as its own page; drop the wrapper block
// whose WebView would show all questions on a single page.
rawDescendants.filter { !it.isLibraryContentBlock }
} else {
// Generic case: filter blocks that are declared children of another
// block in the same list (handles other nested xBlock containers).
val childIdsOfDescendants = rawDescendants.flatMap { it.descendants }.toSet()
rawDescendants.filter { it.id !in childIdsOfDescendants }
}
_subSectionUnitBlocks.value =
getSubSectionUnitBlocks(blocks, getSubSectionId(unitId))

Expand All @@ -295,7 +310,7 @@ class CourseUnitContainerViewModel(
setNextVerticalIndex()
}
if (currentVerticalIndex != -1) {
_verticalBlockCounts.value = blocks[currentVerticalIndex].descendants.size
_verticalBlockCounts.value = _descendantsBlocks.value.size
}
if (componentId.isNotEmpty()) {
currentIndex = _descendantsBlocks.value.indexOfFirst { it.id == componentId }
Expand Down
Loading