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

Commit

Permalink
fix: Deep links to component navigation (#1827)
Browse files Browse the repository at this point in the history
The links were not functioning properly due to the absence of deep
link handling on the Home Tab. Additionally, we implemented checks
on courseData and binding to prevent them from triggering when the
app starts from deep links.

Fixes: LEARNER-9634
  • Loading branch information
HamzaIsrar12 authored Sep 28, 2023
1 parent 6ef292f commit 29ecb08
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import dagger.hilt.android.AndroidEntryPoint
import org.edx.mobile.R
import org.edx.mobile.base.BaseFragmentActivity
import org.edx.mobile.databinding.FragmentCourseHomeBinding
import org.edx.mobile.deeplink.DeepLink
import org.edx.mobile.deeplink.Screen
import org.edx.mobile.deeplink.ScreenDef
import org.edx.mobile.event.CourseDashboardRefreshEvent
import org.edx.mobile.event.CourseOutlineRefreshEvent
Expand All @@ -28,6 +28,7 @@ import org.edx.mobile.event.MediaStatusChangeEvent
import org.edx.mobile.event.NetworkConnectivityChangeEvent
import org.edx.mobile.event.RefreshCourseDashboardEvent
import org.edx.mobile.exception.CourseContentNotValidException
import org.edx.mobile.extenstion.isNotNullOrEmpty
import org.edx.mobile.extenstion.parcelable
import org.edx.mobile.extenstion.serializableOrThrow
import org.edx.mobile.extenstion.setVisibility
Expand Down Expand Up @@ -114,7 +115,7 @@ class CourseHomeTabFragment : OfflineSupportBaseFragment(), CourseHomeAdapter.On
this.serializableOrThrow(Router.EXTRA_COURSE_DATA) as EnrolledCoursesResponse
courseUpgradeData = this.parcelable(Router.EXTRA_COURSE_UPGRADE_DATA)
courseComponentId = this.getString(Router.EXTRA_COURSE_COMPONENT_ID)
screenName = this.getString(DeepLink.Keys.SCREEN_NAME)
screenName = this.getString(Router.EXTRA_SCREEN_NAME)
} ?: run {
throw IllegalStateException("No arguments available")
}
Expand Down Expand Up @@ -257,6 +258,23 @@ class CourseHomeTabFragment : OfflineSupportBaseFragment(), CourseHomeAdapter.On
}
adapter.submitList(sectionList)
updateListUI()
detectDeepLinking()
}

private fun detectDeepLinking() {
if (Screen.COURSE_COMPONENT.equals(screenName, true)
&& courseComponentId.isNotNullOrEmpty()
) {
val courseUnitDetailIntent = environment.router.getCourseUnitDetailIntent(
requireActivity(),
courseData,
courseUpgradeData,
courseComponentId,
false
)
courseUnitDetailLauncher.launch(courseUnitDetailIntent)
screenName = null
}
}

override fun onSectionItemClick(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class CourseTabsDashboardFragment : BaseFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (this::binding.isInitialized.not()) {
return
}
handleTabSelection(requireArguments())

if (EventBus.getDefault().isRegistered(this).not())
Expand Down Expand Up @@ -442,7 +445,9 @@ class CourseTabsDashboardFragment : BaseFragment() {

override fun onResume() {
super.onResume()
courseDateViewModel.fetchCourseDates(courseData.courseId, true)
if (this::binding.isInitialized) {
courseDateViewModel.fetchCourseDates(courseData.courseId, true)
}
}

override fun onPause() {
Expand Down

0 comments on commit 29ecb08

Please sign in to comment.