-
Notifications
You must be signed in to change notification settings - Fork 0
Install Airbridge SDK and Migrate from Firebase Dynamic Links #3
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,17 +17,13 @@ package xyz.duckee.android | |
|
|
||
| import android.net.Uri | ||
| import android.os.Bundle | ||
| import android.util.Log | ||
| import android.view.WindowManager | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.compose.setContent | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.core.view.WindowCompat | ||
| import androidx.navigation.NavHostController | ||
| import com.google.firebase.dynamiclinks.PendingDynamicLinkData | ||
| import com.google.firebase.dynamiclinks.ktx.dynamicLinks | ||
| import com.google.firebase.ktx.Firebase | ||
| import com.stripe.android.paymentsheet.PaymentSheet | ||
| import com.stripe.android.paymentsheet.PaymentSheetResult | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
|
|
@@ -48,6 +44,7 @@ import xyz.duckee.android.core.navigation.navigateToDetailScreen | |
| import xyz.duckee.android.core.navigation.navigateToExploreTab | ||
| import xyz.duckee.android.core.navigation.navigateToRecipeScreen | ||
| import xyz.duckee.android.core.navigation.navigateToSignInScreen | ||
| import co.ab180.airbridge.Airbridge | ||
|
|
||
| @AndroidEntryPoint | ||
| class MainActivity : ComponentActivity() { | ||
|
|
@@ -118,51 +115,55 @@ class MainActivity : ComponentActivity() { | |
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| handleAirbridgeDeeplink() | ||
| } | ||
|
|
||
| Firebase.dynamicLinks | ||
| .getDynamicLink(intent) | ||
| .addOnSuccessListener(this) { pendingDynamicLinkData: PendingDynamicLinkData? -> | ||
| pendingDynamicLinkData?.link?.let { deepLink -> | ||
| val path = deepLink.path ?: return@let | ||
| when { | ||
| path.startsWith("/recipe/") -> { | ||
| val recipePattern = "/recipe/(\\d+)".toRegex() | ||
| val matchResult = recipePattern.find(path) | ||
| matchResult?.let { result -> | ||
| val recipeId = result.groupValues[1] | ||
| navigationController?.navigateToRecipeScreen(recipeId) | ||
| } | ||
| } | ||
|
|
||
| path.startsWith("/detail/") -> { | ||
| val detailPattern = "/detail/([\\w-]+)".toRegex() | ||
| val matchResult = detailPattern.find(path) | ||
| matchResult?.let { result -> | ||
| val detailId = result.groupValues[1] | ||
| navigationController?.navigateToDetailScreen(detailId) | ||
| } | ||
| } | ||
|
|
||
| path == "/explore" -> { | ||
| navigationController?.navigateToExploreTab() | ||
| } | ||
|
|
||
| path == "/collection" -> { | ||
| navigationController?.navigateToCollectionTab() | ||
| } | ||
|
|
||
| path == "/signin" -> { | ||
| navigationController?.navigateToSignInScreen() | ||
| } | ||
|
|
||
| else -> { | ||
| Timber.tag("[DuckeeMainActivity]").w("Unhandled deep link path: $path") | ||
| } | ||
| } | ||
| private fun handleAirbridgeDeeplink() { | ||
| Airbridge.handleDeeplink(intent) { deeplink -> | ||
| handleDeeplink(deeplink) | ||
| } | ||
|
|
||
| Airbridge.handleDeferredDeeplink { deeplink -> | ||
| deeplink?.let { handleDeeplink(it) } | ||
| } | ||
| } | ||
|
Comment on lines
+121
to
+129
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented Airbridge deeplink handling logic. This code is called when the app is launched or resumed via a deeplink, and navigates the user to the appropriate screen. The navigation controller is used to move to the screen corresponding to the deeplink URL. |
||
|
|
||
| private fun handleDeeplink(deeplink: Uri) { | ||
| val path = deeplink.path ?: return | ||
| when { | ||
| path.startsWith("/recipe/") -> { | ||
| val recipePattern = "/recipe/(\\d+)".toRegex() | ||
| val matchResult = recipePattern.find(path) | ||
| matchResult?.let { result -> | ||
| val recipeId = result.groupValues[1] | ||
| navigationController?.navigateToRecipeScreen(recipeId) | ||
| } | ||
| } | ||
|
|
||
| path.startsWith("/detail/") -> { | ||
| val detailPattern = "/detail/([\\w-]+)".toRegex() | ||
| val matchResult = detailPattern.find(path) | ||
| matchResult?.let { result -> | ||
| val detailId = result.groupValues[1] | ||
| navigationController?.navigateToDetailScreen(detailId) | ||
| } | ||
| } | ||
| .addOnFailureListener(this) { e -> | ||
| Timber.tag("[DuckeeMainActivity]").w(e, "getDynamicLink:onFailure") | ||
|
|
||
| path == "/explore" -> { | ||
| navigationController?.navigateToExploreTab() | ||
| } | ||
|
|
||
| path == "/collection" -> { | ||
| navigationController?.navigateToCollectionTab() | ||
| } | ||
|
|
||
| path == "/signin" -> { | ||
| navigationController?.navigateToSignInScreen() | ||
| } | ||
|
|
||
| else -> { | ||
| Timber.tag("[DuckeeMainActivity]").w("Unhandled deep link path: $path") | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+131
to
168
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored the deeplink handling logic to support both Airbridge deeplinks and deferred deeplinks. This change ensures that the app can handle various types of deeplinks, including those that might be triggered after the app is installed. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the AndroidManifest.xml to include Airbridge deeplink schemes and hosts. This configuration is crucial for the app to intercept and handle Airbridge deeplinks correctly. Without these intent filters, the app won't be able to respond to Airbridge deeplinks.