TP-65594 | Shankar | UPI Caching for login/logout case (#10995)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2021-2023 by Navi Technologies Limited
|
||||
* * Copyright © 2021-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
@@ -35,4 +35,5 @@ object CommonPrefConstants {
|
||||
const val PREFERENCE_SSL_KEY = "sslKey"
|
||||
const val FAQ_RECENT_SEARCH = "FAQ_RECENT_SEARCH"
|
||||
const val DEVICE_LOCATION = "DEVICE_LOCATION"
|
||||
const val PREVIOUS_LOGGED_IN_EXTERNAL_CUSTOMER_ID = "PREVIOUS_LOGGED_IN_EXTERNAL_CUSTOMER_ID"
|
||||
}
|
||||
|
||||
@@ -16,6 +16,13 @@ import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.navi.base.sharedpref.CommonPrefConstants.CURRENT_USER
|
||||
import com.navi.base.sharedpref.CommonPrefConstants.IS_LOAN_JOURNEY_DATA_DELETED
|
||||
import com.navi.base.utils.removeSelectiveData
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
object PreferenceManager {
|
||||
@@ -27,12 +34,12 @@ object PreferenceManager {
|
||||
|
||||
// Cleared on logout/endOfSession
|
||||
private lateinit var sharedPreferencesForSession: SharedPreferences
|
||||
private var secureSharedPreferencesForSession: SharedPreferences? = null
|
||||
|
||||
// Not cleared on logout/endOfSession
|
||||
private lateinit var sharedPreferencesForApp: SharedPreferences
|
||||
private var secureSharedPreferencesForApp: SharedPreferences? = null
|
||||
|
||||
private var secureSharedPreferencesForSession: SharedPreferences? = null
|
||||
private lateinit var gson: Gson
|
||||
|
||||
fun init(application: Application) {
|
||||
@@ -179,13 +186,29 @@ object PreferenceManager {
|
||||
}
|
||||
}
|
||||
|
||||
fun clearPrefDataSession() {
|
||||
try {
|
||||
sharedPreferencesForSession.edit().clear().apply()
|
||||
if (shouldUseEncryptedSharedPref()) {
|
||||
secureSharedPreferencesForSession?.edit()?.clear()?.apply()
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
fun clearPrefDataSession(
|
||||
excludeSharedPrefKeys: List<String> = listOf(),
|
||||
excludeSecureSharedPrefKeys: List<String> = listOf()
|
||||
) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val clearSharedPrefTasks = mutableListOf<Deferred<Unit>>()
|
||||
clearSharedPrefTasks.add(
|
||||
async {
|
||||
removeSelectiveData(sharedPreferencesForSession, excludeSharedPrefKeys)
|
||||
}
|
||||
)
|
||||
clearSharedPrefTasks.add(
|
||||
async {
|
||||
removeSelectiveData(
|
||||
secureSharedPreferencesForSession,
|
||||
excludeSecureSharedPrefKeys
|
||||
)
|
||||
}
|
||||
)
|
||||
clearSharedPrefTasks.awaitAll()
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun removePrefData(keys: Array<String>) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2021-2023 by Navi Technologies Limited
|
||||
* * Copyright © 2021-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
@@ -77,6 +77,10 @@ object BaseUtils {
|
||||
?: run { PreferenceManager.getStringPreference(CommonPrefConstants.PHONE_NUMBER) }
|
||||
}
|
||||
|
||||
fun getExternalCustomerId(): String? {
|
||||
return PreferenceManager.getStringPreference(CommonPrefConstants.USER_EXTERNAL_ID)
|
||||
}
|
||||
|
||||
fun getEmail(): String? {
|
||||
return PreferenceManager.getSecureString(CommonPrefConstants.EMAIL)
|
||||
?: run { PreferenceManager.getStringPreference(CommonPrefConstants.EMAIL) }
|
||||
@@ -579,4 +583,17 @@ object BaseUtils {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun saveCurrentExternalCustomerId(externalCustomerId: String) {
|
||||
PreferenceManager.saveStringPreferenceAppOnMainThread(
|
||||
CommonPrefConstants.PREVIOUS_LOGGED_IN_EXTERNAL_CUSTOMER_ID,
|
||||
externalCustomerId
|
||||
)
|
||||
}
|
||||
|
||||
fun getPreviousLoggedInExternalCustomerId(): String? {
|
||||
return PreferenceManager.getStringPreferenceApp(
|
||||
CommonPrefConstants.PREVIOUS_LOGGED_IN_EXTERNAL_CUSTOMER_ID
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.base.utils
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
fun removeSelectiveData(
|
||||
sharedPreferencesForSession: SharedPreferences?,
|
||||
excludeSharedPrefKeys: List<String>
|
||||
) {
|
||||
val data = getExcludeSharedPrefKeysData(sharedPreferencesForSession, excludeSharedPrefKeys)
|
||||
sharedPreferencesForSession?.edit()?.clear()?.commit()
|
||||
updateExcludeSharedPrefKeysDataBackSharedPref(sharedPreferencesForSession, data)
|
||||
}
|
||||
|
||||
private fun getExcludeSharedPrefKeysData(
|
||||
sharedPreferencesForSession: SharedPreferences?,
|
||||
excludeSharedPrefKeys: List<String>
|
||||
): Map<String, Any?> {
|
||||
val excludeSharedPrefMap = mutableMapOf<String, Any>()
|
||||
val allSharedPref = sharedPreferencesForSession?.all
|
||||
excludeSharedPrefKeys.forEach { key ->
|
||||
val value = allSharedPref?.get(key)
|
||||
if (value != null) {
|
||||
excludeSharedPrefMap[key] = value
|
||||
}
|
||||
}
|
||||
return excludeSharedPrefMap
|
||||
}
|
||||
|
||||
private fun updateExcludeSharedPrefKeysDataBackSharedPref(
|
||||
sharedPreferencesForSession: SharedPreferences?,
|
||||
sharedPrefKeys: Map<String, Any?>?
|
||||
) {
|
||||
val sharedPrefEditor = sharedPreferencesForSession?.edit()
|
||||
sharedPrefKeys?.keys?.forEach { key ->
|
||||
when (val value = sharedPrefKeys[key]) {
|
||||
is Boolean -> sharedPrefEditor?.putBoolean(key, value)
|
||||
is String -> sharedPrefEditor?.putString(key, value)
|
||||
is Long -> sharedPrefEditor?.putLong(key, value)
|
||||
is Float -> sharedPrefEditor?.putFloat(key, value)
|
||||
}
|
||||
}
|
||||
sharedPrefEditor?.apply()
|
||||
}
|
||||
Reference in New Issue
Block a user