diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/common/model/config/NaviPayDefaultConfig.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/common/model/config/NaviPayDefaultConfig.kt index 3be50147c5..2c60bb32ee 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/common/model/config/NaviPayDefaultConfig.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/common/model/config/NaviPayDefaultConfig.kt @@ -80,7 +80,7 @@ data class DefaultConfigContent( @SerializedName("frequentTransactionMaxColumns") val frequentTransactionsMaxColumns: Int = 4, @SerializedName("frequentTransactionTotalEntries") val frequentTransactionsTotalEntries: Int = 12, - @SerializedName("frequentTransactionDays") val frequentTransactionsDays: Int = 60, + @SerializedName("frequentTransactionDays") val frequentTransactionsDays: Int = 180, @SerializedName("frequentTransactionHeading") val frequentTransactionHeading: String = "Pay again", @SerializedName("upiAppLogoS3BaseUrl") diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/management/paytocontacts/viewmodel/PayToContactsViewModel.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/management/paytocontacts/viewmodel/PayToContactsViewModel.kt index a26ca693e1..a7d047bba3 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/management/paytocontacts/viewmodel/PayToContactsViewModel.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/management/paytocontacts/viewmodel/PayToContactsViewModel.kt @@ -58,6 +58,7 @@ import javax.inject.Inject import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -244,70 +245,78 @@ constructor( ) init { - updateNaviPaySessionId() - updateNaviPayDefaultConfig() - fetchFrequentOrders() - observeAndHandleSearchResults() + viewModelScope.launch(context = Dispatchers.IO) { + initializeSynchronously() + initializeAsynchronously() + } } - private fun observeAndHandleSearchResults() { - viewModelScope.launch(Dispatchers.IO) { - combine(searchQuery, filteredContactList, filteredFrequentOrdersList) { - searchQuery, - filteredContactList, - filteredFrequentOrdersList -> - Triple(searchQuery, filteredContactList, filteredFrequentOrdersList) - } - .collectLatest { (searchQuery, filteredContactList, filteredFrequentOrdersList) -> - updateShouldShowYourContactsTitle() - updateIsWarningOrErrorState( - isError = false, - isWarning = - filteredContactList.isEmpty() && - filteredFrequentOrdersList.isEmpty() && - searchQuery.removeSpaces().isValidSearchQuery() && - searchQuery.removeSpaces().isValidPhoneNumberLength().not(), - warningMessage = - resourceProvider.getString(R.string.np_please_enter_valid_number), - ) + private suspend fun initializeSynchronously() { + updateNaviPayDefaultConfig() + } - _isNewContactVisible.update { + private suspend fun initializeAsynchronously() { + coroutineScope { + launch { updateNaviPaySessionId() } + launch { fetchFrequentOrders() } + launch { observeAndHandleSearchResults() } + } + } + + private suspend fun observeAndHandleSearchResults() { + combine(searchQuery, filteredContactList, filteredFrequentOrdersList) { + searchQuery, + filteredContactList, + filteredFrequentOrdersList -> + Triple(searchQuery, filteredContactList, filteredFrequentOrdersList) + } + .collectLatest { (searchQuery, filteredContactList, filteredFrequentOrdersList) -> + updateShouldShowYourContactsTitle() + updateIsWarningOrErrorState( + isError = false, + isWarning = filteredContactList.isEmpty() && filteredFrequentOrdersList.isEmpty() && searchQuery.removeSpaces().isValidSearchQuery() && - searchQuery.removeSpaces().isValidPhoneNumberLength() - } + searchQuery.removeSpaces().isValidPhoneNumberLength().not(), + warningMessage = + resourceProvider.getString(R.string.np_please_enter_valid_number), + ) - if (isNewContactVisible.value) { - updateShimmerState(showShimmer = true) - updateNewContact(newContactEntity = null) - fetchNewContactDetails(searchQuery) - } else { - updateShimmerState(showShimmer = false) - } + _isNewContactVisible.update { + filteredContactList.isEmpty() && + filteredFrequentOrdersList.isEmpty() && + searchQuery.removeSpaces().isValidSearchQuery() && + searchQuery.removeSpaces().isValidPhoneNumberLength() } - } + + if (isNewContactVisible.value) { + updateShimmerState(showShimmer = true) + updateNewContact(newContactEntity = null) + fetchNewContactDetails(searchQuery) + } else { + updateShimmerState(showShimmer = false) + } + } } - private fun updateNaviPayDefaultConfig() { - viewModelScope.launch(Dispatchers.IO) { - naviPayDefaultConfig = - naviPayConfigUseCase.execute( - configKey = DEFAULT_CONFIG, - type = object : TypeToken() {}.type, - screenName = screenName, - ) ?: NaviPayDefaultConfig() + private suspend fun updateNaviPayDefaultConfig() { + naviPayDefaultConfig = + naviPayConfigUseCase.execute( + configKey = DEFAULT_CONFIG, + type = object : TypeToken() {}.type, + screenName = screenName, + ) ?: NaviPayDefaultConfig() - updateFrequentOrderTotalEntries( - naviPayDefaultConfig.config.frequentTransactionsTotalEntries - ) - updateFrequentOrderDays(naviPayDefaultConfig.config.frequentTransactionsDays) - updateFrequentOrderHeading(naviPayDefaultConfig.config.frequentTransactionHeading) - } + updateFrequentOrderTotalEntries( + naviPayDefaultConfig.config.frequentTransactionsTotalEntries + ) + updateFrequentOrderDays(naviPayDefaultConfig.config.frequentTransactionsDays) + updateFrequentOrderHeading(naviPayDefaultConfig.config.frequentTransactionHeading) } - private fun updateNaviPaySessionId() { - viewModelScope.launch(Dispatchers.IO) { naviPaySessionHelper.createNewSessionId() } + private suspend fun updateNaviPaySessionId() { + naviPaySessionHelper.createNewSessionId() } fun getNaviPaySessionAttributes(): Map { @@ -332,7 +341,7 @@ constructor( } } - fun updateUiState(uiState: PayToContactsUIState) { + private fun updateUiState(uiState: PayToContactsUIState) { _uiState.update { uiState } } @@ -582,16 +591,20 @@ constructor( updateSearchQueryStringState(searchQuery = EMPTY) } - private fun fetchFrequentOrders() { - viewModelScope.launch(Dispatchers.IO) { - val getFrequentOrderList = - frequentOrdersHelper.getFrequentOrderList( - frequentOrdersTotalEntries = frequentOrdersTotalEntries.value, - frequentOrdersDays = frequentOrdersDays.value, - ) - updateFrequentOrderEntityList(getFrequentOrderList) - updateUiState(uiState = PayToContactsUIState.Loaded) - } + private suspend fun fetchFrequentOrders() { + val getFrequentOrderList = + frequentOrdersHelper.getFrequentOrderList( + frequentOrdersTotalEntries = frequentOrdersTotalEntries.value, + frequentOrdersDays = frequentOrdersDays.value, + ) + updateFrequentOrderEntityList(getFrequentOrderList) + naviPayAnalytics.onSendToContactsLoaded( + naviPaySessionAttributes = getNaviPaySessionAttributes(), + isPermissionGranted = true, + isContactListEmpty = allContactList.value.isEmpty(), + isFrequentOrderListEmpty = frequentOrders.value.isEmpty(), + ) + updateUiState(uiState = PayToContactsUIState.Loaded) } fun fetchContacts() { @@ -599,12 +612,6 @@ constructor( val savedContactListJob = async { contactManager.getPhoneContacts() } allContactList.update { savedContactListJob.await() } _isSavedContactListNonEmpty.update { allContactList.value.isNotEmpty() } - naviPayAnalytics.onSendToContactsLoaded( - naviPaySessionAttributes = getNaviPaySessionAttributes(), - isPermissionGranted = true, - isContactListEmpty = allContactList.value.isEmpty(), - isFrequentOrderListEmpty = frequentOrders.value.isEmpty(), - ) } }