Skip to content

Commit

Permalink
fix: Handle units with no descendants (#29) (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
dixidroid authored Nov 18, 2024
1 parent 1a3826a commit a27e22d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -884,15 +884,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 @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class CourseUnitContainerViewModel(
}
_subSectionUnitBlocks.value =
getSubSectionUnitBlocks(blocks, getSubSectionId(unitId))

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

0 comments on commit a27e22d

Please sign in to comment.