diff --git a/android/app/src/main/java/com/naviapp/common/navigator/NaviDeepLinkNavigator.kt b/android/app/src/main/java/com/naviapp/common/navigator/NaviDeepLinkNavigator.kt index 94f1bf825f..5f04ea97bd 100644 --- a/android/app/src/main/java/com/naviapp/common/navigator/NaviDeepLinkNavigator.kt +++ b/android/app/src/main/java/com/naviapp/common/navigator/NaviDeepLinkNavigator.kt @@ -144,7 +144,7 @@ import com.naviapp.utils.deleteCacheAndOpenLoginPage import com.naviapp.utils.openPlayStore import com.naviapp.utils.openWhatsAppChatConversation import com.naviapp.utils.toggleNaviPayIntentActivityState -import com.naviapp.webredirection.presentation.chrometab.CustomChromeTabManager.warmUpAndLaunchCCT +import com.naviapp.webredirection.presentation.chrometab.CustomChromeTabManager.launchCustomChromeTab import com.naviapp.webredirection.presentation.utils.BUSINESS_UNIT import com.naviapp.webredirection.presentation.utils.WEB_PLATFORM_IDENTIFIER import com.naviapp.webredirection.presentation.utils.WEB_REDIRECTION_SUBTITLE @@ -201,7 +201,7 @@ object NaviDeepLinkNavigator : DeepLinkListener { private const val ICON_TITLE_DESC_BOTTOMSHEET = "icon_title_desc_bottomsheet" private const val GOLD = "gold" const val WEB_URL = "webUrl" - private const val CUSTOM_CHROME_TAB = "customChromeTab" + private const val ENABLE_CUSTOM_CHROME_TAB = "enableCustomChromeTab" private const val NAVI_WEB_VIEW = "NAVI_WEB_VIEW" private const val OPEN_EMAIL = "openEmail" const val VIEW_VIDEO = "view_video" @@ -642,7 +642,7 @@ object NaviDeepLinkNavigator : DeepLinkListener { var isCustomChromeTab: Boolean? = false ctaData.parameters?.forEach { keyValue -> if (keyValue.key == URL) url = keyValue.value - else if (keyValue.key == CUSTOM_CHROME_TAB) + else if (keyValue.key == ENABLE_CUSTOM_CHROME_TAB) isCustomChromeTab = keyValue.value.toBoolean() } if (url.isNullOrEmpty() && bundle.containsKey(URL)) { @@ -661,7 +661,7 @@ object NaviDeepLinkNavigator : DeepLinkListener { } } activity?.let { - warmUpAndLaunchCCT( + launchCustomChromeTab( activity = activity, url = url.orEmpty(), events = diff --git a/android/app/src/main/java/com/naviapp/webredirection/presentation/chrometab/CustomChromeTabManager.kt b/android/app/src/main/java/com/naviapp/webredirection/presentation/chrometab/CustomChromeTabManager.kt index 3aeaf0e1ad..08c3cfb283 100644 --- a/android/app/src/main/java/com/naviapp/webredirection/presentation/chrometab/CustomChromeTabManager.kt +++ b/android/app/src/main/java/com/naviapp/webredirection/presentation/chrometab/CustomChromeTabManager.kt @@ -11,6 +11,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.ActivityNotFoundException import android.content.ComponentName +import android.content.Context import android.content.Intent import android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP import android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP @@ -164,18 +165,41 @@ object CustomChromeTabManager { } } + fun launchCustomChromeTab( + url: String, + events: CustomChromeTabCustomEvents, + activity: Activity, + ) { + this.url = url + // Use applicationContext to avoid leaking an Activity reference. + val appContext = AppServiceManager.application.applicationContext + val packageName = CustomTabsClient.getPackageName(appContext, null) + if (packageName != null) { + warmUpAndLaunchCCT( + url = url, + events = events, + activity = activity, + appContext = appContext, + packageName = packageName, + ) + } else { + launchWebPageInChrome(activity, url) + } + } + /** * This function should be called to warm up the custom tab and launch it. Used to open url in * custom tab for cases where we do not need any token exchange. For Ex:- Ads * * @param activity The activity from which the custom tab is launched. */ - fun warmUpAndLaunchCCT(url: String, events: CustomChromeTabCustomEvents, activity: Activity) { - this.url = url - // Use applicationContext to avoid leaking an Activity reference. - val appContext = AppServiceManager.application.applicationContext - val packageName = CustomTabsClient.getPackageName(appContext, null) - + private fun warmUpAndLaunchCCT( + url: String, + events: CustomChromeTabCustomEvents, + activity: Activity, + appContext: Context, + packageName: String, + ) { customTabsServiceConnection = object : CustomTabsServiceConnection() { @SuppressLint("RequiresFeature") @@ -185,15 +209,7 @@ object CustomChromeTabManager { ) { try { warmUp(client = client, events = events) - if (packageName != null) { - launchWebPageInCustomChromeTab(activity, url) - } else { - /** - * Fallback to opening the Url in browser, if custom tab is not - * available * - */ - launchWebPageInChrome(activity, url) - } + launchWebPageInCustomChromeTab(activity, url) } catch (e: Exception) { NaviTrackEvent.trackEvent( eventName = CHROME_CUSTOM_TAB_WARMUP_AND_LAUNCH_FAILED, @@ -250,7 +266,6 @@ object CustomChromeTabManager { ) { try { warmUp(client = client, events = events) - customTabsSession?.mayLaunchUrl(Uri.parse(url), null, null) } catch (e: Exception) { NaviTrackEvent.trackEvent( eventName = CHROME_CUSTOM_TAB_WARMUP_FAILED, @@ -280,6 +295,7 @@ object CustomChromeTabManager { if (isEngagementSignalsSupported()) { customTabsSession?.setEngagementSignalsCallback(engagementCallback(events), Bundle()) } + customTabsSession?.mayLaunchUrl(Uri.parse(url), null, null) } fun cleanup() {