Application-wide in-app browser for all urls (#1674)

* Application-wide in-app browser for all urls

* Changelog entries fixed

---------

Co-authored-by: Honza <rychnovsky.honza@gmail.com>
This commit is contained in:
Milan 2024-11-13 15:01:58 +01:00 committed by GitHub
parent d4be4a5dda
commit af5ed30e8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 26 additions and 57 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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())
}
}

View File

@ -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)
)
}
}

View File

@ -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))
}
}

View File

@ -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)
}
}