From 4a7f9c077521a314595fa8fbd53159bce78059d4 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Tue, 26 Apr 2022 17:04:56 +0200 Subject: [PATCH] Converted Room Dao functions to suspend functions. --- .../java/com/ivy/wallet/HiltTestRunner.kt | 3 +- .../com/ivy/wallet/compose/IvyComposeTest.kt | 3 +- .../domain/deprecated/logic/AccountCreator.kt | 2 +- .../deprecated/logic/CustomerJourneyLogic.kt | 2 +- .../logic/PlannedPaymentsGenerator.kt | 8 +- .../deprecated/logic/PlannedPaymentsLogic.kt | 18 ++-- .../deprecated/logic/PreloadDataLogic.kt | 6 +- .../logic/SmartTitleSuggestionsLogic.kt | 4 +- .../deprecated/logic/WalletAccountLogic.kt | 29 +++---- .../deprecated/logic/WalletCategoryLogic.kt | 42 +++++----- .../deprecated/logic/csv/CSVImporter.kt | 6 +- .../logic/currency/ExchangeRatesLogic.kt | 18 ++-- .../wallet/domain/deprecated/sync/IvySync.kt | 2 +- .../deprecated/sync/item/AccountSync.kt | 2 +- .../domain/deprecated/sync/item/BudgetSync.kt | 2 +- .../deprecated/sync/item/CategorySync.kt | 2 +- .../deprecated/sync/item/LoanRecordSync.kt | 2 +- .../domain/deprecated/sync/item/LoanSync.kt | 2 +- .../sync/item/PlannedPaymentSync.kt | 2 +- .../deprecated/sync/item/TransactionSync.kt | 2 +- .../com/ivy/wallet/io/network/IvySession.kt | 2 +- .../wallet/io/persistence/IvyRoomDatabase.kt | 2 +- .../wallet/io/persistence/dao/AccountDao.kt | 20 ++--- .../wallet/io/persistence/dao/BudgetDao.kt | 18 ++-- .../wallet/io/persistence/dao/CategoryDao.kt | 18 ++-- .../io/persistence/dao/ExchangeRateDao.kt | 6 +- .../ivy/wallet/io/persistence/dao/LoanDao.kt | 18 ++-- .../io/persistence/dao/LoanRecordDao.kt | 18 ++-- .../persistence/dao/PlannedPaymentRuleDao.kt | 22 ++--- .../wallet/io/persistence/dao/SettingsDao.kt | 14 ++-- .../io/persistence/dao/TransactionDao.kt | 82 +++++++++---------- .../ivy/wallet/io/persistence/dao/UserDao.kt | 6 +- .../ivy/wallet/ui/charts/ChartsViewModel.kt | 4 +- .../ui/theme/transaction/TransactionCard.kt | 2 +- .../com/ivy/wallet/buildsrc/dependencies.kt | 3 + .../src/main/java/com/ivy/fp/Composition.kt | 5 ++ 36 files changed, 204 insertions(+), 193 deletions(-) diff --git a/app/src/androidTest/java/com/ivy/wallet/HiltTestRunner.kt b/app/src/androidTest/java/com/ivy/wallet/HiltTestRunner.kt index d00ad1665d..3a8a0f9a8d 100644 --- a/app/src/androidTest/java/com/ivy/wallet/HiltTestRunner.kt +++ b/app/src/androidTest/java/com/ivy/wallet/HiltTestRunner.kt @@ -8,7 +8,8 @@ import dagger.hilt.android.testing.HiltTestApplication // A custom runner to set up the instrumented application class for tests. class HiltTestRunner : AndroidJUnitRunner() { - override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { + override fun newApplication(cl: ClassLoader?, name: String?, context: Context): Application { + IvyAndroidApp.appContext = context return super.newApplication(cl, HiltTestApplication::class.java.name, context) } } \ No newline at end of file diff --git a/app/src/androidTest/java/com/ivy/wallet/compose/IvyComposeTest.kt b/app/src/androidTest/java/com/ivy/wallet/compose/IvyComposeTest.kt index e599f9a326..0b14f6b553 100644 --- a/app/src/androidTest/java/com/ivy/wallet/compose/IvyComposeTest.kt +++ b/app/src/androidTest/java/com/ivy/wallet/compose/IvyComposeTest.kt @@ -20,6 +20,7 @@ import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.utils.* import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import kotlinx.coroutines.test.runTest import org.junit.After import org.junit.Before import org.junit.Rule @@ -98,7 +99,7 @@ abstract class IvyComposeTest { SharedPrefs(context()).removeAll() } - private fun resetDatabase() { + private fun resetDatabase() = runTest { ivyRoomDatabase.reset() } diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt index 7791bfcc0f..f4b099f6c3 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt @@ -33,7 +33,7 @@ class AccountCreator( color = data.color.toArgb(), icon = data.icon, includeInBalance = data.includeBalance, - orderNum = accountDao.findMaxOrderNum() + 1, + orderNum = accountDao.findMaxOrderNum() + 1.0, isSynced = false ) accountDao.save(account.toEntity()) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt index 2f45174949..c989a63fba 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt @@ -24,7 +24,7 @@ class CustomerJourneyLogic( private val ivyContext: IvyWalletCtx ) { - fun loadCards(): List { + suspend fun loadCards(): List { val trnCount = transactionDao.countHappenedTransactions() val plannedPaymentsCount = plannedPaymentRuleDao.countPlannedPayments() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt index 3f028b636f..fefb81070c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt @@ -13,7 +13,7 @@ class PlannedPaymentsGenerator( private const val GENERATED_INSTANCES_LIMIT = 72 } - fun generate(rule: PlannedPaymentRule) { + suspend fun generate(rule: PlannedPaymentRule) { //delete all not happened transactions transactionDao.flagDeletedByRecurringRuleIdAndNoDateTime( recurringRuleId = rule.id @@ -26,7 +26,7 @@ class PlannedPaymentsGenerator( } } - private fun generateOneTime(rule: PlannedPaymentRule) { + private suspend fun generateOneTime(rule: PlannedPaymentRule) { val trns = transactionDao.findAllByRecurringRuleId(recurringRuleId = rule.id) if (trns.isEmpty()) { @@ -34,7 +34,7 @@ class PlannedPaymentsGenerator( } } - private fun generateRecurring(rule: PlannedPaymentRule) { + private suspend fun generateRecurring(rule: PlannedPaymentRule) { val startDate = rule.startDate!! val endDate = startDate.plusYears(3) @@ -69,7 +69,7 @@ class PlannedPaymentsGenerator( } } - private fun generateTransaction(rule: PlannedPaymentRule, dueDate: LocalDateTime) { + private suspend fun generateTransaction(rule: PlannedPaymentRule, dueDate: LocalDateTime) { transactionDao.save( Transaction( type = rule.type, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt index 9be79816a1..dbd8be39bf 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt @@ -31,7 +31,7 @@ class PlannedPaymentsLogic( private const val AVG_DAYS_IN_MONTH = 30.436875 } - fun plannedPaymentsAmountFor(range: FromToTimeRange): Double { + suspend fun plannedPaymentsAmountFor(range: FromToTimeRange): Double { val baseCurrency = settingsDao.findFirst().currency val accounts = accountDao.findAll() @@ -53,11 +53,11 @@ class PlannedPaymentsLogic( } } - fun oneTime(): List { + suspend fun oneTime(): List { return plannedPaymentRuleDao.findAllByOneTime(oneTime = true).map { it.toDomain() } } - fun oneTimeIncome(): Double { + suspend fun oneTimeIncome(): Double { return oneTime() .filter { it.type == TransactionType.INCOME } .sumByDoublePlannedInBaseCurrency( @@ -67,7 +67,7 @@ class PlannedPaymentsLogic( ) } - fun oneTimeExpenses(): Double { + suspend fun oneTimeExpenses(): Double { return oneTime() .filter { it.type == TransactionType.EXPENSE } .sumByDoublePlannedInBaseCurrency( @@ -77,22 +77,22 @@ class PlannedPaymentsLogic( ) } - fun recurring(): List = + suspend fun recurring(): List = plannedPaymentRuleDao.findAllByOneTime(oneTime = false).map { it.toDomain() } - fun recurringIncome(): Double { + suspend fun recurringIncome(): Double { return recurring() .filter { it.type == TransactionType.INCOME } .sumByDoubleRecurringForMonthInBaseCurrency() } - fun recurringExpenses(): Double { + suspend fun recurringExpenses(): Double { return recurring() .filter { it.type == TransactionType.EXPENSE } .sumByDoubleRecurringForMonthInBaseCurrency() } - private fun Iterable.sumByDoubleRecurringForMonthInBaseCurrency(): Double { + private suspend fun Iterable.sumByDoubleRecurringForMonthInBaseCurrency(): Double { val accounts = accountDao.findAll() val baseCurrency = settingsDao.findFirst().currency @@ -105,7 +105,7 @@ class PlannedPaymentsLogic( } } - private fun amountForMonthInBaseCurrency( + private suspend fun amountForMonthInBaseCurrency( plannedPayment: PlannedPaymentRule, baseCurrency: String, accounts: List diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt index 963fba05fe..0008da514c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt @@ -24,7 +24,7 @@ class PreloadDataLogic( return accounts.size < 2 } - fun preloadAccounts() { + suspend fun preloadAccounts() { val cash = Account( name = stringRes(R.string.cash), currency = null, @@ -71,7 +71,7 @@ class PreloadDataLogic( ), ) - fun preloadCategories() { + suspend fun preloadCategories() { categoryOrderNum = 0.0 val categoriesToPreload = preloadCategoriesCreateData() @@ -143,7 +143,7 @@ class PreloadDataLogic( ), ) - private fun preloadCategory( + private suspend fun preloadCategory( data: CreateCategoryData ) { val category = Category( diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt index 875eedfeac..10e5aab77a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt @@ -18,7 +18,7 @@ class SmartTitleSuggestionsLogic( * - most used titles for categories * - if suggestions.size < SUGGESTIONS_LIMIT most used titles for accounts */ - fun suggest( + suspend fun suggest( title: String?, categoryId: UUID?, accountId: UUID? @@ -100,7 +100,7 @@ private fun List.extractUniqueTitles( } @Deprecated("Use FP style, look into `domain.fp` package") -private fun Set.sortedByMostUsedFirst(countUses: (String) -> Long): Set { +private suspend fun Set.sortedByMostUsedFirst(countUses: suspend (String) -> Long): Set { val titleCountMap = this .map { it to countUses(it) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt index 453d65b76f..e3dc661147 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt @@ -23,9 +23,9 @@ class WalletAccountLogic( private val settingsDao: SettingsDao ) { - fun adjustBalance( + suspend fun adjustBalance( account: Account, - actualBalance: Double = calculateAccountBalance(account), + actualBalance: Double? = null, newBalance: Double, adjustTransactionTitle: String = "Adjust balance", @@ -33,7 +33,8 @@ class WalletAccountLogic( isFiat: Boolean? = null, trnIsSyncedFlag: Boolean = false, //TODO: Remove this once Bank Integration trn sync is properly implemented ) { - val diff = actualBalance - newBalance + val ab = actualBalance ?: calculateAccountBalance(account) + val diff = ab - newBalance val finalDiff = if (isFiat == true && abs(diff) < 0.009) 0.0 else diff when { @@ -68,7 +69,7 @@ class WalletAccountLogic( } } - fun calculateAccountBalance( + suspend fun calculateAccountBalance( account: Account, before: LocalDateTime? = null ): Double { @@ -81,7 +82,7 @@ class WalletAccountLogic( ) } - private fun calculateIncomeWithTransfers( + private suspend fun calculateIncomeWithTransfers( account: Account, before: LocalDateTime? ): Double { @@ -102,7 +103,7 @@ class WalletAccountLogic( ) } - private fun calculateExpensesWithTransfers( + private suspend fun calculateExpensesWithTransfers( account: Account, before: LocalDateTime? ): Double { @@ -135,7 +136,7 @@ class WalletAccountLogic( } } - fun calculateAccountIncome(account: Account, range: FromToTimeRange): Double = + suspend fun calculateAccountIncome(account: Account, range: FromToTimeRange): Double = transactionDao .findAllByTypeAndAccountBetween( type = TransactionType.INCOME, @@ -146,7 +147,7 @@ class WalletAccountLogic( .filter { it.dateTime != null } .sumOf { it.amount } - fun calculateAccountExpenses(account: Account, range: FromToTimeRange): Double = + suspend fun calculateAccountExpenses(account: Account, range: FromToTimeRange): Double = transactionDao .findAllByTypeAndAccountBetween( type = TransactionType.EXPENSE, @@ -157,27 +158,27 @@ class WalletAccountLogic( .filter { it.dateTime != null } .sumOf { it.amount } - fun calculateUpcomingIncome(account: Account, range: FromToTimeRange): Double = + suspend fun calculateUpcomingIncome(account: Account, range: FromToTimeRange): Double = upcoming(account, range = range) .filter { it.type == TransactionType.INCOME } .sumOf { it.amount.toDouble() } - fun calculateUpcomingExpenses(account: Account, range: FromToTimeRange): Double = + suspend fun calculateUpcomingExpenses(account: Account, range: FromToTimeRange): Double = upcoming(account = account, range = range) .filter { it.type == TransactionType.EXPENSE } .sumOf { it.amount.toDouble() } - fun calculateOverdueIncome(account: Account, range: FromToTimeRange): Double = + suspend fun calculateOverdueIncome(account: Account, range: FromToTimeRange): Double = overdue(account, range = range) .filter { it.type == TransactionType.INCOME } .sumOf { it.amount.toDouble() } - fun calculateOverdueExpenses(account: Account, range: FromToTimeRange): Double = + suspend fun calculateOverdueExpenses(account: Account, range: FromToTimeRange): Double = overdue(account, range = range) .filter { it.type == TransactionType.EXPENSE } .sumOf { it.amount.toDouble() } - fun upcoming(account: Account, range: FromToTimeRange): List { + suspend fun upcoming(account: Account, range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByAccount( accountId = account.id, startDate = range.upcomingFrom(), @@ -188,7 +189,7 @@ class WalletAccountLogic( } - fun overdue(account: Account, range: FromToTimeRange): List { + suspend fun overdue(account: Account, range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByAccount( accountId = account.id, startDate = range.from(), diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt index e17d498e3c..94d5d8ec89 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt @@ -23,7 +23,7 @@ class WalletCategoryLogic( private val transactionDao: TransactionDao ) { - fun calculateCategoryBalance( + suspend fun calculateCategoryBalance( category: Category, range: FromToTimeRange, accountFilterSet: Set = emptySet(), @@ -53,7 +53,7 @@ class WalletCategoryLogic( } } - fun calculateCategoryIncome( + suspend fun calculateCategoryIncome( category: Category, range: FromToTimeRange, accountFilterSet: Set = emptySet(), @@ -75,7 +75,7 @@ class WalletCategoryLogic( ) } - fun calculateCategoryIncome( + suspend fun calculateCategoryIncome( incomeTransaction: List, accountFilterSet: Set = emptySet() ): Double { @@ -90,7 +90,7 @@ class WalletCategoryLogic( ) } - fun calculateCategoryExpenses( + suspend fun calculateCategoryExpenses( category: Category, range: FromToTimeRange, accountFilterSet: Set = emptySet(), @@ -113,7 +113,7 @@ class WalletCategoryLogic( } - fun calculateCategoryExpenses( + suspend fun calculateCategoryExpenses( expenseTransactions: List, accountFilterSet: Set = emptySet() ): Double { @@ -128,11 +128,11 @@ class WalletCategoryLogic( ) } - fun calculateUnspecifiedBalance(range: FromToTimeRange): Double { + suspend fun calculateUnspecifiedBalance(range: FromToTimeRange): Double { return calculateUnspecifiedIncome(range) - calculateUnspecifiedExpenses(range) } - fun calculateUnspecifiedIncome(range: FromToTimeRange): Double { + suspend fun calculateUnspecifiedIncome(range: FromToTimeRange): Double { return transactionDao .findAllUnspecifiedAndTypeAndBetween( type = TransactionType.INCOME, @@ -146,7 +146,7 @@ class WalletCategoryLogic( ) } - fun calculateUnspecifiedExpenses(range: FromToTimeRange): Double { + suspend fun calculateUnspecifiedExpenses(range: FromToTimeRange): Double { return transactionDao .findAllUnspecifiedAndTypeAndBetween( type = TransactionType.EXPENSE, @@ -178,7 +178,7 @@ class WalletCategoryLogic( ) } - fun historyByCategory( + suspend fun historyByCategory( category: Category, range: FromToTimeRange, accountFilterSet: Set = emptySet(), @@ -213,7 +213,7 @@ class WalletCategoryLogic( } - fun calculateUpcomingIncomeByCategory(category: Category, range: FromToTimeRange): Double { + suspend fun calculateUpcomingIncomeByCategory(category: Category, range: FromToTimeRange): Double { return upcomingByCategory(category = category, range = range) .filter { it.type == TransactionType.INCOME } .sumInBaseCurrency( @@ -223,7 +223,7 @@ class WalletCategoryLogic( ) } - fun calculateUpcomingExpensesByCategory(category: Category, range: FromToTimeRange): Double { + suspend fun calculateUpcomingExpensesByCategory(category: Category, range: FromToTimeRange): Double { return upcomingByCategory(category = category, range = range) .filter { it.type == TransactionType.EXPENSE } .sumInBaseCurrency( @@ -233,7 +233,7 @@ class WalletCategoryLogic( ) } - fun calculateUpcomingIncomeUnspecified(range: FromToTimeRange): Double { + suspend fun calculateUpcomingIncomeUnspecified(range: FromToTimeRange): Double { return upcomingUnspecified(range = range) .filter { it.type == TransactionType.INCOME } .sumInBaseCurrency( @@ -243,7 +243,7 @@ class WalletCategoryLogic( ) } - fun calculateUpcomingExpensesUnspecified(range: FromToTimeRange): Double { + suspend fun calculateUpcomingExpensesUnspecified(range: FromToTimeRange): Double { return upcomingUnspecified(range = range) .filter { it.type == TransactionType.EXPENSE } .sumInBaseCurrency( @@ -253,7 +253,7 @@ class WalletCategoryLogic( ) } - fun upcomingByCategory(category: Category, range: FromToTimeRange): List { + suspend fun upcomingByCategory(category: Category, range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategory( categoryId = category.id, startDate = range.upcomingFrom(), @@ -263,7 +263,7 @@ class WalletCategoryLogic( .filterUpcoming() } - fun upcomingUnspecified(range: FromToTimeRange): List { + suspend fun upcomingUnspecified(range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategoryUnspecified( startDate = range.upcomingFrom(), endDate = range.to() @@ -272,7 +272,7 @@ class WalletCategoryLogic( .filterUpcoming() } - fun calculateOverdueIncomeByCategory(category: Category, range: FromToTimeRange): Double { + suspend fun calculateOverdueIncomeByCategory(category: Category, range: FromToTimeRange): Double { return overdueByCategory(category, range = range) .filter { it.type == TransactionType.INCOME } .sumInBaseCurrency( @@ -282,7 +282,7 @@ class WalletCategoryLogic( ) } - fun calculateOverdueExpensesByCategory(category: Category, range: FromToTimeRange): Double { + suspend fun calculateOverdueExpensesByCategory(category: Category, range: FromToTimeRange): Double { return overdueByCategory(category, range = range) .filter { it.type == TransactionType.EXPENSE } .sumInBaseCurrency( @@ -292,7 +292,7 @@ class WalletCategoryLogic( ) } - fun calculateOverdueIncomeUnspecified(range: FromToTimeRange): Double { + suspend fun calculateOverdueIncomeUnspecified(range: FromToTimeRange): Double { return overdueUnspecified(range = range) .filter { it.type == TransactionType.INCOME } .sumInBaseCurrency( @@ -302,7 +302,7 @@ class WalletCategoryLogic( ) } - fun calculateOverdueExpensesUnspecified(range: FromToTimeRange): Double { + suspend fun calculateOverdueExpensesUnspecified(range: FromToTimeRange): Double { return overdueUnspecified(range = range) .filter { it.type == TransactionType.EXPENSE } .sumInBaseCurrency( @@ -313,7 +313,7 @@ class WalletCategoryLogic( } - fun overdueByCategory(category: Category, range: FromToTimeRange): List { + suspend fun overdueByCategory(category: Category, range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategory( categoryId = category.id, startDate = range.from(), @@ -323,7 +323,7 @@ class WalletCategoryLogic( .filterOverdue() } - fun overdueUnspecified(range: FromToTimeRange): List { + suspend fun overdueUnspecified(range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategoryUnspecified( startDate = range.from(), endDate = range.overdueTo() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt index cd36a3f8e9..3fdc40ab26 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt @@ -132,7 +132,7 @@ class CSVImporter( ) } - private fun mapToTransaction( + private suspend fun mapToTransaction( baseCurrency: String, row: List, rowMapping: RowMapping @@ -403,7 +403,7 @@ class CSVImporter( ).convertLocalToUTC() } - private fun mapAccount( + private suspend fun mapAccount( baseCurrency: String, accountNameString: String?, color: Int?, @@ -466,7 +466,7 @@ class CSVImporter( } - private fun mapCategory( + private suspend fun mapCategory( categoryNameString: String?, color: Int?, icon: String?, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt index 374110e9bc..d5187c7111 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt @@ -46,7 +46,7 @@ class ExchangeRatesLogic( } } - fun amountBaseCurrency( + suspend fun amountBaseCurrency( plannedPayment: PlannedPaymentRule, baseCurrency: String, accounts: List //helper @@ -59,7 +59,7 @@ class ExchangeRatesLogic( ) } - fun amountBaseCurrency( + suspend fun amountBaseCurrency( transaction: Transaction, baseCurrency: String, accounts: List //helper @@ -72,7 +72,7 @@ class ExchangeRatesLogic( ) } - fun toAmountBaseCurrency( + suspend fun toAmountBaseCurrency( transaction: Transaction, baseCurrency: String, accounts: List //helper @@ -88,7 +88,7 @@ class ExchangeRatesLogic( ) } - private fun amountBaseCurrency( + private suspend fun amountBaseCurrency( amount: Double, accountId: UUID, baseCurrency: String, @@ -104,7 +104,7 @@ class ExchangeRatesLogic( ) } - fun amountBaseCurrency( + suspend fun amountBaseCurrency( amount: Double, amountCurrency: String, baseCurrency: String @@ -118,7 +118,7 @@ class ExchangeRatesLogic( } } - fun convertAmount( + suspend fun convertAmount( baseCurrency: String, amount: Double, fromCurrency: String, @@ -134,7 +134,7 @@ class ExchangeRatesLogic( /** * base = BGN, currency = EUR => rate = 0.51 */ - private fun exchangeRate( + private suspend fun exchangeRate( baseCurrency: String, currency: String ): Double { @@ -150,7 +150,7 @@ class ExchangeRatesLogic( } @Deprecated("Use FP style, look into `domain.fp` package") -fun Iterable.sumInBaseCurrency( +suspend fun Iterable.sumInBaseCurrency( exchangeRatesLogic: ExchangeRatesLogic, settingsDao: SettingsDao, accountDao: AccountDao, @@ -168,7 +168,7 @@ fun Iterable.sumInBaseCurrency( } @Deprecated("Use FP style, look into `domain.fp` package") -fun Iterable.sumByDoublePlannedInBaseCurrency( +suspend fun Iterable.sumByDoublePlannedInBaseCurrency( exchangeRatesLogic: ExchangeRatesLogic, settingsDao: SettingsDao, accountDao: AccountDao, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt index 41cb2a9941..6e6d1588c7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt @@ -13,7 +13,7 @@ class IvySync( private val loanRecordSync: LoanRecordSync, private val ivySession: IvySession ) { - fun isSynced(): Boolean { + suspend fun isSynced(): Boolean { return accountSync.isSynced() && categorySync.isSynced() && transactionSync.isSynced() && diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt index 6181a6d4c7..0aa9f1184b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt @@ -17,7 +17,7 @@ class AccountSync( ) { private val service = restClient.accountService - fun isSynced(): Boolean = + suspend fun isSynced(): Boolean = dao.findByIsSyncedAndIsDeleted(synced = false, deleted = false).isEmpty() && dao.findByIsSyncedAndIsDeleted(synced = false, deleted = true).isEmpty() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt index 022c54b2bf..2b6f644cd4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt @@ -17,7 +17,7 @@ class BudgetSync( ) { private val service = restClient.budgetService - fun isSynced(): Boolean = + suspend fun isSynced(): Boolean = dao.findByIsSyncedAndIsDeleted(synced = false, deleted = false).isEmpty() && dao.findByIsSyncedAndIsDeleted(synced = false, deleted = true).isEmpty() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt index b3327ddfa7..3d9146b160 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt @@ -17,7 +17,7 @@ class CategorySync( ) { private val service = restClient.categoryService - fun isSynced(): Boolean = + suspend fun isSynced(): Boolean = dao.findByIsSyncedAndIsDeleted(synced = false, deleted = false).isEmpty() && dao.findByIsSyncedAndIsDeleted(synced = false, deleted = true).isEmpty() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt index cb0ece3006..38f48e19f5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt @@ -17,7 +17,7 @@ class LoanRecordSync( ) { private val service = restClient.loanService - fun isSynced(): Boolean = + suspend fun isSynced(): Boolean = dao.findByIsSyncedAndIsDeleted(synced = false, deleted = false).isEmpty() && dao.findByIsSyncedAndIsDeleted(synced = false, deleted = true).isEmpty() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt index f4e6e634ae..243d05c56a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt @@ -17,7 +17,7 @@ class LoanSync( ) { private val service = restClient.loanService - fun isSynced(): Boolean = + suspend fun isSynced(): Boolean = dao.findByIsSyncedAndIsDeleted(synced = false, deleted = false).isEmpty() && dao.findByIsSyncedAndIsDeleted(synced = false, deleted = true).isEmpty() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt index 46e80e4a1e..aa2ad770a7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt @@ -17,7 +17,7 @@ class PlannedPaymentSync( ) { private val service = restClient.plannedPaymentRuleService - fun isSynced(): Boolean = + suspend fun isSynced(): Boolean = dao.findByIsSyncedAndIsDeleted(synced = false, deleted = false).isEmpty() && dao.findByIsSyncedAndIsDeleted(synced = false, deleted = true).isEmpty() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt index 1b97b9df6f..5c65746124 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt @@ -17,7 +17,7 @@ class TransactionSync( ) { private val service = restClient.transactionService - fun isSynced(): Boolean = + suspend fun isSynced(): Boolean = dao.findByIsSyncedAndIsDeleted(synced = false, deleted = false).isEmpty() && dao.findByIsSyncedAndIsDeleted(synced = false, deleted = true).isEmpty() diff --git a/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt b/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt index c34c322c24..5f3d2ddffb 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt @@ -28,7 +28,7 @@ class IvySession( return userId != null && authToken != null } - fun initiate(authResponse: AuthResponse) { + suspend fun initiate(authResponse: AuthResponse) { val user = authResponse.user userDao.save(user.toEntity()) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt index 1a3c3c88b1..66b50e77ea 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt @@ -78,7 +78,7 @@ abstract class IvyRoomDatabase : RoomDatabase() { } } - fun reset() { + suspend fun reset() { accountDao().deleteAll() transactionDao().deleteAll() categoryDao().deleteAll() diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt index c7b4a7248e..4145ca297d 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt @@ -10,32 +10,32 @@ import java.util.* @Dao interface AccountDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: AccountEntity) + suspend fun save(value: AccountEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM accounts WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM accounts WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + suspend fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM accounts WHERE id = :id") - fun findById(id: UUID): AccountEntity? + suspend fun findById(id: UUID): AccountEntity? @Query("UPDATE accounts SET isDeleted = 1, isSynced = 0 WHERE id = :id") - fun flagDeleted(id: UUID) + suspend fun flagDeleted(id: UUID) @Query("DELETE FROM accounts WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("DELETE FROM accounts") - fun deleteAll() + suspend fun deleteAll() @Query("SELECT MIN(orderNum) FROM accounts") - fun findMinOrderNum(): Double + suspend fun findMinOrderNum(): Double @Query("SELECT MAX(orderNum) FROM accounts") - fun findMaxOrderNum(): Double + suspend fun findMaxOrderNum(): Double } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt index 5644bcc8db..ecae068e50 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt @@ -10,29 +10,29 @@ import java.util.* @Dao interface BudgetDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: BudgetEntity) + suspend fun save(value: BudgetEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM budgets WHERE isDeleted = 0 ORDER BY orderId ASC") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM budgets WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + suspend fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM budgets WHERE id = :id") - fun findById(id: UUID): BudgetEntity? + suspend fun findById(id: UUID): BudgetEntity? @Query("DELETE FROM budgets WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("UPDATE budgets SET isDeleted = 1, isSynced = 0 WHERE id = :id") - fun flagDeleted(id: UUID) + suspend fun flagDeleted(id: UUID) @Query("DELETE FROM budgets") - fun deleteAll() + suspend fun deleteAll() @Query("SELECT MAX(orderId) FROM budgets") - fun findMaxOrderNum(): Double + suspend fun findMaxOrderNum(): Double } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt index 609e7f3e5f..db01b463a4 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt @@ -10,29 +10,29 @@ import java.util.* @Dao interface CategoryDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: CategoryEntity) + suspend fun save(value: CategoryEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM categories WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM categories WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + suspend fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM categories WHERE id = :id") - fun findById(id: UUID): CategoryEntity? + suspend fun findById(id: UUID): CategoryEntity? @Query("DELETE FROM categories WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("UPDATE categories SET isDeleted = 1, isSynced = 0 WHERE id = :id") - fun flagDeleted(id: UUID) + suspend fun flagDeleted(id: UUID) @Query("DELETE FROM categories") - fun deleteAll() + suspend fun deleteAll() @Query("SELECT MAX(orderNum) FROM categories") - fun findMaxOrderNum(): Double + suspend fun findMaxOrderNum(): Double } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt index a85007ee8a..fac1ea743c 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt @@ -9,14 +9,14 @@ import com.ivy.wallet.io.persistence.data.ExchangeRateEntity @Dao interface ExchangeRateDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: ExchangeRateEntity) + suspend fun save(value: ExchangeRateEntity) @Query("SELECT * FROM exchange_rates WHERE baseCurrency = :baseCurrency AND currency = :currency") - fun findByBaseCurrencyAndCurrency( + suspend fun findByBaseCurrencyAndCurrency( baseCurrency: String, currency: String ): ExchangeRateEntity? @Query("DELETE FROM exchange_rates") - fun deleteALl() + suspend fun deleteALl() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt index 349a3d28dd..e0fda32466 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt @@ -10,29 +10,29 @@ import java.util.* @Dao interface LoanDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: LoanEntity) + suspend fun save(value: LoanEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM loans WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM loans WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + suspend fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM loans WHERE id = :id") - fun findById(id: UUID): LoanEntity? + suspend fun findById(id: UUID): LoanEntity? @Query("DELETE FROM loans WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("UPDATE loans SET isDeleted = 1, isSynced = 0 WHERE id = :id") - fun flagDeleted(id: UUID) + suspend fun flagDeleted(id: UUID) @Query("DELETE FROM loans") - fun deleteAll() + suspend fun deleteAll() @Query("SELECT MAX(orderNum) FROM loans") - fun findMaxOrderNum(): Double + suspend fun findMaxOrderNum(): Double } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt index fedc62336b..b0c01b911d 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt @@ -10,32 +10,32 @@ import java.util.* @Dao interface LoanRecordDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: LoanRecordEntity) + suspend fun save(value: LoanRecordEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM loan_records WHERE isDeleted = 0 ORDER BY dateTime DESC") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM loan_records WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted( + suspend fun findByIsSyncedAndIsDeleted( synced: Boolean, deleted: Boolean = false ): List @Query("SELECT * FROM loan_records WHERE id = :id") - fun findById(id: UUID): LoanRecordEntity? + suspend fun findById(id: UUID): LoanRecordEntity? @Query("SELECT * FROM loan_records WHERE loanId = :loanId AND isDeleted = 0 ORDER BY dateTime DESC") - fun findAllByLoanId(loanId: UUID): List + suspend fun findAllByLoanId(loanId: UUID): List @Query("DELETE FROM loan_records WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("UPDATE loan_records SET isDeleted = 1, isSynced = 0 WHERE id = :id") - fun flagDeleted(id: UUID) + suspend fun flagDeleted(id: UUID) @Query("DELETE FROM loan_records") - fun deleteAll() + suspend fun deleteAll() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt index 9986b3c2d6..23d6492392 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt @@ -10,38 +10,38 @@ import java.util.* @Dao interface PlannedPaymentRuleDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: PlannedPaymentRuleEntity) + suspend fun save(value: PlannedPaymentRuleEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM planned_payment_rules WHERE isDeleted = 0 ORDER BY amount DESC, startDate ASC") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM planned_payment_rules WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted( + suspend fun findByIsSyncedAndIsDeleted( synced: Boolean, deleted: Boolean = false ): List @Query("SELECT * FROM planned_payment_rules WHERE isDeleted = 0 AND oneTime = :oneTime ORDER BY amount DESC, startDate ASC") - fun findAllByOneTime(oneTime: Boolean): List + suspend fun findAllByOneTime(oneTime: Boolean): List @Query("SELECT * FROM planned_payment_rules WHERE id = :id AND isDeleted = 0") - fun findById(id: UUID): PlannedPaymentRuleEntity? + suspend fun findById(id: UUID): PlannedPaymentRuleEntity? @Query("UPDATE planned_payment_rules SET isDeleted = 1, isSynced = 0 WHERE id = :id") - fun flagDeleted(id: UUID) + suspend fun flagDeleted(id: UUID) @Query("UPDATE planned_payment_rules SET isDeleted = 1, isSynced = 0 WHERE accountId = :accountId") - fun flagDeletedByAccountId(accountId: UUID) + suspend fun flagDeletedByAccountId(accountId: UUID) @Query("DELETE FROM planned_payment_rules WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("DELETE FROM planned_payment_rules") - fun deleteAll() + suspend fun deleteAll() @Query("SELECT COUNT(*) FROM planned_payment_rules WHERE isDeleted = 0 ") - fun countPlannedPayments(): Long + suspend fun countPlannedPayments(): Long } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt index a77a89f405..81b24813c2 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt @@ -10,23 +10,23 @@ import java.util.* @Dao interface SettingsDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: SettingsEntity) + suspend fun save(value: SettingsEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM settings LIMIT 1") - fun findFirst(): SettingsEntity + suspend fun findFirst(): SettingsEntity @Query("SELECT * FROM settings") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM settings WHERE id = :id") - fun findById(id: UUID): SettingsEntity? + suspend fun findById(id: UUID): SettingsEntity? @Query("DELETE FROM settings WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("DELETE FROM settings") - fun deleteAll() + suspend fun deleteAll() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt index b89d721f8a..1c4f3a3ffc 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt @@ -12,26 +12,26 @@ import java.util.* @Dao interface TransactionDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: TransactionEntity) + suspend fun save(value: TransactionEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + suspend fun save(value: List) @Query("SELECT * FROM transactions WHERE isDeleted = 0 ORDER BY dateTime DESC, dueDate ASC") - fun findAll(): List + suspend fun findAll(): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 LIMIT 1") - fun findAll_LIMIT_1(): List + suspend fun findAll_LIMIT_1(): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type ORDER BY dateTime DESC") - fun findAllByType(type: TransactionType): List + suspend fun findAllByType(type: TransactionType): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and accountId = :accountId ORDER BY dateTime DESC") - fun findAllByTypeAndAccount(type: TransactionType, accountId: UUID): List + suspend fun findAllByTypeAndAccount(type: TransactionType, accountId: UUID): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and accountId = :accountId and dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllByTypeAndAccountBetween( + suspend fun findAllByTypeAndAccountBetween( type: TransactionType, accountId: UUID, startDate: LocalDateTime, @@ -39,13 +39,13 @@ interface TransactionDao { ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and toAccountId = :toAccountId ORDER BY dateTime DESC") - fun findAllTransfersToAccount( + suspend fun findAllTransfersToAccount( toAccountId: UUID, type: TransactionType = TransactionType.TRANSFER ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and toAccountId = :toAccountId and dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllTransfersToAccountBetween( + suspend fun findAllTransfersToAccountBetween( toAccountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime, @@ -53,30 +53,30 @@ interface TransactionDao { ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllBetween(startDate: LocalDateTime, endDate: LocalDateTime): List + suspend fun findAllBetween(startDate: LocalDateTime, endDate: LocalDateTime): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND accountId = :accountId AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllByAccountAndBetween( + suspend fun findAllByAccountAndBetween( accountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllByCategoryAndBetween( + suspend fun findAllByCategoryAndBetween( categoryId: UUID, startDate: LocalDateTime, endDate: LocalDateTime ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllUnspecifiedAndBetween( + suspend fun findAllUnspecifiedAndBetween( startDate: LocalDateTime, endDate: LocalDateTime ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllByCategoryAndTypeAndBetween( + suspend fun findAllByCategoryAndTypeAndBetween( categoryId: UUID, type: TransactionType, startDate: LocalDateTime, @@ -84,135 +84,135 @@ interface TransactionDao { ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllUnspecifiedAndTypeAndBetween( + suspend fun findAllUnspecifiedAndTypeAndBetween( type: TransactionType, startDate: LocalDateTime, endDate: LocalDateTime ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND toAccountId = :toAccountId AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllToAccountAndBetween( + suspend fun findAllToAccountAndBetween( toAccountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate ORDER BY dueDate ASC") - fun findAllDueToBetween( + suspend fun findAllDueToBetween( startDate: LocalDateTime, endDate: LocalDateTime ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId = :categoryId) ORDER BY dateTime DESC, dueDate ASC") - fun findAllDueToBetweenByCategory( + suspend fun findAllDueToBetweenByCategory( startDate: LocalDateTime, endDate: LocalDateTime, categoryId: UUID ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId IS NULL) ORDER BY dateTime DESC, dueDate ASC") - fun findAllDueToBetweenByCategoryUnspecified( + suspend fun findAllDueToBetweenByCategoryUnspecified( startDate: LocalDateTime, endDate: LocalDateTime, ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND accountId = :accountId ORDER BY dateTime DESC, dueDate ASC") - fun findAllDueToBetweenByAccount( + suspend fun findAllDueToBetweenByAccount( startDate: LocalDateTime, endDate: LocalDateTime, accountId: UUID ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND recurringRuleId = :recurringRuleId ORDER BY dateTime DESC") - fun findAllByRecurringRuleId(recurringRuleId: UUID): List + suspend fun findAllByRecurringRuleId(recurringRuleId: UUID): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate AND type = :type ORDER BY dateTime DESC") - fun findAllBetweenAndType( + suspend fun findAllBetweenAndType( startDate: LocalDateTime, endDate: LocalDateTime, type: TransactionType ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate AND recurringRuleId = :recurringRuleId ORDER BY dateTime DESC") - fun findAllBetweenAndRecurringRuleId( + suspend fun findAllBetweenAndRecurringRuleId( startDate: LocalDateTime, endDate: LocalDateTime, recurringRuleId: UUID ): List @Query("SELECT * FROM transactions WHERE id = :id") - fun findById(id: UUID): TransactionEntity? + suspend fun findById(id: UUID): TransactionEntity? @Query("SELECT * FROM transactions WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted( + suspend fun findByIsSyncedAndIsDeleted( synced: Boolean, deleted: Boolean = false ): List @Query("UPDATE transactions SET isDeleted = 1, isSynced = 0 WHERE id = :id") - fun flagDeleted(id: UUID) + suspend fun flagDeleted(id: UUID) @Query("UPDATE transactions SET isDeleted = 1, isSynced = 0 WHERE recurringRuleId = :recurringRuleId AND dateTime IS NULL") - fun flagDeletedByRecurringRuleIdAndNoDateTime(recurringRuleId: UUID) + suspend fun flagDeletedByRecurringRuleIdAndNoDateTime(recurringRuleId: UUID) @Query("UPDATE transactions SET isDeleted = 1, isSynced = 0 WHERE accountId = :accountId") - fun flagDeletedByAccountId(accountId: UUID) + suspend fun flagDeletedByAccountId(accountId: UUID) @Query("DELETE FROM transactions WHERE id = :id") - fun deleteById(id: UUID) + suspend fun deleteById(id: UUID) @Query("DELETE FROM transactions WHERE accountId = :accountId") - fun deleteAllByAccountId(accountId: UUID) + suspend fun deleteAllByAccountId(accountId: UUID) @Query("DELETE FROM transactions") - fun deleteAll() + suspend fun deleteAll() @Query("SELECT COUNT(*) FROM transactions WHERE isDeleted = 0 AND dateTime IS NOT null") - fun countHappenedTransactions(): Long + suspend fun countHappenedTransactions(): Long //Smart Title Suggestions @Query("SELECT * FROM transactions WHERE title LIKE :pattern AND isDeleted = 0") - fun findAllByTitleMatchingPattern(pattern: String): List + suspend fun findAllByTitleMatchingPattern(pattern: String): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND isDeleted = 0") - fun countByTitleMatchingPattern( + suspend fun countByTitleMatchingPattern( pattern: String, ): Long @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) ORDER BY dateTime DESC") - fun findAllByCategory( + suspend fun findAllByCategory( categoryId: UUID, ): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND categoryId = :categoryId AND isDeleted = 0") - fun countByTitleMatchingPatternAndCategoryId( + suspend fun countByTitleMatchingPatternAndCategoryId( pattern: String, categoryId: UUID ): Long @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND accountId = :accountId ORDER BY dateTime DESC") - fun findAllByAccount( + suspend fun findAllByAccount( accountId: UUID ): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND accountId = :accountId AND isDeleted = 0") - fun countByTitleMatchingPatternAndAccountId( + suspend fun countByTitleMatchingPatternAndAccountId( pattern: String, accountId: UUID ): Long @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanId = :loanId AND loanRecordId IS NULL") - fun findLoanTransaction( + suspend fun findLoanTransaction( loanId: UUID ): TransactionEntity? @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanRecordId = :loanRecordId") - fun findLoanRecordTransaction( + suspend fun findLoanRecordTransaction( loanRecordId: UUID ): TransactionEntity? @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanId = :loanId") - fun findAllByLoanId( + suspend fun findAllByLoanId( loanId: UUID ): List } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt index d76364d46f..081db84a66 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt @@ -10,11 +10,11 @@ import java.util.* @Dao interface UserDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(user: UserEntity) + suspend fun save(user: UserEntity) @Query("SELECT * FROM users WHERE id = :userId") - fun findById(userId: UUID): UserEntity? + suspend fun findById(userId: UUID): UserEntity? @Query("DELETE FROM users") - fun deleteAll() + suspend fun deleteAll() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt index b18cc06f0f..8e011bcbcb 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt @@ -155,7 +155,7 @@ class ChartsViewModel @Inject constructor( _categoryExpenseCount.value = categoryExpenseCount.loadCategoryValue( period = period, category = category, - calculateValue = { range -> + calculateValue = { range -> walletCategoryLogic.historyByCategory( category = category, range = range @@ -200,7 +200,7 @@ class ChartsViewModel @Inject constructor( private suspend fun StateFlow>.loadCategoryValue( period: ChartPeriod, category: Category, - calculateValue: (range: FromToTimeRange) -> Double + calculateValue: suspend (range: FromToTimeRange) -> Double ): List { TODO() // val values = ioThread { diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt index ececf3fe25..cd8f598ef9 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt @@ -143,7 +143,7 @@ fun LazyItemScope.TransactionCard( amount = transaction.amount.toDouble() ) - if (transaction.type == TransactionType.TRANSFER && transaction.toAmount != null && toAccountCurrency != transactionCurrency) { + if (transaction.type == TransactionType.TRANSFER && toAccountCurrency != transactionCurrency) { Text( modifier = Modifier.padding(start = 68.dp), text = "${transaction.toAmount.toDouble().format(2)} $toAccountCurrency", diff --git a/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt b/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt index dc72f5bdf5..23d674e7a0 100644 --- a/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt @@ -284,6 +284,9 @@ fun DependencyHandler.Coroutines( //URL: https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-play-services implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$version") + + //URL: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/ + androidTestImplementation ("org.jetbrains.kotlinx:kotlinx-coroutines-test:$version") } fun DependencyHandler.ThirdParty() { diff --git a/ivy-fp/src/main/java/com/ivy/fp/Composition.kt b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt index 684c40b766..5e57f85277 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/Composition.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt @@ -23,6 +23,11 @@ annotation class Partial(val inCaseOf: String = "") @MustBeDocumented annotation class SideEffect +infix fun (suspend (A) -> B).then(f: suspend (B) -> C): suspend (A) -> C = { a -> + val b = this(a) + f(b) +} + infix fun ((A) -> B).then(f: (B) -> C): (A) -> C = { a -> val b = this(a) f(b)