From 9cc57833c35ec1b1669a607335f45b8288fd93db Mon Sep 17 00:00:00 2001 From: Hamza Israr Date: Fri, 3 Nov 2023 03:00:04 +0500 Subject: [PATCH] fix: Prevent Deep Link Activation on Orientation Change Previously, the deep link was inadvertently activated when the fragment was recreated during an orientation change. This occurred because the screen name value was unnecessarily re-fetched from the fragment's arguments. To resolve this issue, we now set the argument to null, ensuring that deep link activation no longer occurs during orientation changes. Fixes: LEARNER-9659 --- .../edx/mobile/view/CourseHomeTabFragment.kt | 1 + .../view/CourseTabsDashboardFragment.kt | 46 ++++++++++--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseHomeTabFragment.kt b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseHomeTabFragment.kt index d30a9821de..698cbf2f1e 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseHomeTabFragment.kt +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseHomeTabFragment.kt @@ -273,6 +273,7 @@ class CourseHomeTabFragment : OfflineSupportBaseFragment(), CourseHomeAdapter.On false ) courseUnitDetailLauncher.launch(courseUnitDetailIntent) + arguments?.putString(Router.EXTRA_SCREEN_NAME, null) screenName = null } } diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt index 33c580c31a..40bfb50266 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt @@ -130,28 +130,7 @@ class CourseTabsDashboardFragment : BaseFragment() { private val fullscreenLoader: FullscreenLoaderDialogFragment? get() = getRetainedInstance(childFragmentManager) - private val courseTabItems: List - get() { - val screenName = arguments?.getString(Router.EXTRA_SCREEN_NAME) - val items = mutableListOf() - - items.add(createCourseOutlineItem(screenName)) - if (environment.config.isCourseVideosEnabled) { - items.add(createVideosItem()) - } - if (environment.config.isDiscussionsEnabled && - courseData.course.discussionUrl?.isNotEmpty() == true - ) { - items.add(createDiscussionsItem()) - } - if (environment.config.isCourseDatesEnabled) { - items.add(createDatesItem()) - } - items.add(createHandoutsItem()) - items.add(createAnnouncementsItem()) - - return items - } + private lateinit var courseTabItems: List private val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) { @@ -191,6 +170,7 @@ class CourseTabsDashboardFragment : BaseFragment() { binding = FragmentCourseTabsDashboardBinding.inflate(inflater, container, false) courseData = arguments?.serializableOrThrow(Router.EXTRA_COURSE_DATA) as EnrolledCoursesResponse + courseTabItems = getCourseTabItems() setHasOptionsMenu(courseData.course.coursewareAccess.hasAccess()) @@ -788,6 +768,28 @@ class CourseTabsDashboardFragment : BaseFragment() { }) } + private fun getCourseTabItems(): List { + val screenName = arguments?.getString(Router.EXTRA_SCREEN_NAME) + val items = mutableListOf() + + items.add(createCourseOutlineItem(screenName)) + if (environment.config.isCourseVideosEnabled) { + items.add(createVideosItem()) + } + if (environment.config.isDiscussionsEnabled && + courseData.course.discussionUrl?.isNotEmpty() == true + ) { + items.add(createDiscussionsItem()) + } + if (environment.config.isCourseDatesEnabled) { + items.add(createDatesItem()) + } + items.add(createHandoutsItem()) + items.add(createAnnouncementsItem()) + + return items + } + private fun createCourseOutlineItem(screenName: String?): FragmentItemModel { return FragmentItemModel( CourseHomeTabFragment::class.java,