Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
PieChartScreen Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwa-Raghavendra committed May 3, 2022
1 parent 5cf3c0d commit 120a26d
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 352 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PieChartAct @Inject constructor(
)
} then {
addAccountTransfersCategory(
treatTransferAsIncExp = treatTransferAsIncExp,
showAccountTransfersCategory = showAccountTransfersCategory,
type = type,
accountTransfersCategory = accountTransfersCategory,
accountIdFilterSet = accountIdFilterList.toHashSet(),
Expand Down Expand Up @@ -172,7 +172,8 @@ class PieChartAct @Inject constructor(
TransactionType.EXPENSE -> catIncomeExpense.expense.toDouble()
else -> error("not supported transactionType - $type")
},
associatedTransactions = categoryTransactions.await()
associatedTransactions = categoryTransactions.await(),
isCategoryUnspecified = category == null
)
} thenFilter { catAmt ->
catAmt.amount != 0.0
Expand Down Expand Up @@ -213,7 +214,7 @@ class PieChartAct @Inject constructor(

@Pure
private suspend fun addAccountTransfersCategory(
treatTransferAsIncExp: Boolean,
showAccountTransfersCategory: Boolean,
type: TransactionType,
accountTransfersCategory: Category,
accountIdFilterSet: Set<UUID>,
Expand All @@ -231,7 +232,7 @@ class PieChartAct @Inject constructor(
val incExpQuad = incomeExpenseTransfer()

val catAmtList =
if (!treatTransferAsIncExp || incExpQuad.transferIncome == BigDecimal.ZERO && incExpQuad.transferExpense == BigDecimal.ZERO)
if (!showAccountTransfersCategory || incExpQuad.transferIncome == BigDecimal.ZERO && incExpQuad.transferExpense == BigDecimal.ZERO)
categoryAmounts then { it.sortedByDescending { ca -> ca.amount } }
else {

Expand All @@ -251,7 +252,12 @@ class PieChartAct @Inject constructor(

categoryAmounts then {
it.plus(
CategoryAmount(accountTransfersCategory, amt, categoryTrans)
CategoryAmount(
category = accountTransfersCategory,
amount = amt,
associatedTransactions = categoryTrans,
isCategoryUnspecified = true
)
)
} then {
it.sortedByDescending { ca -> ca.amount }
Expand All @@ -267,6 +273,7 @@ class PieChartAct @Inject constructor(
val type: TransactionType,
val accountIdFilterList: List<UUID>,
val treatTransferAsIncExp: Boolean = false,
val showAccountTransfersCategory: Boolean = treatTransferAsIncExp,
val existingTransactions: List<Transaction> = emptyList()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import com.ivy.wallet.domain.data.core.Transaction
data class CategoryAmount(
val category: Category?,
val amount: Double,
val associatedTransactions: List<Transaction> = emptyList()
val associatedTransactions: List<Transaction> = emptyList(),
val isCategoryUnspecified: Boolean = false
)
Loading

0 comments on commit 120a26d

Please sign in to comment.