Skip to content

Commit

Permalink
fix: Handle units with no descendants (openedx#29)
Browse files Browse the repository at this point in the history
fix: Handle units with no descendants
- Handle UI if an unit has zero descendant
- show unit list if a subsection have more then 1 units.
  • Loading branch information
omerhabib26 authored and dixidroid committed Nov 14, 2024
1 parent 88dfc54 commit 94a5c63
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -848,15 +848,15 @@ fun SubSectionUnitsTitle(
onUnitsClick: () -> Unit,
) {
val textStyle = MaterialTheme.appTypography.titleMedium
val hasUnits = unitsCount > 0
val hasMultipleUnits = unitsCount > 1
var rowModifier = Modifier
.fillMaxWidth()
.padding(
horizontal = 16.dp,
vertical = 8.dp
)
.displayCutoutForLandscape()
if (hasUnits) {
if (hasMultipleUnits) {
rowModifier = rowModifier.noRippleClickable { onUnitsClick() }
}

Expand All @@ -876,7 +876,7 @@ fun SubSectionUnitsTitle(
textAlign = TextAlign.Start
)

if (hasUnits) {
if (hasMultipleUnits) {
Icon(
modifier = Modifier.rotate(if (unitsListShowed) 180f else 0f),
painter = painterResource(id = R.drawable.ic_course_arrow_down),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,25 @@ class CourseUnitContainerFragment : Fragment(R.layout.fragment_course_unit_conta

binding.subSectionUnitsList.setContent {
val unitBlocks by viewModel.subSectionUnitBlocks.collectAsState()
val selectedUnitIndex = unitBlocks.indexOfFirst { it.id == viewModel.unitId }
OpenEdXTheme {
SubSectionUnitsList(
unitBlocks = unitBlocks,
selectedUnitIndex = selectedUnitIndex
) { index, unit ->
if (index != selectedUnitIndex) {
router.navigateToCourseContainer(
fm = requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
unitId = unit.id,
mode = requireArguments().serializable(ARG_MODE)!!
)

} else {
handleUnitsClick()
// If there is more than one unit in the section, show the list
if (unitBlocks.size > 1) {
val selectedUnitIndex = unitBlocks.indexOfFirst { it.id == viewModel.unitId }
OpenEdXTheme {
SubSectionUnitsList(
unitBlocks = unitBlocks,
selectedUnitIndex = selectedUnitIndex
) { index, unit ->
if (index != selectedUnitIndex) {
router.navigateToCourseContainer(
fm = requireActivity().supportFragmentManager,
courseId = viewModel.courseId,
unitId = unit.id,
mode = requireArguments().serializable(ARG_MODE)!!
)

} else {
handleUnitsClick()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class CourseUnitContainerViewModel(
_subSectionUnitBlocks.value =
getSubSectionUnitBlocks(blocks, getSubSectionId(unitId))

if(_descendantsBlocks.value.isEmpty()){
_descendantsBlocks.value = listOf(block)
}
} else {
setNextVerticalIndex()
}
Expand Down

0 comments on commit 94a5c63

Please sign in to comment.