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 authored and lukstbit committed May 19, 2024
1 parent 22efbf3 commit 555a8e0
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,9 @@ abstract class CardViewerFragment(@LayoutRes layout: Int) : Fragment(layout) {
"videoended" -> viewModel.onVideoFinished()
"videopause" -> viewModel.onVideoPaused()
"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 -> {
"android-app" -> handleIntentUrl(url, Intent.URI_ANDROID_APP_SCHEME)
"intent" -> handleIntentUrl(url, Intent.URI_INTENT_SCHEME)
else -> {
try {
openUrl(url)
} catch (_: Throwable) {
Expand All @@ -180,6 +169,21 @@ abstract class CardViewerFragment(@LayoutRes layout: Int) : Fragment(layout) {
return true
}

private fun handleIntentUrl(url: Uri, flags: Int) {
val intent = Intent.parseUri(url.toString(), flags)
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 555a8e0

Please sign in to comment.