NTP-4542 | SIP Autopay nudge fixes (#13064)

Co-authored-by: Aman S <aman.s@navi.com>
This commit is contained in:
Varun Jain
2024-10-15 20:32:05 +05:30
committed by GitHub
parent 29951f46de
commit a4e0c45755
7 changed files with 59 additions and 27 deletions

View File

@@ -10,6 +10,7 @@ package com.naviapp.home.common.hopperProcessor.processHandlerImpl
import androidx.activity.ComponentActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import com.navi.amc.common.viewmodel.CheckerVM
import com.navi.amc.fundbuy.viewmodel.FundListViewModel
import com.navi.amc.kyc.viewmodel.BankDetailsVM
@@ -29,6 +30,8 @@ import com.navi.amc.utils.Constant.SIP_REFERENCE_ID
import com.navi.analytics.utils.NaviTrackEvent
import com.navi.base.model.CtaData
import com.navi.common.utils.Constants.CTAData
import com.navi.common.utils.Constants.HOPPER_API_RESPONSE_NOT_RECEIVED
import com.navi.common.utils.Constants.HOPPER_API_TIMEOUT
import com.navi.common.utils.Constants.HOPPER_PROCESS_ADD_IN_CACHE_FAILURE
import com.navi.common.utils.Constants.HOPPER_PROCESS_ADD_IN_CACHE_SUCCESS
import com.navi.common.utils.Constants.HOPPER_PROCESS_FETCH_AND_CACHE_DATA_START
@@ -39,6 +42,7 @@ import com.naviapp.utils.Constants.KYC_JOURNEY
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
@@ -166,10 +170,22 @@ class HopperHelper {
activity: ComponentActivity,
ctaData: CtaData,
liveData: LiveData<*>,
onResult: (Boolean) -> Unit
onResult: (Boolean) -> Unit,
timeoutMillis: Long = HOPPER_API_TIMEOUT
) {
var responseReceived = false
val job =
activity.lifecycleScope.launch {
delay(timeoutMillis)
if (!responseReceived) {
NaviTrackEvent.trackEvent(eventName = HOPPER_API_RESPONSE_NOT_RECEIVED)
onResult(false)
}
}
liveData.observeNullable(activity) { response ->
responseReceived = true
liveData.removeObservers(activity)
job.cancel()
handleResponse(ctaData, response, onResult)
}
}

View File

@@ -37,6 +37,7 @@ import com.naviapp.home.model.HpBottomSheetState
import com.naviapp.home.model.InvestmentBottomSheetData
import com.naviapp.home.viewmodel.SharedVM
import com.naviapp.utils.Constants
import com.naviapp.utils.Constants.AUTOPAY_NUDGE_BOTTOMSHEET
import com.naviapp.utils.Constants.INVESTMENT_TAB_BOTTOM_NUDGE_COLOR
import com.naviapp.utils.Constants.INVESTMENT_TAB_BOTTOM_NUDGE_ICON
import com.naviapp.utils.Constants.INVESTMENT_TAB_BOTTOM_NUDGE_TITLE
@@ -82,7 +83,8 @@ class InvestmentsScreenHelper {
activity: HomePageActivity,
sharedVM: SharedVM,
bottomSheetData: BottomSheetData? = null,
index: Int = 0
index: Int = 0,
investmentsTabVm: InvestmentsVm
) {
actionData?.metaData?.clickedData?.apply {
if (parameters == null) {
@@ -124,27 +126,26 @@ class InvestmentsScreenHelper {
activity = activity,
ctaData = it,
onResult = { ctaData ->
val bundle = Bundle()
bundle.putParcelable(
CAPS_DATA,
bottomSheetData?.nextCtaResponse?.statusData
)
buttonState?.value = FooterButtonState.ENABLED
sharedVM.updateBottomSheetState(
state = HpBottomSheetState.Hidden
)
ctaData?.let {
bottomSheetData
?.nextCtaResponse
?.nextCTA
?.let { actionData ->
when (investmentsTabVm.bottomSheetType) {
AUTOPAY_NUDGE_BOTTOMSHEET -> {
handleAutoPayNudgeBottomSheetData(
bottomSheetData,
ctaData,
activity
)
}
else -> {
ctaData?.let { ctaData ->
navigateTo(
ctaData =
actionData.toCtaData(),
activity = activity,
bundle = bundle
ctaData = ctaData,
activity = activity
)
}
}
}
}
)
@@ -212,4 +213,19 @@ class InvestmentsScreenHelper {
onClick(actionData)
}
}
private fun handleAutoPayNudgeBottomSheetData(
bottomSheetData: BottomSheetData?,
ctaData: CtaData?,
activity: HomePageActivity
) {
val bundle = Bundle()
bundle.putParcelable(CAPS_DATA, bottomSheetData?.nextCtaResponse?.statusData)
ctaData?.let {
bottomSheetData?.nextCtaResponse?.nextCTA?.let { actionData ->
navigateTo(ctaData = actionData.toCtaData(), activity = activity, bundle = bundle)
}
}
}
}

View File

@@ -127,7 +127,8 @@ fun InvestmentsTab(
activity,
sharedVM,
investmentsTabVm.getBottomSheetData(actionData?.type),
index
index,
investmentsTabVm
)
},
onVisible = { genericAnalytics ->
@@ -154,7 +155,8 @@ fun InvestmentsTab(
investmentsTabVm.getBottomSheetData(
actionData?.type
),
index
index,
investmentsTabVm
)
}
)
@@ -173,7 +175,8 @@ fun InvestmentsTab(
actionData?.toActionData(),
activity,
sharedVM,
investmentsTabVm.getBottomSheetData(actionData?.type)
investmentsTabVm.getBottomSheetData(actionData?.type),
investmentsTabVm = investmentsTabVm
)
}
)

