Updated on 2026-08-14
This commit is contained in:
commit
8bef5a68d8
4 changed files with 41 additions and 18 deletions
|
|
@ -3,12 +3,12 @@ package com.tangem.tap.common.url
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
|
||||||
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||||
import androidx.browser.customtabs.CustomTabsClient
|
import androidx.browser.customtabs.CustomTabsClient
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_DARK
|
import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_DARK
|
||||||
import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_LIGHT
|
import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_LIGHT
|
||||||
|
import androidx.core.net.toUri
|
||||||
import com.tangem.core.navigation.url.UrlOpener
|
import com.tangem.core.navigation.url.UrlOpener
|
||||||
import com.tangem.tap.common.apptheme.MutableAppThemeModeHolder
|
import com.tangem.tap.common.apptheme.MutableAppThemeModeHolder
|
||||||
import com.tangem.tap.common.extensions.getColorCompat
|
import com.tangem.tap.common.extensions.getColorCompat
|
||||||
|
|
@ -25,30 +25,37 @@ internal class CustomTabsUrlOpener : UrlOpener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun openUrlExternalBrowser(url: String) {
|
||||||
|
foregroundActivityObserver.withForegroundActivity { context ->
|
||||||
|
if (url.isEmpty()) return@withForegroundActivity
|
||||||
|
val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||||
|
context.startActivity(browserIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun openUrl(url: String, context: Context) {
|
private fun openUrl(url: String, context: Context) {
|
||||||
if (url.isEmpty()) return
|
if (url.isEmpty()) return
|
||||||
val customTabsIntent = CustomTabsIntent.Builder()
|
val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||||
.setDefaultColorSchemeParams(
|
|
||||||
CustomTabColorSchemeParams.Builder()
|
|
||||||
.setNavigationBarColor(context.getColorCompat(R.color.toolbarColor))
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
.setColorScheme(
|
|
||||||
if (MutableAppThemeModeHolder.isDarkThemeActive) COLOR_SCHEME_DARK else COLOR_SCHEME_LIGHT,
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
|
|
||||||
|
|
||||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
|
||||||
runCatching {
|
runCatching {
|
||||||
if (checkCustomTabsAvailability(context, browserIntent)) {
|
if (checkCustomTabsAvailability(context, browserIntent)) {
|
||||||
context.startActivity(browserIntent)
|
context.startActivity(browserIntent)
|
||||||
} else {
|
} else {
|
||||||
customTabsIntent.launchUrl(context, Uri.parse(url))
|
val customTabsIntent = CustomTabsIntent.Builder()
|
||||||
|
.setDefaultColorSchemeParams(
|
||||||
|
CustomTabColorSchemeParams.Builder()
|
||||||
|
.setNavigationBarColor(context.getColorCompat(R.color.toolbarColor))
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
.setColorScheme(
|
||||||
|
if (MutableAppThemeModeHolder.isDarkThemeActive) COLOR_SCHEME_DARK else COLOR_SCHEME_LIGHT,
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
|
customTabsIntent.launchUrl(context, url.toUri())
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it.message)
|
Timber.e(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,8 @@ class DummyUrlOpener : UrlOpener {
|
||||||
override fun openUrl(url: String) {
|
override fun openUrl(url: String) {
|
||||||
/* no-op */
|
/* no-op */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun openUrlExternalBrowser(url: String) {
|
||||||
|
/* no-op */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,4 +3,6 @@ package com.tangem.core.navigation.url
|
||||||
interface UrlOpener {
|
interface UrlOpener {
|
||||||
|
|
||||||
fun openUrl(url: String)
|
fun openUrl(url: String)
|
||||||
|
|
||||||
|
fun openUrlExternalBrowser(url: String)
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +86,13 @@ internal class OnrampRedirectModel @Inject constructor(
|
||||||
.onLeft(::handleError)
|
.onLeft(::handleError)
|
||||||
.onRight {
|
.onRight {
|
||||||
latestOnrampTransaction = it
|
latestOnrampTransaction = it
|
||||||
urlOpener.openUrl(it.redirectUrl)
|
|
||||||
|
// Workaround to open Unlimit provider in external browser instead of chrome custom tabs
|
||||||
|
if (params.onrampProviderWithQuote.provider.id.equals(UNLIMIT_PROVIDER_ID, ignoreCase = true)) {
|
||||||
|
urlOpener.openUrlExternalBrowser(it.redirectUrl)
|
||||||
|
} else {
|
||||||
|
urlOpener.openUrl(it.redirectUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -127,4 +133,8 @@ internal class OnrampRedirectModel @Inject constructor(
|
||||||
|
|
||||||
messageSender.send(message)
|
messageSender.send(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val UNLIMIT_PROVIDER_ID = "unlimit"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue