Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
fix: Prevent Deep Link Activation on Orientation Change
Browse files Browse the repository at this point in the history
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
  • Loading branch information
HamzaIsrar12 committed Nov 2, 2023
1 parent c4e2dba commit 9cc5783
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class CourseHomeTabFragment : OfflineSupportBaseFragment(), CourseHomeAdapter.On
false
)
courseUnitDetailLauncher.launch(courseUnitDetailIntent)
arguments?.putString(Router.EXTRA_SCREEN_NAME, null)
screenName = null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,7 @@ class CourseTabsDashboardFragment : BaseFragment() {
private val fullscreenLoader: FullscreenLoaderDialogFragment?
get() = getRetainedInstance(childFragmentManager)

private val courseTabItems: List<FragmentItemModel>
get() {
val screenName = arguments?.getString(Router.EXTRA_SCREEN_NAME)
val items = mutableListOf<FragmentItemModel>()

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<FragmentItemModel>

private val onBackPressedCallback: OnBackPressedCallback =
object : OnBackPressedCallback(true) {
Expand Down Expand Up @@ -191,6 +170,7 @@ class CourseTabsDashboardFragment : BaseFragment() {
binding = FragmentCourseTabsDashboardBinding.inflate(inflater, container, false)
courseData =
arguments?.serializableOrThrow(Router.EXTRA_COURSE_DATA) as EnrolledCoursesResponse
courseTabItems = getCourseTabItems()

Check warning on line 173 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L173

Added line #L173 was not covered by tests

setHasOptionsMenu(courseData.course.coursewareAccess.hasAccess())

Expand Down Expand Up @@ -788,6 +768,28 @@ class CourseTabsDashboardFragment : BaseFragment() {
})
}

private fun getCourseTabItems(): List<FragmentItemModel> {
val screenName = arguments?.getString(Router.EXTRA_SCREEN_NAME)
val items = mutableListOf<FragmentItemModel>()

Check warning on line 773 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L773

Added line #L773 was not covered by tests

items.add(createCourseOutlineItem(screenName))

Check warning on line 775 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L775

Added line #L775 was not covered by tests
if (environment.config.isCourseVideosEnabled) {
items.add(createVideosItem())

Check warning on line 777 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L777

Added line #L777 was not covered by tests
}
if (environment.config.isDiscussionsEnabled &&
courseData.course.discussionUrl?.isNotEmpty() == true
) {
items.add(createDiscussionsItem())

Check warning on line 782 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L782

Added line #L782 was not covered by tests
}
if (environment.config.isCourseDatesEnabled) {
items.add(createDatesItem())

Check warning on line 785 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L785

Added line #L785 was not covered by tests
}
items.add(createHandoutsItem())
items.add(createAnnouncementsItem())

Check warning on line 788 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L787-L788

Added lines #L787 - L788 were not covered by tests

return items

Check warning on line 790 in OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.kt#L790

Added line #L790 was not covered by tests
}

private fun createCourseOutlineItem(screenName: String?): FragmentItemModel {
return FragmentItemModel(
CourseHomeTabFragment::class.java,
Expand Down

0 comments on commit 9cc5783

Please sign in to comment.