Skip to content

Commit

Permalink
feat: added the external router for deep links
Browse files Browse the repository at this point in the history
  • Loading branch information
dixidroid committed Jun 4, 2024
1 parent 3e95560 commit 3cc55bf
Show file tree
Hide file tree
Showing 23 changed files with 658 additions and 36 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
android:exported="true"
android:fitsSystemWindows="true"
android:theme="@style/Theme.App.Starting"
android:windowSoftInputMode="adjustPan">
android:windowSoftInputMode="adjustPan"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/org/openedx/app/AppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder {
super.onStart()

if (viewModel.isBranchEnabled) {
val callback = BranchUniversalReferralInitListener { _, linkProperties, error ->
if (linkProperties != null) {
val callback = BranchUniversalReferralInitListener { branchUniversalObject, _, error ->
if (branchUniversalObject?.contentMetadata?.customMetadata != null) {
branchLogger.i { "Branch init complete." }
branchLogger.i { linkProperties.controlParams.toString() }
branchLogger.i { branchUniversalObject.contentMetadata.customMetadata.toString() }
viewModel.makeExternalRoute(
fm = supportFragmentManager,
deepLink = DeepLink(branchUniversalObject.contentMetadata.customMetadata)
)
} else if (error != null) {
branchLogger.e { "Branch init failed. Caused by -" + error.message }
}
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.openedx.auth.presentation.restore.RestorePasswordFragment
import org.openedx.auth.presentation.signin.SignInFragment
import org.openedx.auth.presentation.signup.SignUpFragment
import org.openedx.core.FragmentViewType
import org.openedx.core.HomeTab
import org.openedx.core.presentation.course.CourseViewMode
import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRouter
import org.openedx.core.presentation.global.app_upgrade.UpgradeRequiredFragment
Expand Down Expand Up @@ -59,10 +60,15 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
ProfileRouter, AppUpgradeRouter, WhatsNewRouter {

//region AuthRouter
override fun navigateToMain(fm: FragmentManager, courseId: String?, infoType: String?) {
override fun navigateToMain(
fm: FragmentManager,
courseId: String?,
infoType: String?,
selectedTab: HomeTab?
) {
fm.popBackStack()
fm.beginTransaction()
.replace(R.id.container, MainFragment.newInstance(courseId, infoType))
.replace(R.id.container, MainFragment.newInstance(courseId, infoType, selectedTab))
.commit()
}

Expand Down Expand Up @@ -277,12 +283,11 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
override fun navigateToHandoutsWebView(
fm: FragmentManager,
courseId: String,
title: String,
type: HandoutsType
) {
replaceFragmentWithBackStack(
fm,
HandoutsWebViewFragment.newInstance(title, type.name, courseId)
HandoutsWebViewFragment.newInstance(type.name, courseId)
)
}
//endregion
Expand Down Expand Up @@ -400,6 +405,10 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
}
//endregion

fun getVisibleFragment(fm: FragmentManager): Fragment? {
return fm.fragments.firstOrNull { it.isVisible }
}

private fun replaceFragmentWithBackStack(fm: FragmentManager, fragment: Fragment) {
fm.beginTransaction()
.replace(R.id.container, fragment, fragment.javaClass.simpleName)
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/openedx/app/AppViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openedx.app

import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope
Expand All @@ -22,6 +23,7 @@ class AppViewModel(
private val preferencesManager: CorePreferences,
private val dispatcher: CoroutineDispatcher,
private val analytics: AppAnalytics,
private val deepLinkRouter: DeepLinkRouter,
private val fileUtil: FileUtil,
) : BaseViewModel() {

Expand Down Expand Up @@ -71,6 +73,10 @@ class AppViewModel(
preferencesManager.canResetAppDirectory = false
}

fun makeExternalRoute(fm: FragmentManager, deepLink: DeepLink) {
deepLinkRouter.makeRoute(fm, deepLink)
}

private fun setUserId() {
preferencesManager.user?.let {
analytics.setUserIdForSession(it.id)
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/org/openedx/app/DeepLink.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.openedx.app

class DeepLink(params: Map<String, String>) {

val screenName = params[Keys.SCREEN_NAME.value]
val courseId = params[Keys.COURSE_ID.value]
val pathId = params[Keys.PATH_ID.value]
val componentId = params[Keys.COMPONENT_ID.value]
val topicId = params[Keys.TOPIC_ID.value]
val threadId = params[Keys.THREAD_ID.value]
val commentId = params[Keys.COMMENT_ID.value]

enum class Keys(val value: String) {
SCREEN_NAME("screen_name"),
COURSE_ID("course_id"),
PATH_ID("path_id"),
COMPONENT_ID("component_id"),
TOPIC_ID("topic_id"),
THREAD_ID("thread_id"),
COMMENT_ID("comment_id")
}
}
Loading

0 comments on commit 3cc55bf

Please sign in to comment.