mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-27 05:03:28 +00:00
Adjust how we external nav for ideal donations.
This commit is contained in:
committed by
Greyson Parrelli
parent
8013da681f
commit
86fa653ac6
@@ -11,6 +11,8 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.widget.Toast
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.signal.core.util.isNotNullOrBlank
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.donations.StripeApi
|
||||
import org.thoughtcrime.securesms.R
|
||||
|
||||
@@ -20,6 +22,8 @@ import org.thoughtcrime.securesms.R
|
||||
*/
|
||||
object ExternalNavigationHelper {
|
||||
|
||||
private val TAG = Log.tag(ExternalNavigationHelper::class)
|
||||
|
||||
fun maybeLaunchExternalNavigationIntent(context: Context, webRequestUri: Uri?, launchIntent: (Intent) -> Unit): Boolean {
|
||||
val url = webRequestUri ?: return false
|
||||
if (url.scheme?.startsWith("http") == true || url.scheme == StripeApi.RETURN_URL_SCHEME) {
|
||||
@@ -37,55 +41,19 @@ object ExternalNavigationHelper {
|
||||
}
|
||||
|
||||
private fun attemptIntentLaunch(context: Context, url: Uri, launchIntent: (Intent) -> Unit) {
|
||||
val intent = Intent(Intent.ACTION_VIEW, url)
|
||||
val intent = Intent.parseUri(url.toString(), Intent.URI_INTENT_SCHEME)
|
||||
try {
|
||||
launchIntent(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
// Parses intent:// schema uris according to https://developer.chrome.com/docs/multidevice/android/intents/
|
||||
Log.w(TAG, "Cannot find activity for intent. Checking for fallback URL.", e)
|
||||
|
||||
if (url.scheme?.equals("intent") == true) {
|
||||
val fragmentParts: Map<String, String?> = url.fragment
|
||||
?.split(";")
|
||||
?.associate {
|
||||
val parts = it.split('=', limit = 2)
|
||||
|
||||
if (parts.size > 1) {
|
||||
parts[0] to parts[1]
|
||||
} else {
|
||||
parts[0] to null
|
||||
}
|
||||
} ?: emptyMap()
|
||||
|
||||
val fallbackUri = fragmentParts["S.browser_fallback_url"]?.let { Uri.parse(it) }
|
||||
|
||||
val packageId: String? = if (looksLikeAMarketLink(fallbackUri)) {
|
||||
fallbackUri!!.getQueryParameter("id")
|
||||
} else {
|
||||
fragmentParts["package"]
|
||||
}
|
||||
|
||||
if (!packageId.isNullOrBlank()) {
|
||||
try {
|
||||
launchIntent(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("market://details?id=$packageId")
|
||||
)
|
||||
)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toastOnActivityNotFound(context)
|
||||
}
|
||||
} else if (fallbackUri != null) {
|
||||
try {
|
||||
launchIntent(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
fallbackUri
|
||||
)
|
||||
)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toastOnActivityNotFound(context)
|
||||
}
|
||||
val fallback = intent.getStringExtra("browser_fallback_url")
|
||||
if (fallback.isNotNullOrBlank()) {
|
||||
try {
|
||||
launchIntent(Intent.parseUri(fallback, Intent.URI_INTENT_SCHEME))
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.w(TAG, "Failed to launch fallback URL.", e)
|
||||
toastOnActivityNotFound(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,8 +62,4 @@ object ExternalNavigationHelper {
|
||||
private fun toastOnActivityNotFound(context: Context) {
|
||||
Toast.makeText(context, R.string.CommunicationActions_no_browser_found, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun looksLikeAMarketLink(uri: Uri?): Boolean {
|
||||
return uri != null && uri.host == "play.google.com" && uri.getQueryParameter("id") != null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,12 @@ class Stripe3DSDialogFragment : DialogFragment(R.layout.donation_webview_fragmen
|
||||
gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
|
||||
}
|
||||
setOnClickListener {
|
||||
handleLaunchExternal(Intent(Intent.ACTION_VIEW, args.uri))
|
||||
ExternalNavigationHelper.maybeLaunchExternalNavigationIntent(
|
||||
context,
|
||||
args.uri
|
||||
) {
|
||||
handleLaunchExternal(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.root.addView(openApp)
|
||||
|
||||
Reference in New Issue
Block a user