Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle units with no descendants #405

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
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
Loading