diff --git a/app/build.gradle b/app/build.gradle index fc7ae1c943..e82d04d2b9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -339,7 +339,7 @@ dependencies { }) // Facebook sdk - implementation 'com.facebook.android:facebook-android-sdk:8.2.0' + implementation 'com.facebook.android:facebook-applinks:[4,5)' // for branch io deeplink implementation 'io.branch.sdk.android:library:5.+' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index af2e27748f..2e0aa4fb8a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -263,6 +263,10 @@ tools:replace="android:resource" /> + + { - val url = jsonObject.optString(URL).replace("-", "/") - val source = jsonObject.optString(Constants.LOGIN_SOURCE) - val additionalDataRequired = jsonObject.optBoolean(ADDITIONAL_DATA_NEEDED) - if (CommonUtils.isUserLoggedIn()) { - if (additionalDataRequired) { - fetchData(activity, source, url) - } else { - NaviDeepLinkNavigator.navigate( - activity, - CtaData(url = url), - bundle = extractData(jsonObject), - finish = true, - clearTask = true - ) - } - } else if (isPublicPage(url)) { - NaviDeepLinkNavigator.navigate( - activity, - CtaData(url = url), - bundle = extractData(jsonObject), - finish = true, - clearTask = true - ) - } else if (source.isNullOrEmpty().not()) { - NaviDeepLinkNavigator.navigate( - activity, - CtaData(url = DeeplinkConstants.REGISTRATION), - bundle = extractData(jsonObject), - finish = true, - clearTask = true - ) - } else if (deepLinkValue.isNullOrEmpty().not()) { - NaviDeepLinkNavigator.navigate( - activity, - CtaData(url = DeeplinkConstants.REGISTRATION), - bundle = Bundle().apply { - putString( - Constants.LOGIN_SOURCE, - deepLinkValue - ) - }, - finish = true, - clearTask = true - ) - } + val url = jsonObject?.optString(URL)?.replace("-", "/").orEmpty() + val source = jsonObject?.optString(Constants.LOGIN_SOURCE) + val additionalDataRequired = jsonObject?.optBoolean(ADDITIONAL_DATA_NEEDED) + redirectToDestination( + activity, + url, + source, + additionalDataRequired, + extractData(jsonObject), + deepLinkValue + ) } DeeplinkType.FB.name -> { - // handle deeplink data + uriData?.let { uri -> + val url = uri.getQueryParameter(URL).orEmpty() + val source = uri.getQueryParameter(Constants.LOGIN_SOURCE) + val additionalDataRequired = + uri.getQueryParameter(ADDITIONAL_DATA_NEEDED)?.toBoolean() + redirectToDestination( + activity, + url, + source, + additionalDataRequired, + extractData(uri), + deepLinkValue + ) + } } } } catch (ex: Exception) { @@ -104,6 +86,58 @@ object DeeplinkManager { } } + private fun redirectToDestination( + activity: Activity, + url: String, + source: String?, + additionalDataRequired: Boolean?, + bundle: Bundle, + deepLinkValue: String? = null + ) { + if (CommonUtils.isUserLoggedIn()) { + if (additionalDataRequired.orFalse()) { + fetchData(activity, source, url) + } else { + NaviDeepLinkNavigator.navigate( + activity, + CtaData(url = url), + bundle = bundle, + finish = true, + clearTask = true + ) + } + } else if (isPublicPage(url)) { + NaviDeepLinkNavigator.navigate( + activity, + CtaData(url = url), + bundle = bundle, + finish = true, + clearTask = true + ) + } else if (source.isNullOrEmpty().not()) { + NaviDeepLinkNavigator.navigate( + activity, + CtaData(url = DeeplinkConstants.REGISTRATION), + bundle = bundle, + finish = true, + clearTask = true + ) + } else if (deepLinkValue.isNullOrEmpty().not()) { + NaviDeepLinkNavigator.navigate( + activity, + CtaData(url = DeeplinkConstants.REGISTRATION), + bundle = Bundle().apply { + putString( + Constants.LOGIN_SOURCE, + deepLinkValue + ) + }, + finish = true, + clearTask = true + ) + } + } + private fun fetchData(activity: Activity, channel: String?, url: String) { coroutineScope.launch { val response: RepoResult = if (channel == BranchManager.CHANNEL_GI) { diff --git a/app/src/main/java/com/naviapp/analytics/utils/NaviSDKHelper.kt b/app/src/main/java/com/naviapp/analytics/utils/NaviSDKHelper.kt index 89f4d31d8a..7c3586a7f4 100644 --- a/app/src/main/java/com/naviapp/analytics/utils/NaviSDKHelper.kt +++ b/app/src/main/java/com/naviapp/analytics/utils/NaviSDKHelper.kt @@ -33,8 +33,7 @@ import com.naviapp.utils.getAppName object NaviSDKHelper { fun init(naviApplication: NaviApplication) { FirebaseRemoteConfigHelper.init() - FacebookSdk.setAutoInitEnabled(true) - FacebookSdk.fullyInitialize() + FacebookSdk.sdkInitialize(naviApplication) val inAppOptOutScreens = mutableSetOf>() inAppOptOutScreens.add(SplashActivity::class.java) NaviTrackEvent.appInit( diff --git a/app/src/main/java/com/naviapp/registration/SplashActivity.kt b/app/src/main/java/com/naviapp/registration/SplashActivity.kt index 2a03144d6b..463a5a2704 100644 --- a/app/src/main/java/com/naviapp/registration/SplashActivity.kt +++ b/app/src/main/java/com/naviapp/registration/SplashActivity.kt @@ -11,7 +11,7 @@ import android.os.Bundle import android.os.Handler import androidx.databinding.DataBindingUtil import androidx.lifecycle.ViewModelProvider -import com.facebook.applinks.AppLinkData +import bolts.AppLinks import com.navi.amc.investorapp.constants.Constant import com.navi.analytics.appsflyer.AppsFlyerUtil import com.navi.analytics.appsflyer.DeepLinkListener @@ -246,11 +246,11 @@ class SplashActivity : BaseActivity(), DeepLinkListener { } private fun fbDeeplink() { - AppLinkData.fetchDeferredAppLinkData(this) { appData -> - appData?.appLinkData?.let { appLinkData -> - DeeplinkManager.handleDeeplinkData(this, appLinkData, DeeplinkType.FB.name) - } - } + DeeplinkManager.handleDeeplinkData( + this, + uriData = AppLinks.getTargetUrlFromInboundIntent(this, intent), + type = DeeplinkType.FB.name + ) } override fun onBackPressed() { @@ -262,6 +262,11 @@ class SplashActivity : BaseActivity(), DeepLinkListener { get() = NaviAnalytics.SPLASH override fun onDeepLinking(jsonObject: JSONObject, type: String, deepLinkValue: String?) { - DeeplinkManager.handleDeeplinkData(this, jsonObject, type, deepLinkValue) + DeeplinkManager.handleDeeplinkData( + this, + jsonObject, + type = type, + deepLinkValue = deepLinkValue + ) } } diff --git a/app/src/main/java/com/naviapp/utils/Utility.kt b/app/src/main/java/com/naviapp/utils/Utility.kt index 4c8cd9e545..37bfa3626f 100644 --- a/app/src/main/java/com/naviapp/utils/Utility.kt +++ b/app/src/main/java/com/naviapp/utils/Utility.kt @@ -603,9 +603,9 @@ fun isPublicPage(screen: String?): Boolean { } } -fun extractData(jsonObject: JSONObject): Bundle { +fun extractData(jsonObject: JSONObject?): Bundle { val bundle = Bundle() - jsonObject.keys().forEach { key -> + jsonObject?.keys()?.forEach { key -> val value = jsonObject.opt(key) try { when (value) { @@ -621,4 +621,12 @@ fun extractData(jsonObject: JSONObject): Bundle { } } return bundle +} + +fun extractData(uri: Uri?): Bundle { + val bundle = Bundle() + uri?.queryParameterNames?.forEach { key -> + bundle.putString(key, uri.getQueryParameter(key)) + } + return bundle } \ No newline at end of file diff --git a/navi-amc/src/main/java/com/navi/amc/investorapp/ui/splash/SplashActivity.kt b/navi-amc/src/main/java/com/navi/amc/investorapp/ui/splash/SplashActivity.kt deleted file mode 100644 index 2da5329272..0000000000 --- a/navi-amc/src/main/java/com/navi/amc/investorapp/ui/splash/SplashActivity.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.navi.amc.investorapp.ui.splash - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.lifecycleScope -import com.navi.amc.investorapp.R -import com.navi.amc.investorapp.extension.goto -import com.navi.amc.investorapp.extension.statusBarTransparent -import com.navi.amc.investorapp.ui.home.HomeActivity -import com.navi.amc.investorapp.utils.RootDeviceUtil -import com.navi.analytics.utils.NaviTrackEvent -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch - -class SplashActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_splash) - init() - } - - private fun init() { - if (!RootDeviceUtil.instance.isDeviceRooted()) { - lifecycleScope.launch { - delay(1000) - try { - goto(HomeActivity::class.java) - } catch (e: Exception) { - } - } - } else { - NaviTrackEvent.trackEvent("THIS_USER_IS_ROOTED") - } - } -} - diff --git a/navi-amc/src/main/res/layout/activity_splash.xml b/navi-amc/src/main/res/layout/activity_splash.xml index f35d846e93..956f5dc3a3 100644 --- a/navi-amc/src/main/res/layout/activity_splash.xml +++ b/navi-amc/src/main/res/layout/activity_splash.xml @@ -7,8 +7,7 @@ + android:background="@color/white"> --> - - val errorText = - if (err.message.isNullOrEmpty()) "Something went wrong" else "Error: ${err.message}" - Toast.makeText( - this, - errorText, - Toast.LENGTH_LONG - ).show() - - navigateToNextScreen() - } - registrationVM.errorMessage.observeNonNull(this) { err -> - err.getContentIfNotHandled()?.run(errorObserver) - } - } - - /*private fun checkUpgrade() { - - val appUpdateInfoTask = - appUpdateManager?.appUpdateInfo - - appUpdateInfoTask?.addOnSuccessListener { appUpdateInfo -> - if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) { - val updateType: String = FirebaseRemoteConfigUtils.getString("IN_APP_UPDATE_TYPE") - if (updateType == "IMMEDIATE") { - try { - appUpdateManager?.startUpdateFlowForResult( - appUpdateInfo, - AppUpdateType.IMMEDIATE, - this, - APP_UPDATE_REQUEST_CODE - ) - } catch (e: IntentSender.SendIntentException) { - FirebaseCrashlytics.getInstance().recordException(e) - } - } else { - try { - appUpdateManager?.startUpdateFlowForResult( - appUpdateInfo, - AppUpdateType.FLEXIBLE, - this, - APP_UPDATE_REQUEST_CODE - ) - } catch (e: IntentSender.SendIntentException) { - FirebaseCrashlytics.getInstance().recordException(e) - } - } - } else if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) { - launchRestartDialog(appUpdateManager!!) - } else { - checkAppUpdateAndProceed() - } - } - - appUpdateInfoTask?.addOnFailureListener { - checkAppUpdateAndProceed() - } - }*/ - - /* private fun initInAppUpdateConfig() { - appUpdateManager = AppUpdateManagerFactory.create(this) - listener = InstallStateUpdatedListener { installState -> - if (installState.installStatus() == InstallStatus.DOWNLOADED) { - launchRestartDialog(appUpdateManager!!) - } else if (installState.installStatus() == InstallStatus.INSTALLED) { - appUpdateManager?.unregisterListener(listener) - } else if (installState.installStatus() == InstallStatus.DOWNLOADING) { - navigateToNextScreen() - } - } - appUpdateManager?.registerListener(listener) - }*/ - - private fun checkAppUpdateAndProceed() { - registrationVM.appSettings.value?.run { - if (this.appUpgradeResponse?.hardUpgrade.orFalse() || this.appUpgradeResponse?.softUpgrade.orFalse()) { - val intent = Intent(this@SplashActivity, UpdateAppActivity::class.java) - intent.putExtra(Constants.APP_UPGRADE_EXTRA, this.appUpgradeResponse) - if (this.appUpgradeResponse?.hardUpgrade.orFalse()) { - //Needs forced update - startActivity(intent) - finish() - } else { - //Needs soft update - startActivityForResult(intent, SOFT_UPGRADE_REQUEST_CODE) - } - } else { - //No need of forced update, go with app flow - handler.postDelayed({ - navigateToNextScreen() - }, SPLASH_MAX_DELAY) - } - } ?: navigateToNextScreen() - } - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - when (requestCode) { - SOFT_UPGRADE_REQUEST_CODE -> navigateToNextScreen() - APP_UPDATE_REQUEST_CODE -> { - if (resultCode != Activity.RESULT_OK) { - navigateToNextScreen() - } - } - } - super.onActivityResult(requestCode, resultCode, data) - } - - private fun initPreferences() { - NaviPreferenceManager.setStringPreference(USER_LOCATION_COUNTRY_CODE, "IN") //TODO - } - - private fun navigateToNextScreen() { - var nextScreen = "" - - when { - - //Hit API to check if policies exist - CommonUtils.isUserLoggedIn() -> { - fetchUserPolicies() - } - - //Send user to Landing page if not logged in - else -> { - - launchLandingPage() - - } - } - - } - - private fun checkForDeeplink() { - AppLinkData.fetchDeferredAppLinkData( - this - ) { - if (it != null) { - NaviPreferenceManager.setBooleanPreference(IS_FROM_FB, true) - } - } - } - - private fun redirectToQuoteScreen(od: OfferDetail) { - var nextScreen = "" - - val intent = Intent(this@SplashActivity, BuyInsuranceActivity::class.java) - - nextScreen = InsuranceAnalyticsConstants.OFFER_FORM - - intent.putExtra(REDIRECT_TO_QUOTE_SCREEN_EXTRA, true) - intent.putExtra(QUOTE_DETAILS_EXTRA, od) - - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - startActivity(intent) - - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - - } - - private fun fetchUserPolicies() { - policyVM.customerPolicies.observeNonNull(this) { - observeLastQuote(it) - offerVM.fetchQuoteIfExists() - } - - val errorObserver = { err: ErrorMessage -> - if (!tryHandleError(err, null)) { - val errorText = - if (err.message.isNullOrEmpty()) "Something went wrong" else "Error: ${err.message}" - Toast.makeText( - this, - errorText, - Toast.LENGTH_LONG - ).show() - } - } - - policyVM.errorMessage.observeNonNull(this) { err -> - err.getContentIfNotHandled()?.run(errorObserver) - } - policyVM.fetchCustomerPolicies() - } - - private fun observeLastQuote(customerPolicyDetails: CustomerPolicyDetails) { - offerVM.quoteDetail.observeNullable(this) { - if (it?.status == PROCESSING_PAYMENT && it.paymentReferenceId != null) { - binding.logoImage.visibility = View.GONE - val paymentProcessingFragment = - PaymentProcessingFragment.newInstance(it.paymentReferenceId) - supportFragmentManager.beginTransaction() - .setCustomAnimations( - R.anim.slide_in_right, - R.anim.slide_out_left, - R.anim.slide_in_left, - R.anim.slide_out_right - ) - .replace( - R.id.form_fragment, - paymentProcessingFragment, - PaymentProcessingFragment.TAG - ) - .addToBackStack(PaymentProcessingFragment.TAG) - .commit() - } else if (!isNoPolicies()) { - redirectToDashboard(customerPolicyDetails) - } else { - var nextScreen = "" - if (it == null) { - if (NaviPreferenceManager.getStringPreference(BOOK_INSURANCE_RESULT) - .isNullOrBlank() - ) { - //Redirect to landing page if no ongoing chat - launchLandingPage() - - } else { - //Redirect to chat if chat already in progress - val intent = Intent(this@SplashActivity, ChatActivity::class.java) - intent.flags = - Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - startActivity(intent) - - nextScreen = InsuranceAnalyticsConstants.INSURANCE_FORM - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - - } - - } else if (it.quoteProcessType == Constants.NSTP) { - if (!NaviPreferenceManager.getBooleanPreference(QUOTE_GENERATED_FOR_CURRENT_CHAT) && it.updateAllowed) { - //Redirect to landing page if no ongoing chat - val intent = Intent(this@SplashActivity, ChatActivity::class.java) - intent.flags = - Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - startActivity(intent) - - nextScreen = InsuranceAnalyticsConstants.CHAT_SCREEN - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - } else { - val intent = Intent(this@SplashActivity, BuyInsuranceActivity::class.java) - intent.putExtra(REDIRECT_TO_QUOTE_SCREEN_EXTRA, true) - intent.putExtra(QUOTE_DETAILS_EXTRA, it as OfferDetail) - intent.flags = - Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - startActivity(intent) - } - } else if (!NaviPreferenceManager.getBooleanPreference( - QUOTE_GENERATED_FOR_CURRENT_CHAT - ) - ) { - //Redirect to chat with quote details if there is incomplete chat - val intent = Intent(this, ChatActivity::class.java) - intent.putExtra(Constants.IS_QUOTE_DETAILS_EXTRA, true) - intent.putExtra(QUOTE_DETAILS_EXTRA, it) - startActivity(intent) - - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - } else { - //Redirect to quote screen - redirectToQuoteScreen(it) - } - - finish() - } - } - - offerVM.proposalDetail.observeNonNull(this) { - - var nextScreen = "" - - if (!isNoPolicies()) { - redirectToDashboard(customerPolicyDetails) - } else if (it.status == ACCEPTED) { - it.proposalId?.let { it1 -> offerVM.getQuoteFromProposal(it1) } - } else { - val intent = Intent(this@SplashActivity, ChatActivity::class.java) - intent.putExtra(PROPOSAL_EXTRA, it) - intent.putExtra(PROPOSAL_STATUS_EXTRA, it.status) - intent.flags = - Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - startActivity(intent) - - nextScreen = InsuranceAnalyticsConstants.INSURANCE_FORM - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - - } - } - - val errorObserver = { err: ErrorMessage -> - if (!tryHandleError(err, null)) { - showErrorMessageToast(this, err.message) - } - } - - offerVM.errorMessage.observeNonNull(this) { err -> - err.getContentIfNotHandled()?.run(errorObserver) - } - } - - private fun launchLandingPage() { - var nextScreen = "" - if (FirebaseRemoteConfigUtils.getBoolean("AB_TEST_SKIP_INTRO_SCREEN")) { - val intent = Intent(this@SplashActivity, RegisterActivity::class.java) - intent.flags = - Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - intent.putExtra("sourceScreen", screenName) - startActivity(intent) - - nextScreen = InsuranceAnalyticsConstants.REGISTER_SCREEN - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - } else { - val intent = Intent(this@SplashActivity, IntroActivityV3::class.java) - intent.flags = - Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - startActivity(intent) - - nextScreen = InsuranceAnalyticsConstants.INTRO_SCREEN - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - } - - } - - private fun redirectToDashboard(customerPolicyDetails: CustomerPolicyDetails) { - val intent = Intent(this@SplashActivity, DashboardActivity::class.java) - - intent.putExtra(POLICY_DETAILS_EXTRA, customerPolicyDetails) - intent.putExtra("sourceScreen", screenName) - intent.putExtra("showBack", false) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - startActivity(intent) - - val nextScreen = InsuranceAnalyticsConstants.DASHBOARD_SCREEN - NaviInsuranceAnalytics.postAnalyticsEvent( - "HI_next_screen_$nextScreen", - mapOf(Pair("screen", screenName)) - ) - } - - private fun isNoPolicies(): Boolean { - return policyVM.customerPolicies.value?.applications?.filter { - checkProposalStatus(it.status) - }?.size?.orZero() == 0 - && policyVM.customerPolicies.value?.policies?.size?.orZero() == 0 - } - - /*private fun initThirdPartyServices() { - //Record session on UX Cam if non-debug build - if (!DEBUG) { - UXCam.startWithKey(getString(R.string.ux_cam_key)) - } - }*/ - - /* private fun postDeviceDetailsToServer() { - coroutineScope.launch { - val userDeviceDetails: DeviceDetailsRequest? = getUserDeviceDetails( - NaviInsuranceApplication.instance.applicationContext - ) - - if (userDeviceDetails != null) { - registrationVM.postUserDeviceDetailsPreLogin(userDeviceDetails) - } - } - }*/ - - override val screenName - get() = InsuranceAnalyticsConstants.SPLASH_SCREEN -}