Skip to content

Commit

Permalink
Move try catch to the global handler
Browse files Browse the repository at this point in the history
This way the same behavior is exercised both when using the lambda
directly and when we use the LocalUriHandler composition local.
  • Loading branch information
StylianosGakis committed Jan 8, 2025
1 parent 5e80aa4 commit 3ca5964
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,7 @@ internal fun HedvigApp(
hedvigDeepLinkContainer = hedvigDeepLinkContainer,
externalNavigator = externalNavigator,
shouldShowRequestPermissionRationale = shouldShowRequestPermissionRationale,
openUrl = { uri ->
try {
deepLinkFirstUriHandler.openUri(uri)
} catch (e: IllegalArgumentException) {
logcat(LogPriority.ERROR) { "Tried to open uri: $uri but got IllegalArgumentException" }
// todo: not sure we need it, it's more for it not to crash while we still not getting proper uri for addon etc
}
},
openUrl = deepLinkFirstUriHandler::openUri,
finishApp = finishApp,
market = marketManager.market.collectAsStateWithLifecycle().value,
imageLoader = imageLoader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hedvig.android.app.urihandler
import androidx.compose.ui.platform.UriHandler
import androidx.core.net.toUri
import androidx.navigation.NavController
import com.hedvig.android.logger.LogPriority
import com.hedvig.android.logger.logcat

/**
Expand All @@ -14,13 +15,17 @@ internal class DeepLinkFirstUriHandler(
private val delegate: UriHandler,
) : UriHandler {
override fun openUri(uri: String) {
if (navController.graph.hasDeepLink(uri.toUri())) {
logcat { "DeepLinkFirstUriHandler will try to navigate to uri:$uri" }
navController.navigate(uri.toUri())
logcat { "DeepLinkFirstUriHandler did deep link to uri:$uri" }
} else {
logcat { "DeepLinkFirstUriHandler falling back to default UriHandler for uri:$uri" }
delegate.openUri(uri)
try {
if (navController.graph.hasDeepLink(uri.toUri())) {
logcat { "DeepLinkFirstUriHandler will try to navigate to uri:$uri" }
navController.navigate(uri.toUri())
logcat { "DeepLinkFirstUriHandler did deep link to uri:$uri" }
} else {
logcat { "DeepLinkFirstUriHandler falling back to default UriHandler for uri:$uri" }
delegate.openUri(uri)
}
} catch (e: IllegalArgumentException) {
logcat(LogPriority.ERROR) { "Tried to open uri: $uri but got IllegalArgumentException" }
}
}
}

0 comments on commit 3ca5964

Please sign in to comment.