diff --git a/app/src/main/java/com/naviapp/configuration/NaviConfigurationActivity.kt b/app/src/main/java/com/naviapp/configuration/NaviConfigurationActivity.kt index 02a3562092..9ea4c5ed78 100644 --- a/app/src/main/java/com/naviapp/configuration/NaviConfigurationActivity.kt +++ b/app/src/main/java/com/naviapp/configuration/NaviConfigurationActivity.kt @@ -34,7 +34,8 @@ class NaviConfigurationActivity : ComponentActivity() { onVersionCodeChange = { BaseUtils.saveUpdatedVersionCodeAndRestart(it, this) }, onBaseUrlChanged = { BaseUtils.saveUpdatedBaseUrlAndRestart(it, this) }, onBackButtonClick = { finish() }, - onEnterApJourneyClicked = ::onEnterApJourneyClicked + onEnterApJourneyClicked = ::onEnterApJourneyClicked, + onRoutingKeyChange = { BaseUtils.saveRoutingKeyAndRestart(it, this) } ) } } @@ -58,22 +59,19 @@ class NaviConfigurationActivity : ComponentActivity() { } private fun onEnterApJourneyClicked(applicationType: String?) { - DeepLinkManager.getDeepLinkListener()?.navigateTo( - activity = this@NaviConfigurationActivity, - ctaData = CtaData( - url = "applicationPlatform/launch", - parameters = listOf( - LineItem( - "applicantType", - "CUSTOMER" + DeepLinkManager.getDeepLinkListener() + ?.navigateTo( + activity = this@NaviConfigurationActivity, + ctaData = + CtaData( + url = "applicationPlatform/launch", + parameters = + listOf( + LineItem(key = "applicantType", value = "CUSTOMER"), + LineItem(key = "applicationType", value = applicationType) + ) ), - LineItem( - "applicationType", - applicationType - ) - ) - ), - finish = true - ) + finish = true + ) } } diff --git a/app/src/main/java/com/naviapp/configuration/composable/NaviConfigurationScreen.kt b/app/src/main/java/com/naviapp/configuration/composable/NaviConfigurationScreen.kt index 4abdb8fb69..1ff96c33a3 100644 --- a/app/src/main/java/com/naviapp/configuration/composable/NaviConfigurationScreen.kt +++ b/app/src/main/java/com/naviapp/configuration/composable/NaviConfigurationScreen.kt @@ -33,11 +33,13 @@ fun NaviConfigurationScreen( onVersionCodeChange: (versionCode: String) -> Unit, onBaseUrlChanged: (baseUrl: String) -> Unit, onBackButtonClick: () -> Unit, - onEnterApJourneyClicked : (applicationType : String?)-> Unit + onEnterApJourneyClicked: (applicationType: String?) -> Unit, + onRoutingKeyChange: (routingKey: String) -> Unit ) { var versionCode by remember { mutableStateOf(TextFieldValue(EMPTY)) } var baseUrl by remember { mutableStateOf(TextFieldValue(EMPTY)) } var applicationType by remember { mutableStateOf(TextFieldValue(EMPTY)) } + var routingKey by remember { mutableStateOf(TextFieldValue(EMPTY)) } Column { NaviTopNavigationBar(onBackButtonClick = onBackButtonClick) @@ -90,6 +92,16 @@ fun NaviConfigurationScreen( onButtonClick = { onEnterApJourneyClicked(applicationType.text) }, ) + NaviTextFieldWithTitleAndButton( + titleText = "Sandbox Routing Key", + placeholderText = "Enter sandbox routing key", + keyboardType = KeyboardType.Uri, + inputText = routingKey, + onTextValueChanged = { routingKey = it }, + buttonText = "Update", + onButtonClick = { onRoutingKeyChange(routingKey.text) }, + ) + Spacer(modifier = Modifier.height(12.dp)) } } @@ -106,6 +118,7 @@ private fun NaviConfigurationScreenPreview() { onVersionCodeChange = {}, onBaseUrlChanged = {}, onBackButtonClick = {}, - onEnterApJourneyClicked = {} + onEnterApJourneyClicked = {}, + onRoutingKeyChange = {} ) } diff --git a/navi-base/src/main/java/com/navi/base/sharedpref/CommonPrefConstants.kt b/navi-base/src/main/java/com/navi/base/sharedpref/CommonPrefConstants.kt index e3290e7216..0594da56b0 100644 --- a/navi-base/src/main/java/com/navi/base/sharedpref/CommonPrefConstants.kt +++ b/navi-base/src/main/java/com/navi/base/sharedpref/CommonPrefConstants.kt @@ -22,9 +22,9 @@ object CommonPrefConstants { const val IS_MOCK_LOCATION = "IS_MOCK_LOCATION" const val IS_LOCATION_DATA_POST = "IS_LOCATION_DATA_POST" const val LOCATION_UPDATE_ENABLED = "LOCATION_UPDATE_ENABLED" - const val CURRENT_FONT = "CURRENT_FONT" const val UPDATED_BASE_URL = "updatedBaseUrl" const val UPDATED_VERSION_CODE = "updatedVersionCode" + const val ROUTING_KEY = "routing_key" const val APP_BASE_URL = "appBaseUrl" const val PULSE_BASE_URL = "pulseBaseUrl" const val UPDATED_PULSE_BASE_URL = "updatedPulseBaseUrl" diff --git a/navi-base/src/main/java/com/navi/base/utils/BaseUtils.kt b/navi-base/src/main/java/com/navi/base/utils/BaseUtils.kt index 54c6dff9ea..2518a3a268 100644 --- a/navi-base/src/main/java/com/navi/base/utils/BaseUtils.kt +++ b/navi-base/src/main/java/com/navi/base/utils/BaseUtils.kt @@ -18,6 +18,7 @@ import android.os.Build import android.provider.Settings import com.navi.base.sharedpref.CommonPrefConstants import com.navi.base.sharedpref.CommonPrefConstants.ALFRED_DIALOG_SCREENSHOT +import com.navi.base.sharedpref.CommonPrefConstants.ROUTING_KEY import com.navi.base.sharedpref.CommonPrefConstants.UPDATED_BASE_URL import com.navi.base.sharedpref.CommonPrefConstants.UPDATED_PULSE_BASE_URL import com.navi.base.sharedpref.CommonPrefConstants.UPDATED_VERSION_CODE @@ -111,11 +112,9 @@ object BaseUtils { value ) } + fun setBaseUrl(baseUrl: String) { - PreferenceManager.setStringPreferenceApp( - key = UPDATED_BASE_URL, - baseUrl - ) + PreferenceManager.setStringPreferenceApp(key = UPDATED_BASE_URL, baseUrl) } fun getPhoneNumberWithCountryCode(): String? { @@ -413,7 +412,7 @@ object BaseUtils { } } - fun checkDiffAndSaveDataInSharedPreference( + private fun checkDiffAndSaveDataInSharedPreference( sharedPrefKey: String, updatedValue: String? ): Boolean { @@ -506,6 +505,21 @@ object BaseUtils { } } + fun saveRoutingKeyAndRestart(updatedRoutingKey: String?, context: Context?) { + if ( + checkDiffAndSaveDataInSharedPreference( + sharedPrefKey = ROUTING_KEY, + updatedValue = updatedRoutingKey + ) + ) { + triggerAppRestart(context = context) + } + } + + fun getRoutingKey(): String? { + return PreferenceManager.getStringPreferenceApp(ROUTING_KEY) + } + fun getDebugVersionCode(): String? = PreferenceManager.getStringPreferenceApp(key = UPDATED_VERSION_CODE) @@ -532,10 +546,10 @@ object BaseUtils { val packageManager = context.packageManager val requestedUpiAppPackageNames = mutableListOf() packageManager?.let { - val allUpiAppsPackageNames = packageManager.queryIntentActivities( - upiIntent, - PackageManager.GET_META_DATA - ).mapNotNull { it.activityInfo?.packageName } + val allUpiAppsPackageNames = + packageManager + .queryIntentActivities(upiIntent, PackageManager.GET_META_DATA) + .mapNotNull { it.activityInfo?.packageName } allUpiAppsPackageNames.forEach { packageName -> if (exceptionUpiApps.contains(packageName).not()) { @@ -545,5 +559,4 @@ object BaseUtils { } return requestedUpiAppPackageNames.isNotEmpty() } - } diff --git a/navi-common/src/main/java/com/navi/common/network/BaseHttpClient.kt b/navi-common/src/main/java/com/navi/common/network/BaseHttpClient.kt index f217fc557a..7c0eb5c6c7 100644 --- a/navi-common/src/main/java/com/navi/common/network/BaseHttpClient.kt +++ b/navi-common/src/main/java/com/navi/common/network/BaseHttpClient.kt @@ -12,6 +12,7 @@ import android.os.Build import com.navi.alfred.AlfredManager import com.navi.analytics.utils.NaviAnalyticsHelper import com.navi.base.security.interceptor.EncryptionHashInterceptor +import com.navi.base.sharedpref.CommonPrefConstants.ROUTING_KEY import com.navi.base.utils.BaseUtils import com.navi.base.utils.isDataNeedsToUpdate import com.navi.common.model.NetworkInfo @@ -35,15 +36,16 @@ abstract class BaseHttpClient( private val networkInfo: NetworkInfo, private val context: Context, private val shouldAddHeaders: Boolean = true, - private val shouldAddAuthenticator : Boolean = true + private val shouldAddAuthenticator: Boolean = true ) { - companion object{ + companion object { const val HEADER_SESSION_TOKEN = "X-Session-Token" const val X_TARGET = "X-Target" const val APPREQUESTID = "appRequestId" const val CF_RAY = "CF_RAY" } + val baseHttpClientBuilder: OkHttpClient.Builder get() { val okHttpClientBuilder = OkHttpClient.Builder() @@ -62,9 +64,7 @@ abstract class BaseHttpClient( addInterceptor(GzipInterceptor()) getChildInterceptors()?.let { interceptors -> - interceptors.forEach { interceptor -> - addInterceptor(interceptor) - } + interceptors.forEach { interceptor -> addInterceptor(interceptor) } } addInterceptor(MetricInterceptor()) @@ -89,6 +89,7 @@ abstract class BaseHttpClient( addUnsafeNonAscii("defaultLocale", BaseUtils.getDefaultLocale()) add("deviceId", BaseUtils.getDeviceId(context)) add(APPREQUESTID, UUID.randomUUID().toString()) + BaseUtils.getRoutingKey()?.let { add(ROUTING_KEY, it) } BaseUtils.getSessionToken()?.let { add(HEADER_SESSION_TOKEN, it) } try { add("X-Click-Stream-Data", NaviAnalyticsHelper.getClickStreamData()) @@ -96,17 +97,15 @@ abstract class BaseHttpClient( Timber.e(e) } networkInfo.moduleName?.name?.let { moduleName -> - add( - X_TARGET, - moduleName - ) + add(X_TARGET, moduleName) } // TODO should removed. GI Backend can use X-Target add("source", "APK") } } request = request.newBuilder().headers(builder.build()).build() - if (isDataNeedsToUpdate( + if ( + isDataNeedsToUpdate( request.method, request.url.toString(), networkInfo.moduleName?.name.orEmpty(), @@ -115,29 +114,32 @@ abstract class BaseHttpClient( ) { TemporaryStorageHelper.updateScreenDataStatus() } - val response: Response = try { - chain.proceed(request).newBuilder().build() - } catch (e: IOException) { - val errorMessage = handleException(e) - logIOException(e, errorMessage, request) - // A mocked response in case of n/w exception - val errorStatusCode: Int = errorMessage.statusCode ?: ApiConstants.API_CODE_ERROR - Response.Builder() - .request(request) - .protocol(Protocol.HTTP_2) - .code(errorStatusCode) - .message(e.message.orEmpty()) - .body(ResponseBody.create("application/json".toMediaTypeOrNull(), "{}")) - .addHeader("content-type", "application/json") - .build() - } + val response: Response = + try { + chain.proceed(request).newBuilder().build() + } catch (e: IOException) { + val errorMessage = handleException(e) + logIOException(e, errorMessage, request) + // A mocked response in case of n/w exception + val errorStatusCode: Int = + errorMessage.statusCode ?: ApiConstants.API_CODE_ERROR + Response.Builder() + .request(request) + .protocol(Protocol.HTTP_2) + .code(errorStatusCode) + .message(e.message.orEmpty()) + .body(ResponseBody.create("application/json".toMediaTypeOrNull(), "{}")) + .addHeader("content-type", "application/json") + .build() + } val endTime = System.currentTimeMillis() val byteSent = request.body?.contentLength() ?: 0L - val byteReceived = try { - response.peekBody(Long.MAX_VALUE).bytes().size.toLong() - } catch (e: Exception) { - 0L - } + val byteReceived = + try { + response.peekBody(Long.MAX_VALUE).bytes().size.toLong() + } catch (e: Exception) { + 0L + } AlfredManager.saveApiLog( byteReceived = byteReceived, byteSent = byteSent,