NTP-1234 | Profile api call optimizations (#15689)
This commit is contained in:
@@ -54,7 +54,6 @@ import com.navi.base.utils.orZero
|
||||
import com.navi.common.constants.APP_UPGRADE_DATA
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper.HP_IAN_FETCH_DISABLED
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper.HP_PROFILE_FETCH_DISABLED
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper.RESOURCE_MANAGER_ENABLED
|
||||
import com.navi.common.handler.CollectRequestPopupEventHandler
|
||||
import com.navi.common.managers.PermissionsManager
|
||||
@@ -441,9 +440,6 @@ class HomePageActivity :
|
||||
handleStatusBarColor()
|
||||
if (BaseUtils.isUserLoggedIn()) {
|
||||
fetchNotificationItems()
|
||||
fetchProfileItems(
|
||||
fetchDataDisabled = FirebaseRemoteConfigHelper.getBoolean(HP_PROFILE_FETCH_DISABLED)
|
||||
)
|
||||
fetchScreenOverlayData()
|
||||
}
|
||||
TempStorageHelper.clear()
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.naviapp.home.compose.profile.ProfileScreenShimmer
|
||||
import com.naviapp.home.model.BottomBarTabType
|
||||
import com.naviapp.home.reducer.HpEvents
|
||||
import com.naviapp.home.reducer.HpStates
|
||||
import com.naviapp.home.ui.state.ProfileScreenState
|
||||
import com.naviapp.home.ui.theme.color.HomeScreenColor.scrimColor
|
||||
import com.naviapp.home.utils.HandleUitronRenderer
|
||||
import com.naviapp.home.viewmodel.HomeViewModel
|
||||
@@ -81,9 +80,7 @@ fun HomeContentFrame(
|
||||
if (hpStates().profileDrawerState) {
|
||||
if (drawerState.isClosed) {
|
||||
drawerState.open()
|
||||
if (profileVM.profileScreenDataState.value !is ProfileScreenState.Success) {
|
||||
activity.fetchProfileItems(isProfileDrawerOpen = true)
|
||||
}
|
||||
activity.fetchProfileItems(isProfileDrawerOpen = true)
|
||||
}
|
||||
} else {
|
||||
if (drawerState.isOpen) drawerState.close()
|
||||
|
||||
@@ -7,17 +7,21 @@
|
||||
|
||||
package com.naviapp.home.viewmodel
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.google.gson.Gson
|
||||
import com.navi.base.cache.model.NaviCacheEntity
|
||||
import com.navi.base.cache.repository.NaviCacheRepository
|
||||
import com.navi.base.cache.util.NaviSharedDbKeys
|
||||
import com.navi.base.sharedpref.PreferenceManager
|
||||
import com.navi.base.utils.isNotNullAndNotEmpty
|
||||
import com.navi.common.commoncomposables.utils.resetScrollToTop
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper
|
||||
import com.navi.common.network.models.RepoResult
|
||||
import com.navi.common.utils.BiometricPromptUtils
|
||||
import com.navi.common.utils.Constants.ScreenLockConstants.DISABLED
|
||||
import com.navi.common.utils.Constants.ScreenLockConstants.ENABLED
|
||||
import com.navi.common.utils.Constants.ScreenLockConstants.HPC_SCREEN_LOCK_EXPERIMENT
|
||||
import com.navi.common.utils.Constants.ScreenLockConstants.IS_SCREEN_LOCK_ENABLED
|
||||
import com.navi.common.utils.Constants.ScreenLockConstants.TOGGLE_SWITCH_CHECKED_STATE
|
||||
import com.navi.common.utils.Constants.ScreenLockConstants.TOGGLE_SWITCH_LAYOUT_ID
|
||||
@@ -26,6 +30,7 @@ import com.navi.common.utils.isValidResponse
|
||||
import com.navi.common.viewmodel.BaseVM
|
||||
import com.navi.uitron.model.action.UpdateViewStateAction
|
||||
import com.navi.uitron.model.data.UiTronActionData
|
||||
import com.naviapp.analytics.utils.NaviAnalytics
|
||||
import com.naviapp.forge.model.ScreenDefinition
|
||||
import com.naviapp.home.respository.ProfileRepository
|
||||
import com.naviapp.home.ui.state.ProfileScreenState
|
||||
@@ -33,6 +38,7 @@ import com.naviapp.network.di.DataDeserializers
|
||||
import com.naviapp.network.di.DataSerializers
|
||||
import com.naviapp.utils.Constants.PROFILE
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
@@ -50,6 +56,7 @@ constructor(
|
||||
private val naviCacheRepository: NaviCacheRepository,
|
||||
@DataDeserializers private val dataDeserializers: Gson,
|
||||
@DataSerializers private val dataSerializers: Gson,
|
||||
@ApplicationContext private val context: Context,
|
||||
) : BaseVM() {
|
||||
|
||||
private val _profileScreenDataState =
|
||||
@@ -65,10 +72,37 @@ constructor(
|
||||
|
||||
var isErrorNaeTriggered = false
|
||||
|
||||
private val biometricPromptUtils by lazy { BiometricPromptUtils() }
|
||||
|
||||
init {
|
||||
initProfileItems()
|
||||
initListeners()
|
||||
}
|
||||
|
||||
private fun initProfileItems() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val profilePageResponse =
|
||||
naviCacheRepository.get(key = NaviSharedDbKeys.NAVI_APP_PROFILE.keyName)
|
||||
val isCacheValid = profilePageResponse?.value.isNotNullAndNotEmpty()
|
||||
if (isCacheValid) {
|
||||
getCachedProfilePageResponse(profilePageResponse)
|
||||
} else {
|
||||
getProfileResponseFromApi(
|
||||
isScreenLockEnabled =
|
||||
FirebaseRemoteConfigHelper.getBoolean(IS_SCREEN_LOCK_ENABLED) &&
|
||||
PreferenceManager.getStringPreference(HPC_SCREEN_LOCK_EXPERIMENT) ==
|
||||
ENABLED,
|
||||
isMobileScreenLockSet =
|
||||
biometricPromptUtils.isDeviceSecure(context) &&
|
||||
PreferenceManager.getStringPreference(IS_SCREEN_LOCK_ENABLED) !=
|
||||
DISABLED,
|
||||
naeScreenName = NaviAnalytics.NEW_HOME_ACTIVITY,
|
||||
isNaeRequired = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initListeners() {
|
||||
observeScreenToggleDataFromHandle()
|
||||
observeBiometricAuthenticationEnabledStatus()
|
||||
@@ -132,18 +166,13 @@ constructor(
|
||||
naeScreenName: String,
|
||||
isProfileDrawerOpen: Boolean,
|
||||
) {
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val profilePageResponse =
|
||||
naviCacheRepository.get(key = NaviSharedDbKeys.NAVI_APP_PROFILE.keyName)
|
||||
val isCacheValid =
|
||||
canCachedDataBeUsed && profilePageResponse?.value.isNotNullAndNotEmpty()
|
||||
if (isCacheValid) {
|
||||
val cacheResponse =
|
||||
dataDeserializers.fromJson(
|
||||
profilePageResponse?.value,
|
||||
ScreenDefinition::class.java,
|
||||
)
|
||||
_profileScreenDataState.update { ProfileScreenState.Success(cacheResponse) }
|
||||
getCachedProfilePageResponse(profilePageResponse)
|
||||
}
|
||||
getProfileResponseFromApi(
|
||||
isScreenLockEnabled = isScreenLockEnabled,
|
||||
@@ -154,6 +183,12 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCachedProfilePageResponse(profilePageResponse: NaviCacheEntity?) {
|
||||
val cacheResponse =
|
||||
dataDeserializers.fromJson(profilePageResponse?.value, ScreenDefinition::class.java)
|
||||
_profileScreenDataState.update { ProfileScreenState.Success(cacheResponse) }
|
||||
}
|
||||
|
||||
private suspend fun setSuccessState(response: RepoResult<ScreenDefinition>) {
|
||||
_profileScreenDataState.update { ProfileScreenState.Success(response.data!!) }
|
||||
naviCacheRepository.save(
|
||||
|
||||
Reference in New Issue
Block a user