Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-30 15:58:43 +05:00
parent 955da46b07
commit 6b2fa7b9be
4 changed files with 41 additions and 18 deletions

View file

@ -3,12 +3,12 @@ package com.tangem.tap.common.url
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsClient
import androidx.browser.customtabs.CustomTabsIntent
import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_DARK
import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_LIGHT
import androidx.core.net.toUri
import com.tangem.core.navigation.url.UrlOpener
import com.tangem.tap.common.apptheme.MutableAppThemeModeHolder
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) {
if (url.isEmpty()) return
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
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri())
runCatching {
if (checkCustomTabsAvailability(context, browserIntent)) {
context.startActivity(browserIntent)
} 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 {
Timber.e(it.message)
Timber.e(it)
}
}

View file

@ -5,4 +5,8 @@ class DummyUrlOpener : UrlOpener {
override fun openUrl(url: String) {
/* no-op */
}
override fun openUrlExternalBrowser(url: String) {
/* no-op */
}
}

View file

@ -3,4 +3,6 @@ package com.tangem.core.navigation.url
interface UrlOpener {
fun openUrl(url: String)
fun openUrlExternalBrowser(url: String)
}

View file

@ -86,7 +86,13 @@ internal class OnrampRedirectModel @Inject constructor(
.onLeft(::handleError)
.onRight {
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)
}
private companion object {
const val UNLIMIT_PROVIDER_ID = "unlimit"
}
}