NTP-3871 | reducing api calls on cams on sell page (#12595)
This commit is contained in:
@@ -231,11 +231,17 @@ constructor(
|
||||
} else {
|
||||
// In the error case if the experiment fails, we will show the new investment tab or the
|
||||
// old one based on the flag
|
||||
investmentTabV2Enabled = investmentTabV2Enabled ?: true
|
||||
investmentTabV2Enabled =
|
||||
investmentTabV2Enabled
|
||||
?: isInvestmentTabResponseInCache(INVESTMENT_TAB_AB_EXPERIMENT_NAME).orFalse()
|
||||
fetchInvestmentTabBasedOnABExperiment()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun isInvestmentTabResponseInCache(cacheKey: String): Boolean {
|
||||
return naviCacheRepository.get(cacheKey) != null
|
||||
}
|
||||
|
||||
private fun setInvestmentTabResponseFromCache(isLoading: Boolean = false) {
|
||||
viewModelScope.safeLaunch(Dispatchers.IO) {
|
||||
val cachedResponse =
|
||||
|
||||
@@ -31,7 +31,7 @@ data class SubItemData(
|
||||
@SerializedName("actionData", alternate = ["action"]) val actionData: ActionData? = null,
|
||||
@SerializedName("titleIcon") val titleIcon: IconAction? = null,
|
||||
@SerializedName("timeLeft", alternate = ["timerInvalidateAfter"])
|
||||
val timerInvalidateAfter: Long? = null
|
||||
var timerInvalidateAfter: Long? = null
|
||||
) : Parcelable
|
||||
|
||||
@Parcelize
|
||||
|
||||
@@ -75,12 +75,32 @@ class FundSellFragment : AmcBaseFragment() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
fetchData(genericTimer.isInitialised())
|
||||
checkIfTimerIsInitialized()
|
||||
}
|
||||
|
||||
private fun checkIfTimerIsInitialized() {
|
||||
viewModel.entryTime = System.currentTimeMillis()
|
||||
val timeDifference = viewModel.calculateTimeElapsed()
|
||||
if (viewModel.hasUserReturned && timeDifference > 0L) {
|
||||
viewModel.timerData?.let { timerData ->
|
||||
timerData.timerInvalidateAfter?.let { timerInvalidateAfter ->
|
||||
if (timerInvalidateAfter > timeDifference) {
|
||||
timerData.timerInvalidateAfter = timerInvalidateAfter - timeDifference
|
||||
setSettlementContainerTimer(timerData)
|
||||
} else if (viewModel.exitTime != 0L) {
|
||||
fetchData(genericTimer.isInitialised())
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
viewModel.hasUserReturned = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
genericTimer.stopTimer()
|
||||
viewModel.exitTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
override fun setContainerView(viewStub: ViewStub) {
|
||||
@@ -117,6 +137,7 @@ class FundSellFragment : AmcBaseFragment() {
|
||||
showWhenDataIsAvailable(item.iconCode)
|
||||
this.setOnClickListener { showBottomSheet(item.actionData) }
|
||||
}
|
||||
viewModel.updateTimerData(item)
|
||||
setSettlementContainerTimer(item)
|
||||
}
|
||||
handleVisibility(viewModel.isAmountSelected)
|
||||
|
||||
@@ -10,6 +10,7 @@ package com.navi.amc.redemption.viewmodel
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.navi.amc.fundbuy.models.SubItemData
|
||||
import com.navi.amc.redemption.model.FundSellScreenResponse
|
||||
import com.navi.amc.redemption.model.RedemptionOrderDetails
|
||||
import com.navi.amc.redemption.repository.FundSellRepository
|
||||
@@ -29,6 +30,11 @@ class FundSellViewModel @Inject constructor(private val repository: FundSellRepo
|
||||
|
||||
var approxValue: String? = null
|
||||
|
||||
var hasUserReturned: Boolean = false
|
||||
var exitTime: Long = 0L
|
||||
var entryTime: Long = 0L
|
||||
var timerData: SubItemData? = null
|
||||
|
||||
private val _fundSellScreenData = MutableLiveData<FundSellScreenResponse?>()
|
||||
val fundSellScreenData: LiveData<FundSellScreenResponse?>
|
||||
get() = _fundSellScreenData
|
||||
@@ -116,6 +122,14 @@ class FundSellViewModel @Inject constructor(private val repository: FundSellRepo
|
||||
}
|
||||
}
|
||||
|
||||
fun updateTimerData(timerData: SubItemData) {
|
||||
this.timerData = timerData
|
||||
}
|
||||
|
||||
fun calculateTimeElapsed(): Long {
|
||||
return (entryTime - exitTime)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
_fundSellScreenData.value = null
|
||||
_redeemOrderDetails.value = null
|
||||
|
||||
@@ -133,8 +133,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_16"
|
||||
android:layout_marginEnd="@dimen/dp_16"
|
||||
android:paddingTop="@dimen/dp_24"
|
||||
android:paddingBottom="@dimen/dp_24"
|
||||
android:paddingTop="@dimen/_16dp"
|
||||
android:paddingBottom="@dimen/_16dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
Reference in New Issue
Block a user