Skip to content

Commit

Permalink
add intent url to previewer
Browse files Browse the repository at this point in the history
  • Loading branch information
MorenoTropical committed May 17, 2024
1 parent 3067fd6 commit 5db214f
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,13 @@ abstract class CardViewerFragment(@LayoutRes layout: Int) : Fragment(layout) {
"tts-voices" -> TtsVoicesDialogFragment().show(childFragmentManager, null)
"android-app" -> {
val intent = Intent.parseUri(url.toString(), Intent.URI_ANDROID_APP_SCHEME)
if (packageManager.resolveActivityCompat(intent) != null) {
startActivity(intent)
} else {
val packageName = intent.getPackage() ?: return true
val marketUri = Uri.parse("market://details?id=$packageName")
val marketIntent = Intent(Intent.ACTION_VIEW, marketUri)
Timber.d("Trying to open market uri %s", marketUri)
if (packageManager.resolveActivityCompat(marketIntent) != null) {
startActivity(marketIntent)
}
}
} else -> {
handleIntentUrl(intent)
}
"intent" -> {
val intent = Intent.parseUri(url.toString(), Intent.URI_INTENT_SCHEME)
handleIntentUrl(intent)
}
else -> {
try {
openUrl(url)
} catch (_: Throwable) {
Expand All @@ -180,6 +175,20 @@ abstract class CardViewerFragment(@LayoutRes layout: Int) : Fragment(layout) {
return true
}

private fun handleIntentUrl(intent: Intent) {
if (packageManager.resolveActivityCompat(intent) != null) {
startActivity(intent)
} else {
val packageName = intent.getPackage() ?: return
val marketUri = Uri.parse("market://details?id=$packageName")
val marketIntent = Intent(Intent.ACTION_VIEW, marketUri)
Timber.d("Trying to open market uri %s", marketUri)
if (packageManager.resolveActivityCompat(marketIntent) != null) {
startActivity(marketIntent)
}
}
}

override fun onReceivedError(
view: WebView,
request: WebResourceRequest,
Expand Down

0 comments on commit 5db214f

Please sign in to comment.