View File

@@ -95,9 +95,7 @@ constructor(
get() = _cutOffFormattedTitle
var cutOffTimerCompositionCount = 0
private val _bottomSheetType = MutableSharedFlow<String?>(replay = 1)
val bottomSheetType: SharedFlow<String?> = _bottomSheetType
var bottomSheetType: String? = null
private val bottomSheetDataFromType: MutableMap<String, BottomSheetData> = mutableMapOf()
@@ -302,11 +300,8 @@ constructor(
return cacheResponse
}
fun setBottomSheetType(bottomSheetType: String?) {
viewModelScope.safeLaunch(Dispatchers.IO) { _bottomSheetType.emit(bottomSheetType) }
}
fun setBottomSheetData(bottomSheetType: String?, bottomSheetData: BottomSheetData) {
this.bottomSheetType = bottomSheetType
bottomSheetType?.let { bottomSheetDataFromType[it] = bottomSheetData }
}

View File

@@ -467,6 +467,7 @@ object Constants {
const val INVESTMENT_TAB_BOTTOM_NUDGE_COLOR = "#E9E7F0"
const val INVESTMENT_TAB_BOTTOM_NUDGE_ICON =
"https://amc-public-assets.s3.ap-south-1.amazonaws.com/investment-tab/investment_tab_bottom_bar_image.png"
const val AUTOPAY_NUDGE_BOTTOMSHEET = "AUTOPAY_NUDGE_BOTTOMSHEET"
// TODO: Remove these constants once delayed onboarding goes 100%
const val CHECK_BALANCE_ROW = "checkBalanceRow"

View File

@@ -1537,7 +1537,6 @@ class FundBuyingFragmentV2 : AmcBaseFragment(), WidgetCallback {
if (frequency == Constant.MONTHLY) {
viewModel.toHideDate = false
binding.date.visibility = View.VISIBLE
binding.container.post { binding.container.fullScroll(View.FOCUS_DOWN) }
} else {
viewModel.toHideDate = true
binding.date.visibility = View.GONE

View File

@@ -275,6 +275,8 @@ object Constants {
/*Hooper CONSTANTS*/
const val HOPPER = "HOPPER"
const val HOPPER_THRESHOLD_FOR_NEW_JOB = 2000
const val HOPPER_API_TIMEOUT = 3000L
const val HOPPER_API_RESPONSE_NOT_RECEIVED = "HOPPER_API_RESPONSE_NOT_RECEIVED"
const val HOPPER_PROCESS_ON_START = "hopper_process_on_start"
const val HOPPER_PROCESS_ON_EXECUTE = "hopper_process_on_execute"
const val HOPPER_PROCESS_JOB_CANCELLED_CALLED = "hopper_process_job_cancelled_called"