From 76b6615be06298315d9a63af21eca0f10060dab1 Mon Sep 17 00:00:00 2001 From: droid Date: Fri, 15 Mar 2024 11:00:16 +0100 Subject: [PATCH] fix: bug when sequence units level appear after tapping on the Back button --- .../java/org/openedx/app/di/ScreenModule.kt | 1 + .../presentation/dates/CourseDatesFragment.kt | 30 ++++++++++++------- .../dates/CourseDatesViewModel.kt | 4 +++ .../outline/CourseOutlineFragment.kt | 26 +++++++++++----- .../outline/CourseOutlineViewModel.kt | 2 ++ 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/openedx/app/di/ScreenModule.kt b/app/src/main/java/org/openedx/app/di/ScreenModule.kt index c74d007a5..a32c35c22 100644 --- a/app/src/main/java/org/openedx/app/di/ScreenModule.kt +++ b/app/src/main/java/org/openedx/app/di/ScreenModule.kt @@ -246,6 +246,7 @@ val screenModule = module { get(), get(), get(), + get(), ) } viewModel { (courseId: String, handoutsType: String) -> diff --git a/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesFragment.kt b/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesFragment.kt index 39a342634..4b0e175c1 100644 --- a/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesFragment.kt +++ b/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesFragment.kt @@ -156,16 +156,26 @@ class CourseDatesFragment : Fragment() { onItemClick = { blockId -> if (blockId.isNotEmpty()) { viewModel.getVerticalBlock(blockId)?.let { verticalBlock -> - viewModel.getSequentialBlock(verticalBlock.id) - ?.let { sequentialBlock -> - router.navigateToCourseSubsections( - fm = requireActivity().supportFragmentManager, - subSectionId = sequentialBlock.id, - courseId = viewModel.courseId, - unitId = verticalBlock.id, - mode = CourseViewMode.FULL - ) - } + if (viewModel.isCourseExpandableSectionsEnabled) { + router.navigateToCourseContainer( + fm = requireActivity().supportFragmentManager, + courseId = viewModel.courseId, + unitId = verticalBlock.id, + componentId = "", + mode = CourseViewMode.FULL + ) + } else { + viewModel.getSequentialBlock(verticalBlock.id) + ?.let { sequentialBlock -> + router.navigateToCourseSubsections( + fm = requireActivity().supportFragmentManager, + subSectionId = sequentialBlock.id, + courseId = viewModel.courseId, + unitId = verticalBlock.id, + mode = CourseViewMode.FULL + ) + } + } } } }, diff --git a/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesViewModel.kt b/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesViewModel.kt index 2380dbab4..6313b599d 100644 --- a/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/dates/CourseDatesViewModel.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.launch import org.openedx.core.BaseViewModel import org.openedx.core.SingleEventLiveData import org.openedx.core.UIMessage +import org.openedx.core.config.Config import org.openedx.core.data.storage.CorePreferences import org.openedx.core.domain.model.Block import org.openedx.core.extension.getSequentialBlocks @@ -37,6 +38,7 @@ class CourseDatesViewModel( private val networkConnection: NetworkConnection, private val resourceManager: ResourceManager, private val corePreferences: CorePreferences, + private val config: Config, ) : BaseViewModel() { private val _uiState = MutableLiveData(DatesUIState.Loading) @@ -64,6 +66,8 @@ class CourseDatesViewModel( val hasInternetConnection: Boolean get() = networkConnection.isOnline() + val isCourseExpandableSectionsEnabled get() = config.isCourseNestedListEnabled() + init { getCourseDates() viewModelScope.launch { diff --git a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineFragment.kt b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineFragment.kt index f00055fa9..86fa2314c 100644 --- a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineFragment.kt +++ b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineFragment.kt @@ -168,14 +168,24 @@ class CourseOutlineFragment : Fragment() { viewModel.resumeSectionBlock?.let { subSection -> viewModel.resumeCourseTappedEvent(subSection.id) viewModel.resumeVerticalBlock?.let { unit -> - router.navigateToCourseSubsections( - requireActivity().supportFragmentManager, - courseId = viewModel.courseId, - subSectionId = subSection.id, - mode = CourseViewMode.FULL, - unitId = unit.id, - componentId = componentId - ) + if (viewModel.isCourseExpandableSectionsEnabled) { + router.navigateToCourseContainer( + fm = requireActivity().supportFragmentManager, + courseId = viewModel.courseId, + unitId = unit.id, + componentId = componentId, + mode = CourseViewMode.FULL + ) + } else { + router.navigateToCourseSubsections( + requireActivity().supportFragmentManager, + courseId = viewModel.courseId, + subSectionId = subSection.id, + mode = CourseViewMode.FULL, + unitId = unit.id, + componentId = componentId + ) + } } } }, diff --git a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt index cf83fd041..0337f811b 100644 --- a/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/outline/CourseOutlineViewModel.kt @@ -73,6 +73,8 @@ class CourseOutlineViewModel( val hasInternetConnection: Boolean get() = networkConnection.isOnline() + val isCourseExpandableSectionsEnabled get() = config.isCourseNestedListEnabled() + private val courseSubSections = mutableMapOf>() private val subSectionsDownloadsCount = mutableMapOf() val courseSubSectionUnit = mutableMapOf()