Updated on 2026-08-14
This commit is contained in:
commit
c48ddbff25
5 changed files with 61 additions and 4 deletions
|
|
@ -30,6 +30,13 @@
|
|||
</intent>
|
||||
</queries>
|
||||
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name=
|
||||
"android.support.customtabs.action.CustomTabsService" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:name="com.tangem.tap.TangemHiltApplication"
|
||||
android:allowBackup="false"
|
||||
|
|
@ -53,7 +60,7 @@
|
|||
android:name="com.tangem.tap.MainActivity"
|
||||
android:configChanges="uiMode"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/SplashTheme"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
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
|
||||
|
|
@ -12,6 +15,7 @@ import com.tangem.tap.common.extensions.getColorCompat
|
|||
import com.tangem.tap.foregroundActivityObserver
|
||||
import com.tangem.tap.withForegroundActivity
|
||||
import com.tangem.wallet.R
|
||||
import timber.log.Timber
|
||||
|
||||
internal class CustomTabsUrlOpener : UrlOpener {
|
||||
|
||||
|
|
@ -34,6 +38,37 @@ internal class CustomTabsUrlOpener : UrlOpener {
|
|||
)
|
||||
.build()
|
||||
|
||||
customTabsIntent.launchUrl(context, Uri.parse(url))
|
||||
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
runCatching {
|
||||
if (checkCustomTabsAvailability(context, browserIntent)) {
|
||||
context.startActivity(browserIntent)
|
||||
} else {
|
||||
customTabsIntent.launchUrl(context, Uri.parse(url))
|
||||
}
|
||||
}.onFailure {
|
||||
Timber.e(it.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Tabs compatibility check. Returns flag whether custom tabs are supported
|
||||
* @see "https://developer.chrome.com/docs/android/custom-tabs/howto-custom-tab-check"
|
||||
*/
|
||||
private fun checkCustomTabsAvailability(context: Context, browserIntent: Intent): Boolean {
|
||||
// Get all apps that can handle VIEW intents and Custom Tab service connections.
|
||||
val resolveInfos = context.packageManager.queryIntentActivities(browserIntent, PackageManager.MATCH_ALL)
|
||||
|
||||
// Extract package names from ResolveInfo objects
|
||||
val packageNames = mutableListOf<String>()
|
||||
for (info in resolveInfos) {
|
||||
packageNames.add(info.activityInfo.packageName)
|
||||
}
|
||||
|
||||
// Get a package that supports Custom Tabs
|
||||
val packageName = CustomTabsClient.getPackageName(context, packageNames, true)
|
||||
|
||||
return packageName == null // Custom Tabs are not supported by any browser on the device
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams
|
|||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
@Deprecated("Replace with CustomTabsUrlOpener")
|
||||
class CustomTabsManager(private val context: WeakReference<Context>) {
|
||||
|
||||
fun openUrl(url: String) {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,13 @@ internal class DefaultTokenDetailsRouter(
|
|||
}
|
||||
|
||||
override fun openOnrampSuccess(externalTxId: String) {
|
||||
router.push(AppRoute.OnrampSuccess(externalTxId))
|
||||
// finish current onramp flow and show onramp success screen
|
||||
val replaceOnrampScreens = router.stack
|
||||
.filterNot { it is AppRoute.Onramp }
|
||||
.toMutableList()
|
||||
|
||||
replaceOnrampScreens.add(AppRoute.OnrampSuccess(externalTxId))
|
||||
|
||||
router.replaceAll(*replaceOnrampScreens.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +130,14 @@ internal class DefaultWalletRouter(
|
|||
}
|
||||
|
||||
override fun openOnrampSuccessScreen(externalTxId: String) {
|
||||
router.push(AppRoute.OnrampSuccess(externalTxId))
|
||||
// finish current onramp flow and show onramp success screen
|
||||
val replaceOnrampScreens = router.stack
|
||||
.filterNot { it is AppRoute.Onramp }
|
||||
.toMutableList()
|
||||
|
||||
replaceOnrampScreens.add(AppRoute.OnrampSuccess(externalTxId))
|
||||
|
||||
router.replaceAll(*replaceOnrampScreens.toTypedArray())
|
||||
}
|
||||
|
||||
override fun openUrl(url: String) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue