NTP-12939 | Order history monthly summary engine (#13644)
This commit is contained in:
@@ -4891,6 +4891,10 @@ class NaviPayAnalytics private constructor() {
|
||||
fun onSendMoneyCtaClicked() {
|
||||
NaviTrackEvent.trackEventOnClickStream("NaviTStore_ViewOrderHistory_SendMoney_Clicked")
|
||||
}
|
||||
|
||||
fun onOrderTagSummaryEnabled() {
|
||||
NaviTrackEvent.trackEventOnClickStream("NaviTStore_OrderTagSummary_Enabled")
|
||||
}
|
||||
}
|
||||
|
||||
inner class OrderDetails {
|
||||
|
||||
@@ -26,8 +26,11 @@ import com.navi.pay.management.upinumber.list.model.view.UpiNumberEntity
|
||||
import com.navi.pay.management.upinumber.list.util.UpiNumberStatusConverter
|
||||
import com.navi.pay.onboarding.account.add.dao.BankDao
|
||||
import com.navi.pay.onboarding.account.add.model.view.BankEntity
|
||||
import com.navi.pay.tstore.list.db.dao.OrderTagSummaryDao
|
||||
import com.navi.pay.tstore.list.model.view.OrderTagSummaryEntity
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_BANK_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_BANK_UPTIME_TABLE
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_SYNC_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_UPI_NUMBERS_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_VPA_TRANSACTION_INSIGHTS_TABLE_NAME
|
||||
@@ -41,7 +44,8 @@ import com.navi.pay.utils.NAVI_PAY_SYNC_TABLE_TRANSACTION_HISTORY_KEY
|
||||
SyncEntity::class,
|
||||
BankUptimeEntity::class,
|
||||
UpiNumberEntity::class,
|
||||
VpaTransactionsInsightEntity::class
|
||||
VpaTransactionsInsightEntity::class,
|
||||
OrderTagSummaryEntity::class
|
||||
],
|
||||
version = 11,
|
||||
exportSchema = false
|
||||
@@ -62,6 +66,8 @@ abstract class NaviPayAppDatabase : RoomDatabase() {
|
||||
abstract fun upiNumbersDao(): UpiNumbersDao
|
||||
|
||||
abstract fun vpaTransactionInsightsDao(): VpaTransactionInsightsDao
|
||||
|
||||
abstract fun orderTagSummaryDao(): OrderTagSummaryDao
|
||||
}
|
||||
|
||||
val NAVI_PAY_APP_DATABASE_MIGRATION_1_2 =
|
||||
@@ -173,5 +179,10 @@ val NAVI_PAY_APP_DATABASE_MIGRATION_10_11 =
|
||||
database.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS $NAVI_PAY_DATABASE_VPA_TRANSACTION_INSIGHTS_TABLE_NAME (`vpa` TEXT PRIMARY KEY NOT NULL, `vpaInfo` TEXT NOT NULL, `vpaTransactionsInfo` TEXT NOT NULL, `updatedAt` INTEGER NOT NULL)"
|
||||
)
|
||||
|
||||
// Migration to add OrderSummaryEntity table
|
||||
database.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS $NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME (`tag` TEXT PRIMARY KEY NOT NULL, `count` INTEGER NOT NULL, `amount` TEXT NOT NULL, `updatedAt` INTEGER NOT NULL)"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.navi.pay.db.NaviPayAppEncryptedDatabase
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_ACCOUNTS_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_BANK_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_BANK_UPTIME_TABLE
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_SAVED_BENEFICIARY_TABLE
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_SYNC_TABLE_NAME
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_TRANSACTION_HISTORY_TABLE_NAME
|
||||
@@ -49,6 +50,8 @@ constructor(
|
||||
naviPayAppDatabase.upiNumbersDao().deleteAll()
|
||||
NAVI_PAY_DATABASE_VPA_TRANSACTION_INSIGHTS_TABLE_NAME ->
|
||||
naviPayAppDatabase.vpaTransactionInsightsDao().deleteAll()
|
||||
NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME ->
|
||||
naviPayAppDatabase.orderTagSummaryDao().deleteAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +252,11 @@ object NaviPayNetworkModule {
|
||||
@Provides
|
||||
fun providesVpaTransactionInsightsDao(naviPayAppDatabase: NaviPayAppDatabase) =
|
||||
naviPayAppDatabase.vpaTransactionInsightsDao()
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun providesOrderTagSummaryDao(naviPayAppDatabase: NaviPayAppDatabase) =
|
||||
naviPayAppDatabase.orderTagSummaryDao()
|
||||
}
|
||||
|
||||
@Module
|
||||
|
||||
@@ -36,7 +36,7 @@ interface OrderDao {
|
||||
@Query(
|
||||
"SELECT " +
|
||||
"orderReferenceId, amount, currency, orderTitle, orderDescription, orderStatusOfView, orderTimestamp, orderImageUrl, " +
|
||||
"categoryTags, paymentModeTags, productType, productId, orderType, ownBankInfo, monthTag, coinEquivalentCash, orderDetails " +
|
||||
"categoryTags, paymentModeTags, productType, productId, paymentStatus, orderType, ownBankInfo, monthTag, coinEquivalentCash, orderDetails " +
|
||||
"FROM $NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME " +
|
||||
"ORDER BY orderTimestamp DESC"
|
||||
)
|
||||
@@ -46,7 +46,7 @@ interface OrderDao {
|
||||
@Query(
|
||||
"SELECT " +
|
||||
"orderReferenceId, amount, currency, orderTitle, orderDescription, orderStatusOfView, orderTimestamp, orderImageUrl, " +
|
||||
"categoryTags, paymentModeTags, productType, productId, orderType, ownBankInfo, monthTag, coinEquivalentCash " +
|
||||
"categoryTags, paymentModeTags, productType, productId, paymentStatus, orderType, ownBankInfo, monthTag, coinEquivalentCash " +
|
||||
"FROM $NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME " +
|
||||
"WHERE orderTitle like :searchQuery OR orderDescription like :searchQuery OR amount like :searchQuery OR otherUserInfo like :searchQuery " +
|
||||
"ORDER BY orderTimestamp DESC"
|
||||
@@ -64,7 +64,7 @@ interface OrderDao {
|
||||
@Query(
|
||||
"SELECT " +
|
||||
"orderReferenceId, amount, currency, orderTitle, orderDescription, orderStatusOfView, orderTimestamp, orderImageUrl, " +
|
||||
"categoryTags, paymentModeTags, productType, productId, orderType, ownBankInfo, monthTag, coinEquivalentCash " +
|
||||
"categoryTags, paymentModeTags, productType, productId, paymentStatus, orderType, ownBankInfo, monthTag, coinEquivalentCash " +
|
||||
"FROM $NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME " +
|
||||
"WHERE productId = :umn " +
|
||||
"ORDER BY orderTimestamp DESC"
|
||||
@@ -88,4 +88,18 @@ interface OrderDao {
|
||||
"ORDER BY orderTimestamp DESC"
|
||||
)
|
||||
suspend fun findAllOrderEntityByOrderTimeStampGreaterThan(dateTime: DateTime): List<OrderEntity>
|
||||
|
||||
@Query(
|
||||
"SELECT " +
|
||||
"orderReferenceId, amount, currency, orderTitle, orderDescription, orderStatusOfView, orderTimestamp, orderImageUrl, " +
|
||||
"categoryTags, paymentModeTags, productType, productId, paymentStatus, orderType, ownBankInfo, monthTag, coinEquivalentCash " +
|
||||
"FROM $NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME " +
|
||||
"WHERE orderTimestamp >= :minDateTime AND orderTimestamp <= :maxDateTime " +
|
||||
"AND monthTag in (:monthTagList) "
|
||||
)
|
||||
suspend fun getAllOrderHistoryByMonthTagInWithMaxAndMinTimestamp(
|
||||
monthTagList: List<String>,
|
||||
minDateTime: DateTime,
|
||||
maxDateTime: DateTime
|
||||
): List<OrderHistoryEntity>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.pay.tstore.list.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import androidx.room.Upsert
|
||||
import com.navi.pay.tstore.list.model.view.OrderTagSummaryEntity
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface OrderTagSummaryDao {
|
||||
|
||||
@Upsert suspend fun insertAll(orderTagSummaryEntityList: List<OrderTagSummaryEntity>)
|
||||
|
||||
@Query("SELECT * FROM $NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME")
|
||||
fun getAll(): Flow<List<OrderTagSummaryEntity>>
|
||||
|
||||
@Query("DELETE FROM $NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME") suspend fun deleteAll()
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import com.navi.base.utils.NaviDateFormatter
|
||||
import com.navi.base.utils.isNotNullAndNotEmpty
|
||||
import com.navi.pay.management.common.transaction.model.view.TransactionPaymentModeTags
|
||||
import com.navi.pay.management.common.transaction.util.getOwnBankIconUrlFromOwnBankInfo
|
||||
import com.navi.pay.tstore.details.model.view.OrderPaymentStatus
|
||||
import com.navi.pay.tstore.list.model.network.OrderType
|
||||
import com.navi.pay.utils.NAVI_PAY_SELF_TRANSFER_LOGO_URL
|
||||
import com.navi.pay.utils.NAVI_PAY_UPI_LITE_LOGO_URL
|
||||
@@ -31,6 +32,7 @@ data class OrderHistoryEntity(
|
||||
val orderDescription: String,
|
||||
val orderImageUrl: String,
|
||||
val orderStatusOfView: OrderStatusOfView,
|
||||
val paymentStatus: OrderPaymentStatus,
|
||||
val orderTimestamp: DateTime,
|
||||
val categoryTags: String,
|
||||
val paymentModeTags: String,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.pay.tstore.list.model.view
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME
|
||||
|
||||
@Entity(tableName = NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME)
|
||||
data class OrderTagSummaryEntity(
|
||||
@PrimaryKey @ColumnInfo(name = "tag") val tag: String,
|
||||
@ColumnInfo("count") val count: Int,
|
||||
@ColumnInfo("amount") val amount: String,
|
||||
@ColumnInfo("updatedAt") val updatedAt: Long = System.currentTimeMillis()
|
||||
)
|
||||
@@ -18,13 +18,16 @@ import com.navi.pay.common.butler.dao.VpaTransactionInsightsDao
|
||||
import com.navi.pay.common.butler.model.view.VpaTransactionInfo
|
||||
import com.navi.pay.common.butler.model.view.VpaTransactionsInsightEntity
|
||||
import com.navi.pay.network.retrofit.NaviPayRetrofitService
|
||||
import com.navi.pay.tstore.details.model.view.OrderPaymentStatus
|
||||
import com.navi.pay.tstore.list.db.dao.OrderDao
|
||||
import com.navi.pay.tstore.list.db.dao.OrderTagSummaryDao
|
||||
import com.navi.pay.tstore.list.model.network.OrderHistoryRequest
|
||||
import com.navi.pay.tstore.list.model.network.OrderHistoryResponse
|
||||
import com.navi.pay.tstore.list.model.view.OrderEntity
|
||||
import com.navi.pay.tstore.list.model.view.OrderHistoryEntity
|
||||
import com.navi.pay.tstore.list.model.view.OrderHistorySearchHolder
|
||||
import com.navi.pay.tstore.list.model.view.OrderStatusOfView
|
||||
import com.navi.pay.tstore.list.model.view.OrderTagSummaryEntity
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.orEmpty
|
||||
@@ -43,7 +46,8 @@ class OrderRepository
|
||||
constructor(
|
||||
private val naviPayRetrofitService: NaviPayRetrofitService,
|
||||
private val orderDao: OrderDao,
|
||||
private val vpaTransactionInsightsDao: VpaTransactionInsightsDao
|
||||
private val vpaTransactionInsightsDao: VpaTransactionInsightsDao,
|
||||
private val orderTagSummaryDao: OrderTagSummaryDao
|
||||
) : ResponseCallback() {
|
||||
|
||||
suspend fun getOrderHistoryFromNetwork(
|
||||
@@ -78,6 +82,11 @@ constructor(
|
||||
)
|
||||
}
|
||||
)
|
||||
taskList.add(
|
||||
async {
|
||||
processOrderEntityListForOrderTagSummaryTable(orderEntityList = orderEntityList)
|
||||
}
|
||||
)
|
||||
taskList.awaitAll()
|
||||
}
|
||||
|
||||
@@ -113,7 +122,7 @@ constructor(
|
||||
val selectQuery =
|
||||
"SELECT " +
|
||||
"orderReferenceId, amount, currency, orderTitle, orderDescription, orderStatusOfView, orderTimestamp, orderImageUrl, " +
|
||||
"categoryTags, paymentModeTags, productType, orderType, ownBankInfo, monthTag, coinEquivalentCash " +
|
||||
"categoryTags, paymentModeTags, productType, productId, paymentStatus, orderType, ownBankInfo, monthTag, coinEquivalentCash " +
|
||||
"FROM $NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME "
|
||||
|
||||
val whereClauseWithSearchQuery =
|
||||
@@ -371,4 +380,63 @@ constructor(
|
||||
|
||||
return newFilteredOrderEntityListGroupedByVpa
|
||||
}
|
||||
|
||||
private suspend fun processOrderEntityListForOrderTagSummaryTable(
|
||||
orderEntityList: List<OrderEntity>
|
||||
) {
|
||||
val affectedMonthTagList = orderEntityList.map { it.monthTag }.distinct()
|
||||
|
||||
// To optimise affected monthTag query, we find min & max timestamp of affected monthTags
|
||||
val affectedMonthTagStartOfMonthAsDateTime =
|
||||
affectedMonthTagList.map {
|
||||
val year = it.take(4).toInt()
|
||||
val month = it.substring(4).toInt()
|
||||
DateTime(year, month, 1, 0, 0).withZone(DateTimeZone.UTC)
|
||||
}
|
||||
|
||||
// To offset for UTC, we substract 1 day from min timestamp
|
||||
val minMonthDateTime = affectedMonthTagStartOfMonthAsDateTime.min()
|
||||
val offsetMinMonthDateTime = minMonthDateTime.minusDays(1)
|
||||
|
||||
// To offset for UTC, we add 1 month and 1 day from max timestamp
|
||||
val maxMonthDateTime = affectedMonthTagStartOfMonthAsDateTime.max()
|
||||
val offsetMaxMonthDateTime = maxMonthDateTime.plusMonths(1).plusDays(1)
|
||||
|
||||
val orderHistoryListForAffectedMonthTag =
|
||||
orderDao.getAllOrderHistoryByMonthTagInWithMaxAndMinTimestamp(
|
||||
monthTagList = affectedMonthTagList,
|
||||
minDateTime = offsetMinMonthDateTime,
|
||||
maxDateTime = offsetMaxMonthDateTime
|
||||
)
|
||||
|
||||
val monthTagAmountCountPairMap =
|
||||
orderHistoryListForAffectedMonthTag
|
||||
.filter {
|
||||
it.orderStatusOfView == OrderStatusOfView.Debit &&
|
||||
it.paymentStatus != OrderPaymentStatus.REFUNDED
|
||||
}
|
||||
.groupBy { it.monthTag }
|
||||
.mapValues { (_, monthTagOrders) ->
|
||||
val netAmount = monthTagOrders.sumOf { it.amount.toDoubleOrNull() ?: 0.00 }
|
||||
val totalOrderCount = monthTagOrders.size
|
||||
Pair(netAmount, totalOrderCount)
|
||||
}
|
||||
|
||||
val orderTagSummaryEntityList =
|
||||
monthTagAmountCountPairMap.map { (monthTag, amountCountMap) ->
|
||||
OrderTagSummaryEntity(
|
||||
tag = monthTag,
|
||||
amount = amountCountMap.first.toString(),
|
||||
count = amountCountMap.second
|
||||
)
|
||||
}
|
||||
|
||||
insertAll(orderTagSummaryEntityList = orderTagSummaryEntityList)
|
||||
}
|
||||
|
||||
suspend fun insertAll(orderTagSummaryEntityList: List<OrderTagSummaryEntity>) {
|
||||
orderTagSummaryDao.insertAll(orderTagSummaryEntityList)
|
||||
}
|
||||
|
||||
fun getAllOrderSummary() = orderTagSummaryDao.getAll()
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ import com.navi.pay.utils.AT_THE_RATE_CHAR
|
||||
import com.navi.pay.utils.DATE_TIME_FORMAT_MONTH_YEAR_WITH_SPACE_SEPARATOR
|
||||
import com.navi.pay.utils.DOT_PNG
|
||||
import com.navi.pay.utils.HYPHEN
|
||||
import com.navi.pay.utils.RUPEE_SYMBOL
|
||||
import com.navi.pay.utils.clickableDebounce
|
||||
import com.navi.pay.utils.conditional
|
||||
import com.navi.pay.utils.contactInitials
|
||||
@@ -137,6 +138,8 @@ fun OrderHistoryScreen(
|
||||
orderHistoryViewModel.upiAppLogoS3BaseUrl.collectAsStateWithLifecycle()
|
||||
val upiAppsIconList by orderHistoryViewModel.upiAppsIconList.collectAsStateWithLifecycle()
|
||||
val coinsSavedMessage by orderHistoryViewModel.coinsSavedMessage.collectAsStateWithLifecycle()
|
||||
val orderSummaryAmountMapData by
|
||||
orderHistoryViewModel.orderSummaryAmountMap.collectAsStateWithLifecycle()
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val view = LocalView.current
|
||||
val context = LocalContext.current
|
||||
@@ -414,7 +417,12 @@ fun OrderHistoryScreen(
|
||||
DATE_TIME_FORMAT_MONTH_YEAR_WITH_SPACE_SEPARATOR
|
||||
)
|
||||
if (index == 0) {
|
||||
NewMonthView(date = currentMonthYearDateAsString)
|
||||
NewMonthView(
|
||||
date = currentMonthYearDateAsString,
|
||||
amount =
|
||||
orderSummaryAmountMapData[
|
||||
transactionHistoryItem.monthTag]
|
||||
)
|
||||
} else {
|
||||
val previousMonthYearDateAsString =
|
||||
DateUtils
|
||||
@@ -433,7 +441,10 @@ fun OrderHistoryScreen(
|
||||
currentMonthYearDateAsString
|
||||
) {
|
||||
NewMonthView(
|
||||
date = currentMonthYearDateAsString
|
||||
date = currentMonthYearDateAsString,
|
||||
amount =
|
||||
orderSummaryAmountMapData[
|
||||
transactionHistoryItem.monthTag]
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -576,16 +587,34 @@ private fun TagCardItem(isSelected: Boolean, onClick: () -> Unit, text: String)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NewMonthView(date: String) {
|
||||
NaviText(
|
||||
text = date,
|
||||
fontFamily = ttComposeFontFamily,
|
||||
fontWeight = getFontWeight(FontWeightEnum.NAVI_HEADLINE_REGULAR),
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier.fillMaxWidth().padding(start = 16.dp, top = 8.dp),
|
||||
color = NaviPayColor.textPrimary
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
fun NewMonthView(date: String, amount: String?) {
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.background(NaviPayColor.bgNonEditable)
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
NaviText(
|
||||
text = date,
|
||||
fontFamily = ttComposeFontFamily,
|
||||
fontWeight = getFontWeight(FontWeightEnum.NAVI_BODY_DEMI_BOLD),
|
||||
fontSize = 14.sp,
|
||||
lineHeight = 22.sp,
|
||||
color = NaviPayColor.textPrimary
|
||||
)
|
||||
|
||||
NaviText(
|
||||
text = if (amount != null) "$RUPEE_SYMBOL$amount" else "",
|
||||
fontFamily = ttComposeFontFamily,
|
||||
fontWeight = getFontWeight(FontWeightEnum.NAVI_BODY_DEMI_BOLD),
|
||||
fontSize = 14.sp,
|
||||
lineHeight = 22.sp,
|
||||
color = NaviPayColor.textPrimary
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.gson.reflect.TypeToken
|
||||
import com.navi.base.utils.DateUtils
|
||||
import com.navi.base.utils.EMPTY
|
||||
import com.navi.base.utils.ResourceProvider
|
||||
import com.navi.common.usecase.LitmusExperimentsUseCase
|
||||
import com.navi.pay.R
|
||||
import com.navi.pay.analytics.NaviPayAnalytics
|
||||
import com.navi.pay.analytics.NaviPayAnalytics.Companion.NAVI_PAY_T_STORE_ORDER_LIST
|
||||
@@ -45,7 +46,9 @@ import com.navi.pay.tstore.list.repository.OrderRepository
|
||||
import com.navi.pay.tstore.list.usecase.SyncOrderHistoryUseCase
|
||||
import com.navi.pay.utils.DATE_TIME_FORMAT_MONTH_YEAR_WITH_COMMA_SEPARATOR
|
||||
import com.navi.pay.utils.DEFAULT_CONFIG
|
||||
import com.navi.pay.utils.LITMUS_EXPERIMENT_NAVIPAY_ORDER_TAG_SUMMARY
|
||||
import com.navi.pay.utils.RESOURCE_DEFAULT_ID
|
||||
import com.navi.pay.utils.getDisplayableAmount
|
||||
import com.navi.pay.utils.parallelMap
|
||||
import com.ramcosta.composedestinations.spec.Direction
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -65,6 +68,7 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
@@ -85,7 +89,8 @@ constructor(
|
||||
private val orderRepository: OrderRepository,
|
||||
private val syncOrderHistoryUseCase: SyncOrderHistoryUseCase,
|
||||
private val resourceProvider: ResourceProvider,
|
||||
private val naviPayConfigUseCase: NaviPayConfigUseCase
|
||||
private val naviPayConfigUseCase: NaviPayConfigUseCase,
|
||||
private val litmusExperimentsUseCase: LitmusExperimentsUseCase
|
||||
) : NaviPayBaseVM() {
|
||||
|
||||
companion object {
|
||||
@@ -238,6 +243,9 @@ constructor(
|
||||
initialValue = false
|
||||
)
|
||||
|
||||
private val _orderSummaryAmountMap = MutableStateFlow<Map<String, String>>(emptyMap())
|
||||
val orderSummaryAmountMap = _orderSummaryAmountMap.asStateFlow()
|
||||
|
||||
init {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
syncOrderHistoryUseCase.execute(screenName = screenName)
|
||||
@@ -254,6 +262,8 @@ constructor(
|
||||
}
|
||||
.collect()
|
||||
}
|
||||
|
||||
initOrderSummaryAmountDataListener()
|
||||
}
|
||||
|
||||
fun refreshOrderHistory() {
|
||||
@@ -869,25 +879,44 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getUpdatedTagHolderForCountList(
|
||||
transactionTagHolders: List<TransactionTagHolder>,
|
||||
countList: List<Int>
|
||||
): List<TransactionTagHolder> {
|
||||
return transactionTagHolders.mapIndexed { index, tagHolder ->
|
||||
val isEnabled = countList[index] != 0
|
||||
|
||||
tagHolder.copy(
|
||||
isEnabled = isEnabled,
|
||||
isActive = isEnabled && tagHolder.isActive,
|
||||
isSelected = isEnabled && tagHolder.isSelected
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initOrderSummaryAmountDataListener() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (
|
||||
litmusExperimentsUseCase
|
||||
.execute(experimentName = LITMUS_EXPERIMENT_NAVIPAY_ORDER_TAG_SUMMARY)
|
||||
?.variant
|
||||
?.enabled != true
|
||||
) {
|
||||
return@launch
|
||||
}
|
||||
naviPayAnalytics.onOrderTagSummaryEnabled()
|
||||
orderRepository.getAllOrderSummary().collectLatest { orderSummaryEntityList ->
|
||||
_orderSummaryAmountMap.update {
|
||||
orderSummaryEntityList.associate { it.tag to it.amount.getDisplayableAmount() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val screenName: String
|
||||
get() = NAVI_PAY_T_STORE_ORDER_LIST
|
||||
}
|
||||
|
||||
fun getUpdatedTagHolderForCountList(
|
||||
transactionTagHolders: List<TransactionTagHolder>,
|
||||
countList: List<Int>
|
||||
): List<TransactionTagHolder> {
|
||||
return transactionTagHolders.mapIndexed { index, tagHolder ->
|
||||
val isEnabled = countList[index] != 0
|
||||
|
||||
tagHolder.copy(
|
||||
isEnabled = isEnabled,
|
||||
isActive = isEnabled && tagHolder.isActive,
|
||||
isSelected = isEnabled && tagHolder.isSelected
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
enum class OrderHistoryScreenBottomSheetUIState {
|
||||
Categories,
|
||||
Months,
|
||||
|
||||
@@ -179,10 +179,12 @@ const val NAVI_PAY_SYNC_TABLE_UPI_LITE_MANDATE_INFO = "upiLiteMandateInfo"
|
||||
const val LITMUS_EXPERIMENT_NAVIPAY_LITE_AUTO_TOP_UP = "NaviPay-lite-auto-top-up"
|
||||
const val LITMUS_EXPERIMENT_NAVIPAY_LITE_DEFAULT_ENTERED_AMOUNT =
|
||||
"NaviPay-lite-default-entered-amount"
|
||||
const val LITMUS_EXPERIMENT_NAVIPAY_ORDER_TAG_SUMMARY = "NaviPay-order-tag-summary"
|
||||
val NAVI_PAY_LITMUS_EXPERIMENTS =
|
||||
listOf(
|
||||
LITMUS_EXPERIMENT_NAVIPAY_LITE_AUTO_TOP_UP,
|
||||
LITMUS_EXPERIMENT_NAVIPAY_LITE_DEFAULT_ENTERED_AMOUNT
|
||||
LITMUS_EXPERIMENT_NAVIPAY_LITE_DEFAULT_ENTERED_AMOUNT,
|
||||
LITMUS_EXPERIMENT_NAVIPAY_ORDER_TAG_SUMMARY
|
||||
)
|
||||
|
||||
// Generic
|
||||
@@ -285,6 +287,7 @@ const val NAVI_PAY_DATABASE_VALIDATE_VPA_CACHE_TABLE_NAME = "validateVpaCache"
|
||||
const val NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME = "orderHistory"
|
||||
const val NAVI_PAY_DATABASE_UPI_NUMBERS_TABLE_NAME = "upiNumbers"
|
||||
const val NAVI_PAY_DATABASE_VPA_TRANSACTION_INSIGHTS_TABLE_NAME = "vpaTransactionsInsights"
|
||||
const val NAVI_PAY_DATABASE_ORDER_TAG_SUMMARY_TABLE_NAME = "orderTagSummary"
|
||||
|
||||
// Dynamic Shortcut
|
||||
const val NAVI_PAY_SCAN_AND_PAY_LAUNCHER_WIDGET_SHORTCUT_ID = "scanAndPayShortcutId"
|
||||
|
||||
Reference in New Issue
Block a user