From e50c806b941757886b1281813bfff6d0530316d9 Mon Sep 17 00:00:00 2001 From: MaratKhakim Date: Thu, 19 Oct 2023 21:14:12 +0200 Subject: [PATCH] refs #1086: Fix skip, skip all and pay buttons on Reports screen (#2797) --- .../main/java/com/ivy/reports/ReportScreen.kt | 8 +++++- .../java/com/ivy/reports/ReportScreenEvent.kt | 2 ++ .../java/com/ivy/reports/ReportViewModel.kt | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/screen-reports/src/main/java/com/ivy/reports/ReportScreen.kt b/screen-reports/src/main/java/com/ivy/reports/ReportScreen.kt index 2097c92933..559ddbaf50 100644 --- a/screen-reports/src/main/java/com/ivy/reports/ReportScreen.kt +++ b/screen-reports/src/main/java/com/ivy/reports/ReportScreen.kt @@ -251,7 +251,13 @@ private fun BoxWithConstraintsScope.UI( onEventHandler.invoke(ReportScreenEvent.OnPayOrGet(transaction = it)) }, emptyStateTitle = stringRes(R.string.no_transactions), - emptyStateText = stringRes(R.string.no_transactions_for_your_filter) + emptyStateText = stringRes(R.string.no_transactions_for_your_filter), + onSkipTransaction = { + onEventHandler.invoke(ReportScreenEvent.SkipTransaction(transaction = it)) + }, + onSkipAllTransactions = { + onEventHandler.invoke(ReportScreenEvent.SkipTransactions(transactions = it)) + } ) } else { item { diff --git a/screen-reports/src/main/java/com/ivy/reports/ReportScreenEvent.kt b/screen-reports/src/main/java/com/ivy/reports/ReportScreenEvent.kt index 1ce53ef860..a8405ef552 100644 --- a/screen-reports/src/main/java/com/ivy/reports/ReportScreenEvent.kt +++ b/screen-reports/src/main/java/com/ivy/reports/ReportScreenEvent.kt @@ -7,6 +7,8 @@ sealed class ReportScreenEvent { data class OnFilter(val filter: ReportFilter?) : ReportScreenEvent() data class OnExport(val context: Context) : ReportScreenEvent() data class OnPayOrGet(val transaction: Transaction) : ReportScreenEvent() + data class SkipTransaction(val transaction: Transaction) : ReportScreenEvent() + data class SkipTransactions(val transactions: List) : ReportScreenEvent() data class OnUpcomingExpanded(val upcomingExpanded: Boolean) : ReportScreenEvent() data class OnOverdueExpanded(val overdueExpanded: Boolean) : ReportScreenEvent() data class OnFilterOverlayVisible(val filterOverlayVisible: Boolean) : ReportScreenEvent() diff --git a/screen-reports/src/main/java/com/ivy/reports/ReportViewModel.kt b/screen-reports/src/main/java/com/ivy/reports/ReportViewModel.kt index aad7050e14..6f1586dcf1 100644 --- a/screen-reports/src/main/java/com/ivy/reports/ReportViewModel.kt +++ b/screen-reports/src/main/java/com/ivy/reports/ReportViewModel.kt @@ -126,6 +126,8 @@ class ReportViewModel @Inject constructor( is ReportScreenEvent.OnFilter -> setFilter(event.filter) is ReportScreenEvent.OnExport -> export(event.context) is ReportScreenEvent.OnPayOrGet -> payOrGet(event.transaction) + is ReportScreenEvent.SkipTransaction -> skipTransaction(event.transaction) + is ReportScreenEvent.SkipTransactions -> skipTransactions(event.transactions) is ReportScreenEvent.OnOverdueExpanded -> setOverdueExpanded(event.overdueExpanded) is ReportScreenEvent.OnUpcomingExpanded -> setUpcomingExpanded(event.upcomingExpanded) is ReportScreenEvent.OnFilterOverlayVisible -> setFilterOverlayVisible(event.filterOverlayVisible) @@ -404,6 +406,7 @@ class ReportViewModel @Inject constructor( uiThread { plannedPaymentsLogic.payOrGet(transaction = transaction) { start() + setFilter(filter.value) } } } @@ -419,4 +422,28 @@ class ReportViewModel @Inject constructor( if (transfersAsIncExp) historyIncomeExpense.value.transferExpense.toDouble() else 0.0 treatTransfersAsIncExp.value = transfersAsIncExp } + + private suspend fun skipTransaction(transaction: Transaction) { + uiThread { + plannedPaymentsLogic.payOrGet( + transaction = transaction, + skipTransaction = true + ) { + start() + setFilter(filter.value) + } + } + } + + private suspend fun skipTransactions(transactions: List) { + uiThread { + plannedPaymentsLogic.payOrGet( + transactions = transactions, + skipTransaction = true + ) { + start() + setFilter(filter.value) + } + } + } }