From 496e0ea566a0f9493a4803d73a4c2f3bf4ec0df7 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 28 Mar 2024 09:31:09 +0100 Subject: [PATCH] Improve openUrlInExternalApp API and move url to UnifiedPushConfig --- .../android/libraries/androidutils/system/SystemUtils.kt | 3 +-- .../libraries/pushproviders/unifiedpush/UnifiedPushConfig.kt | 2 ++ .../unifiedpush/troubleshoot/OpenDistributorWebPageAction.kt | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt index 9f473a7089..737eab7ac7 100644 --- a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt @@ -156,10 +156,9 @@ fun Context.startSharePlainTextIntent( fun Context.openUrlInExternalApp( url: String, errorMessage: String = getString(R.string.error_no_compatible_app_found), - inNewTask: Boolean = false, ) { val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) - if (inNewTask) { + if (this !is Activity) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } try { diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushConfig.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushConfig.kt index 07c57496db..b1d321f42f 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushConfig.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushConfig.kt @@ -23,6 +23,8 @@ object UnifiedPushConfig { */ const val DEFAULT_PUSH_GATEWAY_HTTP_URL: String = "https://matrix.gateway.unifiedpush.org/_matrix/push/v1/notify" + const val UNIFIED_PUSH_DISTRIBUTORS_URL = "https://unifiedpush.org/users/distributors/" + const val INDEX = 1 const val NAME = "UnifiedPush" } diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/OpenDistributorWebPageAction.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/OpenDistributorWebPageAction.kt index daad9afda3..dda4292f12 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/OpenDistributorWebPageAction.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/OpenDistributorWebPageAction.kt @@ -21,6 +21,7 @@ import com.squareup.anvil.annotations.ContributesBinding import io.element.android.libraries.androidutils.system.openUrlInExternalApp import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.ApplicationContext +import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig import javax.inject.Inject interface OpenDistributorWebPageAction { @@ -34,8 +35,7 @@ class DefaultOpenDistributorWebPageAction @Inject constructor( override fun execute() { // Open the distributor download page context.openUrlInExternalApp( - url = "https://unifiedpush.org/users/distributors/", - inNewTask = true + url = UnifiedPushConfig.UNIFIED_PUSH_DISTRIBUTORS_URL, ) } }