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

Commit

Permalink
WIP: Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 24, 2022
1 parent d9402d5 commit 208827e
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 87 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ivy.wallet.domain.action.loan

import com.ivy.fp.action.FPAction
import com.ivy.wallet.domain.data.core.Loan
import com.ivy.wallet.io.persistence.dao.LoanDao
import java.util.*
import javax.inject.Inject

class LoanByIdAct @Inject constructor(
private val loanDao: LoanDao
) : FPAction<UUID, Loan?>() {
override suspend fun UUID.compose(): suspend () -> Loan? = suspend {
loanDao.findById(this)?.toDomain()
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ivy.wallet.domain.action.loan

import com.ivy.fp.action.FPAction
import com.ivy.fp.action.thenMap
import com.ivy.wallet.domain.data.core.Loan
import com.ivy.wallet.io.persistence.dao.LoanDao
import javax.inject.Inject

class LoansAct @Inject constructor(
private val loanDao: LoanDao
) : FPAction<Unit, List<Loan>>() {
override suspend fun Unit.compose(): suspend () -> List<Loan> = suspend {
loanDao.findAll()
} thenMap { it.toDomain() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package com.ivy.wallet.domain.action.viewmodel.home
import arrow.core.nonEmptyListOf
import arrow.core.toOption
import com.ivy.fp.action.FPAction
import com.ivy.fp.action.then
import com.ivy.fp.action.thenMap
import com.ivy.wallet.domain.action.ExchangeAct
import com.ivy.wallet.domain.action.account.AccTrnsAct
import com.ivy.wallet.domain.action.exchange.ExchangeAct
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.pure.ExchangeData
import com.ivy.wallet.domain.pure.account.filterExcluded
import com.ivy.wallet.domain.pure.data.ClosedTimeRange
import com.ivy.wallet.domain.pure.data.IncomeExpensePair
import com.ivy.wallet.domain.pure.exchange.ExchangeData
import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions
import com.ivy.wallet.domain.pure.transaction.foldTransactions
import com.ivy.wallet.domain.pure.util.orZero
import java.math.BigDecimal
import javax.inject.Inject

Expand Down
25 changes: 12 additions & 13 deletions app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import com.ivy.wallet.domain.action.charts.BalanceChartAct
import com.ivy.wallet.domain.action.settings.BaseCurrencyAct
import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.logic.WalletCategoryLogic
import com.ivy.wallet.domain.deprecated.logic.WalletCategoryLogic
import com.ivy.wallet.domain.pure.charts.ChartPeriod
import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint
import com.ivy.wallet.domain.pure.charts.SingleChartPoint
import com.ivy.wallet.domain.pure.charts.incomeExpenseChart
import com.ivy.wallet.domain.pure.data.WalletDAOs
import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode
import com.ivy.wallet.io.persistence.dao.CategoryDao
import com.ivy.wallet.io.persistence.dao.SettingsDao
import com.ivy.wallet.ui.onboarding.model.FromToTimeRange
Expand Down Expand Up @@ -75,7 +74,7 @@ class ChartsViewModel @Inject constructor(

fun start() {
viewModelScope.launch {
_baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) }
// _baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) }

walletCharts(period = period.value)
}
Expand Down Expand Up @@ -137,16 +136,16 @@ class ChartsViewModel @Inject constructor(
period: ChartPeriod,
category: Category
) {
_categoryExpenseValues.value = categoryExpenseValues.loadCategoryValue(
period = period,
category = category,
calculateValue = { range ->
walletCategoryLogic.calculateCategoryExpenses(
category = category,
range = range
).absoluteValue
}
)
// _categoryExpenseValues.value = categoryExpenseValues.loadCategoryValue(
// period = period,
// category = category,
// calculateValue = { range ->
// walletCategoryLogic.calculateCategoryExpenses(
// category = category,
// range = range
// ).absoluteValue
// }
// )
}

private suspend fun loadCategoryExpenseCount(
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.design.navigation.Navigation
import com.ivy.wallet.domain.logic.csv.CSVImporter
import com.ivy.wallet.domain.logic.csv.CSVMapper
import com.ivy.wallet.domain.logic.csv.CSVNormalizer
import com.ivy.wallet.domain.logic.csv.IvyFileReader
import com.ivy.wallet.domain.logic.csv.model.ImportResult
import com.ivy.wallet.domain.logic.csv.model.ImportType
import com.ivy.wallet.domain.logic.zip.ExportZipLogic
import com.ivy.wallet.domain.deprecated.logic.csv.CSVImporter
import com.ivy.wallet.domain.deprecated.logic.csv.CSVMapper
import com.ivy.wallet.domain.deprecated.logic.csv.CSVNormalizer
import com.ivy.wallet.domain.deprecated.logic.csv.IvyFileReader
import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult
import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType
import com.ivy.wallet.domain.deprecated.logic.zip.ExportZipLogic
import com.ivy.wallet.ui.Import
import com.ivy.wallet.ui.IvyWalletCtx
import com.ivy.wallet.ui.onboarding.viewmodel.OnboardingViewModel
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package com.ivy.wallet.ui.loan

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.wallet.domain.action.account.AccountsAct
import com.ivy.wallet.domain.action.category.CategoriesAct
import com.ivy.wallet.domain.action.loan.LoansAct
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Loan
import com.ivy.wallet.domain.deprecated.logic.AccountCreator
import com.ivy.wallet.domain.deprecated.logic.LoanCreator
import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic
import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData
import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData
import com.ivy.wallet.domain.deprecated.sync.item.LoanSync
import com.ivy.wallet.domain.event.AccountsUpdatedEvent
import com.ivy.wallet.domain.logic.AccountCreator
import com.ivy.wallet.domain.logic.LoanCreator
import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic
import com.ivy.wallet.domain.logic.model.CreateAccountData
import com.ivy.wallet.domain.logic.model.CreateLoanData
import com.ivy.wallet.domain.sync.item.LoanSync
import com.ivy.wallet.io.persistence.SharedPrefs
import com.ivy.wallet.io.persistence.dao.AccountDao
import com.ivy.wallet.io.persistence.dao.LoanDao
Expand Down Expand Up @@ -42,7 +45,10 @@ class LoanViewModel @Inject constructor(
private val sharedPrefs: SharedPrefs,
private val accountDao: AccountDao,
private val accountCreator: AccountCreator,
private val loanTransactionsLogic: LoanTransactionsLogic
private val loanTransactionsLogic: LoanTransactionsLogic,
private val loansAct: LoansAct,
private val accountsAct: AccountsAct,
private val categoriesAct: CategoriesAct
) : ViewModel() {

private val _baseCurrencyCode = MutableStateFlow(getDefaultFIATCurrency().currencyCode)
Expand Down Expand Up @@ -75,7 +81,7 @@ class LoanViewModel @Inject constructor(
initialiseAccounts()

_loans.value = ioThread {
loanDao.findAll()
loansAct(Unit)
.map { loan ->
val amountPaid = calculateAmountPaid(loan)
val loanAmount = loan.amount
Expand Down Expand Up @@ -111,7 +117,7 @@ class LoanViewModel @Inject constructor(
}

private suspend fun initialiseAccounts() {
val accounts = ioThread { accountDao.findAll() }
val accounts = accountsAct(Unit)
_accounts.value = accounts
_selectedAccount.value = defaultAccountId(accounts)
_selectedAccount.value?.let {
Expand Down Expand Up @@ -142,7 +148,7 @@ class LoanViewModel @Inject constructor(
ioThread {
newOrder.forEachIndexed { index, item ->
loanDao.save(
item.loan.copy(
item.loan.toEntity().copy(
orderNum = index.toDouble(),
isSynced = false
)
Expand All @@ -165,7 +171,7 @@ class LoanViewModel @Inject constructor(

accountCreator.createAccount(data) {
EventBus.getDefault().post(AccountsUpdatedEvent())
_accounts.value = ioThread { accountDao.findAll() }!!
_accounts.value = accountsAct(Unit)
_state.value = state.value.copy(accounts = _accounts.value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package com.ivy.wallet.ui.loandetails
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.design.navigation.Navigation
import com.ivy.wallet.domain.action.account.AccountsAct
import com.ivy.wallet.domain.action.loan.LoanByIdAct
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Loan
import com.ivy.wallet.domain.data.core.LoanRecord
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.deprecated.logic.AccountCreator
import com.ivy.wallet.domain.deprecated.logic.LoanCreator
import com.ivy.wallet.domain.deprecated.logic.LoanRecordCreator
import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic
import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData
import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData
import com.ivy.wallet.domain.deprecated.logic.model.EditLoanRecordData
import com.ivy.wallet.domain.event.AccountsUpdatedEvent
import com.ivy.wallet.domain.logic.AccountCreator
import com.ivy.wallet.domain.logic.LoanCreator
import com.ivy.wallet.domain.logic.LoanRecordCreator
import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic
import com.ivy.wallet.domain.logic.model.CreateAccountData
import com.ivy.wallet.domain.logic.model.CreateLoanRecordData
import com.ivy.wallet.domain.logic.model.EditLoanRecordData
import com.ivy.wallet.io.persistence.dao.*
import com.ivy.wallet.ui.IvyWalletCtx
import com.ivy.wallet.ui.LoanDetails
Expand Down Expand Up @@ -42,7 +44,9 @@ class LoanDetailsViewModel @Inject constructor(
private val accountDao: AccountDao,
private val accountCreator: AccountCreator,
private val loanTransactionsLogic: LoanTransactionsLogic,
private val nav: Navigation
private val nav: Navigation,
private val accountsAct: AccountsAct,
private val loanByIdAct: LoanByIdAct
) : ViewModel() {

private val _baseCurrency = MutableStateFlow("")
Expand Down Expand Up @@ -87,13 +91,9 @@ class LoanDetailsViewModel @Inject constructor(
_baseCurrency.value = it
}

_accounts.value = ioThread {
accountDao.findAll()
}
_accounts.value = accountsAct(Unit)

_loan.value = ioThread {
loanDao.findById(id = loanId)
}
_loan.value = loanByIdAct(loanId)

loan.value?.let { loan ->
_selectedLoanAccount.value = accounts.value.find {
Expand All @@ -120,7 +120,7 @@ class LoanDetailsViewModel @Inject constructor(
)

DisplayLoanRecord(
it,
it.toDomain(),
account = account,
loanRecordTransaction = trans != null,
loanRecordCurrencyCode = account?.currency ?: defaultCurrencyCode,
Expand Down Expand Up @@ -148,7 +148,7 @@ class LoanDetailsViewModel @Inject constructor(
}

associatedTransaction = ioThread {
transactionDao.findLoanTransaction(loanId = loan.value!!.id)
transactionDao.findLoanTransaction(loanId = loan.value!!.id)?.toDomain()
}

associatedTransaction?.let {
Expand Down Expand Up @@ -296,7 +296,7 @@ class LoanDetailsViewModel @Inject constructor(

accountCreator.createAccount(data) {
EventBus.getDefault().post(AccountsUpdatedEvent())
_accounts.value = ioThread { accountDao.findAll() }
_accounts.value = accountsAct(Unit)
}

TestIdlingResource.decrement()
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.design.navigation.Navigation
import com.ivy.wallet.domain.deprecated.logic.AccountCreator
import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData
import com.ivy.wallet.domain.deprecated.sync.IvySync
import com.ivy.wallet.domain.event.AccountsUpdatedEvent
import com.ivy.wallet.domain.logic.AccountCreator
import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.logic.model.CreateAccountData
import com.ivy.wallet.domain.sync.IvySync
import com.ivy.wallet.io.persistence.dao.SettingsDao
import com.ivy.wallet.ui.IvyWalletCtx
import com.ivy.wallet.ui.Main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.design.l0_system.Theme
import com.ivy.design.navigation.Navigation
import com.ivy.wallet.domain.action.account.AccountsAct
import com.ivy.wallet.domain.action.category.CategoriesAct
import com.ivy.wallet.domain.data.IvyCurrency
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.data.core.Settings
import com.ivy.wallet.domain.logic.*
import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.logic.model.CreateAccountData
import com.ivy.wallet.domain.logic.model.CreateCategoryData
import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic
import com.ivy.wallet.domain.sync.IvySync
import com.ivy.wallet.domain.deprecated.logic.*
import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData
import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData
import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic
import com.ivy.wallet.domain.deprecated.sync.IvySync
import com.ivy.wallet.io.network.FCMClient
import com.ivy.wallet.io.network.IvyAnalytics
import com.ivy.wallet.io.network.IvySession
Expand Down Expand Up @@ -48,6 +50,9 @@ class OnboardingViewModel @Inject constructor(
private val categoryDao: CategoryDao,
private val accountCreator: AccountCreator,

private val accountsAct: AccountsAct,
private val categoriesAct: CategoriesAct,

//Only OnboardingRouter stuff
sharedPrefs: SharedPrefs,
ivySync: IvySync,
Expand Down Expand Up @@ -133,8 +138,8 @@ class OnboardingViewModel @Inject constructor(
theme = if (isSystemDarkMode) Theme.DARK else Theme.LIGHT,
name = "",
baseCurrency = defaultCurrency.code,
bufferAmount = 1000.0
)
bufferAmount = 1000.0.toBigDecimal()
).toEntity()
)
}

Expand Down Expand Up @@ -283,15 +288,13 @@ class OnboardingViewModel @Inject constructor(
}
}

private suspend fun accountsWithBalance(): List<AccountBalance> = ioThread {
accountDao.findAll()
.map {
AccountBalance(
account = it,
balance = accountLogic.calculateAccountBalance(it)
)
}
}
private suspend fun accountsWithBalance(): List<AccountBalance> = accountsAct(Unit)
.map {
AccountBalance(
account = it,
balance = accountLogic.calculateAccountBalance(it)
)
}

fun onAddAccountsDone() {
viewModelScope.launch {
Expand Down Expand Up @@ -320,7 +323,7 @@ class OnboardingViewModel @Inject constructor(
TestIdlingResource.increment()

categoryCreator.editCategory(updatedCategory) {
_categories.value = ioThread { categoryDao.findAll() }!!
_categories.value = categoriesAct(Unit)!!
}

TestIdlingResource.decrement()
Expand All @@ -332,7 +335,7 @@ class OnboardingViewModel @Inject constructor(
TestIdlingResource.increment()

categoryCreator.createCategory(data) {
_categories.value = ioThread { categoryDao.findAll() }!!
_categories.value = categoriesAct(Unit)!!
}

TestIdlingResource.decrement()
Expand Down
Loading

0 comments on commit 208827e

Please sign in to comment.