diff --git a/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt b/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt index a58af2a79..2598ad8ac 100644 --- a/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt +++ b/course/src/main/java/org/openedx/course/presentation/ui/CourseUI.kt @@ -884,7 +884,7 @@ fun SubSectionUnitsTitle( onUnitsClick: () -> Unit, ) { val textStyle = MaterialTheme.appTypography.titleMedium - val hasUnits = unitsCount > 0 + val hasMultipleUnits = unitsCount > 1 var rowModifier = Modifier .fillMaxWidth() .padding( @@ -892,7 +892,7 @@ fun SubSectionUnitsTitle( vertical = 8.dp ) .displayCutoutForLandscape() - if (hasUnits) { + if (hasMultipleUnits) { rowModifier = rowModifier.noRippleClickable { onUnitsClick() } } @@ -912,7 +912,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), diff --git a/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerFragment.kt b/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerFragment.kt index be490df74..c8ea5de29 100644 --- a/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerFragment.kt +++ b/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerFragment.kt @@ -281,21 +281,24 @@ 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() + } } } } diff --git a/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerViewModel.kt b/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerViewModel.kt index 76ea09dac..353a1b0ff 100644 --- a/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/unit/container/CourseUnitContainerViewModel.kt @@ -138,6 +138,10 @@ class CourseUnitContainerViewModel( } _subSectionUnitBlocks.value = getSubSectionUnitBlocks(blocks, getSubSectionId(unitId)) + + if (_descendantsBlocks.value.isEmpty()) { + _descendantsBlocks.value = listOf(block) + } } else { setNextVerticalIndex() }