From af5ed30e8a612d60be93dc7542cfa3e69992fbb4 Mon Sep 17 00:00:00 2001 From: Milan Date: Wed, 13 Nov 2024 15:01:58 +0100 Subject: [PATCH] Application-wide in-app browser for all urls (#1674) * Application-wide in-app browser for all urls * Changelog entries fixed --------- Co-authored-by: Honza --- CHANGELOG.md | 3 +- docs/whatsNew/WHATS_NEW_EN.md | 3 +- docs/whatsNew/WHATS_NEW_ES.md | 3 +- .../screen/about/util/WebBrowserUtilTest.kt | 18 ---------- .../zcash/ui/screen/about/AndroidAboutView.kt | 11 +++--- .../ui/screen/about/util/WebBrowserUtil.kt | 34 +++++++------------ .../integrations/AndroidIntegrations.kt | 11 ++---- 7 files changed, 26 insertions(+), 57 deletions(-) delete mode 100644 ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtilTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b93b3da..2b27a14d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,10 +13,11 @@ and this application adheres to [Semantic Versioning](https://semver.org/spec/v2 - New Sending, Success, Failure, and GrpcFailure subscreens of the Send Confirmation screen have been added - New Copy Transaction IDs feature has been added to the MultipleTransactionFailure screen -### Changelog +### Changed - Shielded transactions are properly indicated in transaction history - The in-app update logic has been fixed and is now correctly requested with every app launch - The Not enough space and In-app udpate screens have been redesigned +- External links now open in in-app browser ### Fixed - Address book toast now correctly shows on send screen when adding both new and known addresses to text field diff --git a/docs/whatsNew/WHATS_NEW_EN.md b/docs/whatsNew/WHATS_NEW_EN.md index 06627942..ec8bea3d 100644 --- a/docs/whatsNew/WHATS_NEW_EN.md +++ b/docs/whatsNew/WHATS_NEW_EN.md @@ -16,10 +16,11 @@ directly impact users rather than highlighting other key architectural updates.* - New Sending, Success, Failure, and GrpcFailure subscreens of the Send Confirmation screen have been added - New Copy Transaction IDs feature has been added to the MultipleTransactionFailure screen -### Changelog +### Changed - Shielded transactions are properly indicated in transaction history - The in-app update logic has been fixed and is now correctly requested with every app launch - The Not enough space and In-app udpate screens have been redesigned +- External links now open in in-app browser ### Fixed - Address book toast now correctly shows on send screen when adding both new and known addresses to text field diff --git a/docs/whatsNew/WHATS_NEW_ES.md b/docs/whatsNew/WHATS_NEW_ES.md index 044370ae..174e2bad 100644 --- a/docs/whatsNew/WHATS_NEW_ES.md +++ b/docs/whatsNew/WHATS_NEW_ES.md @@ -16,10 +16,11 @@ directly impact users rather than highlighting other key architectural updates.* - New Sending, Success, Failure, and GrpcFailure subscreens of the Send Confirmation screen have been added - New Copy Transaction IDs feature has been added to the MultipleTransactionFailure screen -### Changelog +### Changed - Shielded transactions are properly indicated in transaction history - The in-app update logic has been fixed and is now correctly requested with every app launch - The Not enough space and In-app udpate screens have been redesigned +- External links now open in in-app browser ### Fixed - Address book toast now correctly shows on send screen when adding both new and known addresses to text field diff --git a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtilTest.kt b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtilTest.kt deleted file mode 100644 index 74e65f19..00000000 --- a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtilTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package co.electriccoin.zcash.ui.screen.about.util - -import android.content.Intent -import androidx.test.filters.SmallTest -import org.junit.Assert.assertEquals -import org.junit.Test -import kotlin.test.assertContains - -class WebBrowserUtilTest { - @Test - @SmallTest - fun check_intent_for_web_browser() { - val intent = WebBrowserUtil.newActivityIntent(WebBrowserUtil.ZCASH_PRIVACY_POLICY_URI) - assertEquals(intent.action, Intent.ACTION_VIEW) - assertEquals(WebBrowserUtil.FLAGS, intent.flags) - assertContains(WebBrowserUtil.ZCASH_PRIVACY_POLICY_URI, intent.data.toString()) - } -} diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/AndroidAboutView.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/AndroidAboutView.kt index 68a2f93b..05ccd661 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/AndroidAboutView.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/AndroidAboutView.kt @@ -2,7 +2,7 @@ package co.electriccoin.zcash.ui.screen.about -import android.content.Context +import android.app.Activity import androidx.activity.compose.BackHandler import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable @@ -57,7 +57,7 @@ internal fun WrapAbout( configInfo = configInfo, onPrivacyPolicy = { openPrivacyPolicyInWebBrowser( - activity.applicationContext, + activity, snackbarHostState, scope ) @@ -69,17 +69,16 @@ internal fun WrapAbout( } fun openPrivacyPolicyInWebBrowser( - context: Context, + activity: Activity, snackbarHostState: SnackbarHostState, scope: CoroutineScope ) { - val storeIntent = WebBrowserUtil.newActivityIntent(WebBrowserUtil.ZCASH_PRIVACY_POLICY_URI) runCatching { - context.startActivity(storeIntent) + WebBrowserUtil.startActivity(activity, WebBrowserUtil.ZCASH_PRIVACY_POLICY_URI) }.onFailure { scope.launch { snackbarHostState.showSnackbar( - message = context.getString(R.string.about_unable_to_web_browser) + message = activity.getString(R.string.about_unable_to_web_browser) ) } } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtil.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtil.kt index bcc48edd..b1ed771c 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtil.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/about/util/WebBrowserUtil.kt @@ -1,30 +1,22 @@ package co.electriccoin.zcash.ui.screen.about.util -import android.content.Intent +import android.app.Activity import android.net.Uri +import androidx.browser.customtabs.CustomTabsIntent object WebBrowserUtil { - const val FLAGS = - Intent.FLAG_ACTIVITY_NO_HISTORY or - Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_ACTIVITY_MULTIPLE_TASK - const val ZCASH_PRIVACY_POLICY_URI = "https://electriccoin.co/zashi-privacy-policy/" // NON-NLS - /** - * Returns new action view app intent. We assume the a web browser app is installed. - * - * @param url The webpage url to open - * - * @return Intent for launching in a browser app. - */ - internal fun newActivityIntent(url: String): Intent { - val storeUri = Uri.parse(url) - val storeIntent = Intent(Intent.ACTION_VIEW, storeUri) - - // To properly handle the browser backstack while navigate back to our app - storeIntent.addFlags(FLAGS) - - return storeIntent + internal fun startActivity( + activity: Activity, + url: String + ) { + val intent = + CustomTabsIntent.Builder() + .setUrlBarHidingEnabled(true) + .setShowTitle(true) + .setShareState(CustomTabsIntent.SHARE_STATE_OFF) + .build() + intent.launchUrl(activity, Uri.parse(url)) } } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt index cb417c1a..5423fea6 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt @@ -1,8 +1,6 @@ package co.electriccoin.zcash.ui.screen.integrations -import android.net.Uri import androidx.activity.compose.BackHandler -import androidx.browser.customtabs.CustomTabsIntent import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -11,6 +9,7 @@ import co.electriccoin.zcash.di.koinActivityViewModel import co.electriccoin.zcash.ui.common.compose.LocalActivity import co.electriccoin.zcash.ui.common.compose.LocalNavController import co.electriccoin.zcash.ui.common.viewmodel.WalletViewModel +import co.electriccoin.zcash.ui.screen.about.util.WebBrowserUtil import co.electriccoin.zcash.ui.screen.integrations.view.Integrations import co.electriccoin.zcash.ui.screen.integrations.viewmodel.IntegrationsViewModel import com.flexa.core.Flexa @@ -34,13 +33,7 @@ internal fun WrapIntegrations() { LaunchedEffect(Unit) { viewModel.coinbaseNavigationCommand.collect { uri -> - val intent = - CustomTabsIntent.Builder() - .setUrlBarHidingEnabled(true) - .setShowTitle(true) - .setShareState(CustomTabsIntent.SHARE_STATE_OFF) - .build() - intent.launchUrl(activity, Uri.parse(uri)) + WebBrowserUtil.startActivity(activity, uri) } }