Merge pull request #5126 from element-hq/feature/bma/redirectToElementPro

Redirect FOSS user to Element Pro according to element .well-known file
This commit is contained in:
Benoit Marty 2025-08-08 09:38:59 +02:00 committed by GitHub
commit 1afcce2b97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 657 additions and 45 deletions

View file

@ -165,6 +165,7 @@ fun Context.startSharePlainTextIntent(
fun Context.openUrlInExternalApp(
url: String,
errorMessage: String = getString(R.string.error_no_compatible_app_found),
throwInCaseOfError: Boolean = false,
) {
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
if (this !is Activity) {
@ -173,10 +174,27 @@ fun Context.openUrlInExternalApp(
try {
startActivity(intent)
} catch (activityNotFoundException: ActivityNotFoundException) {
if (throwInCaseOfError) throw activityNotFoundException
toast(errorMessage)
}
}
/**
* Open Google Play on the provided application Id.
*/
fun Context.openGooglePlay(
appId: String,
) {
try {
openUrlInExternalApp(
url = "market://details?id=$appId",
throwInCaseOfError = true,
)
} catch (_: ActivityNotFoundException) {
openUrlInExternalApp("https://play.google.com/store/apps/details?id=$appId")
}
}
// Not in KTX anymore
fun Context.toast(resId: Int) {
Toast.makeText(this, resId, Toast.LENGTH_SHORT).show()

View file

@ -69,6 +69,7 @@ const val A_REDACTION_REASON = "A redaction reason"
const val A_HOMESERVER_URL = "matrix.org"
const val A_HOMESERVER_URL_2 = "matrix-client.org"
const val AN_ACCOUNT_PROVIDER_URL = "https://account.provider.org"
const val AN_ACCOUNT_PROVIDER = "matrix.org"
const val AN_ACCOUNT_PROVIDER_2 = "element.io"
const val AN_ACCOUNT_PROVIDER_3 = "other.io"