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 34605f9 commit d9402d5
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ivy.wallet.domain.action.category

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

class CategoryByIdAct @Inject constructor(
private val categoryDao: CategoryDao
) : FPAction<UUID, Category?>() {
override suspend fun UUID.compose(): suspend () -> Category? = suspend {
categoryDao.findById(this)?.toDomain()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ivy.wallet.domain.action.transaction

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

class TrnByIdAct @Inject constructor(
private val transactionDao: TransactionDao
) : FPAction<UUID, Transaction?>() {
override suspend fun UUID.compose(): suspend () -> Transaction? = suspend {
this //transactionId
} then transactionDao::findById then {
it?.toDomain()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -24,7 +23,7 @@ import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.wallet.R
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.logic.model.CreateCategoryData
import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData
import com.ivy.wallet.ui.Categories
import com.ivy.wallet.ui.ItemStatistic
import com.ivy.wallet.ui.IvyWalletPreview
Expand All @@ -43,8 +42,8 @@ import com.ivy.wallet.utils.onScreenStart
fun BoxWithConstraintsScope.CategoriesScreen(screen: Categories) {
val viewModel: CategoriesViewModel = viewModel()

val currency by viewModel.currency.observeAsState("")
val categories by viewModel.categories.observeAsState(emptyList())
val currency by viewModel.currency.collectAsState()
val categories by viewModel.categories.collectAsState()

onScreenStart {
viewModel.start()
Expand Down
33 changes: 18 additions & 15 deletions app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.ivy.wallet.ui.category

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.wallet.domain.logic.CategoryCreator
import com.ivy.wallet.domain.logic.WalletCategoryLogic
import com.ivy.wallet.domain.logic.model.CreateCategoryData
import com.ivy.wallet.domain.sync.item.CategorySync
import com.ivy.wallet.domain.action.category.CategoriesAct
import com.ivy.wallet.domain.action.settings.BaseCurrencyAct
import com.ivy.wallet.domain.deprecated.logic.CategoryCreator
import com.ivy.wallet.domain.deprecated.logic.WalletCategoryLogic
import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData
import com.ivy.wallet.domain.deprecated.sync.item.CategorySync
import com.ivy.wallet.io.persistence.dao.CategoryDao
import com.ivy.wallet.io.persistence.dao.SettingsDao
import com.ivy.wallet.ui.IvyWalletCtx
import com.ivy.wallet.ui.onboarding.model.TimePeriod
import com.ivy.wallet.utils.TestIdlingResource
import com.ivy.wallet.utils.asLiveData
import com.ivy.wallet.utils.ioThread
import com.ivy.wallet.utils.readOnly
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -25,14 +27,16 @@ class CategoriesViewModel @Inject constructor(
private val categoryLogic: WalletCategoryLogic,
private val categorySync: CategorySync,
private val categoryCreator: CategoryCreator,
private val ivyContext: IvyWalletCtx
private val categoriesAct: CategoriesAct,
private val ivyContext: IvyWalletCtx,
private val baseCurrencyAct: BaseCurrencyAct
) : ViewModel() {

private val _currency = MutableLiveData<String>()
val currency = _currency.asLiveData()
private val _currency = MutableStateFlow("")
val currency = _currency.readOnly()

private val _categories = MutableLiveData<List<CategoryData>>()
val categories = _categories.asLiveData()
private val _categories = MutableStateFlow<List<CategoryData>>(emptyList())
val categories = _categories.readOnly()

fun start() {
viewModelScope.launch {
Expand All @@ -42,11 +46,10 @@ class CategoriesViewModel @Inject constructor(
startDayOfMonth = ivyContext.startDayOfMonth
).toRange(ivyContext.startDayOfMonth) //this must be monthly

_currency.value = ioThread { settingsDao.findFirst().currency }!!
_currency.value = baseCurrencyAct(Unit)

_categories.value = ioThread {
categoryDao
.findAll()
categoriesAct(Unit)
.map {
CategoryData(
category = it,
Expand Down Expand Up @@ -77,7 +80,7 @@ class CategoriesViewModel @Inject constructor(
ioThread {
newOrder.forEachIndexed { index, categoryData ->
categoryDao.save(
categoryData.category.copy(
categoryData.category.toEntity().copy(
orderNum = index.toDouble(),
isSynced = false
)
Expand Down
34 changes: 19 additions & 15 deletions app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.ivy.wallet.domain.data.CustomExchangeRateState
import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.logic.model.CreateAccountData
import com.ivy.wallet.domain.logic.model.CreateCategoryData
import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData
import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData
import com.ivy.wallet.ui.EditPlanned
import com.ivy.wallet.ui.EditTransaction
import com.ivy.wallet.ui.IvyWalletPreview
Expand All @@ -54,24 +54,24 @@ fun BoxWithConstraintsScope.EditTransactionScreen(screen: EditTransaction) {
val viewModel: EditTransactionViewModel = viewModel()

val transactionType by viewModel.transactionType.observeAsState(screen.type)
val initialTitle by viewModel.initialTitle.observeAsState()
val initialTitle by viewModel.initialTitle.collectAsState()
val titleSuggestions by viewModel.titleSuggestions.collectAsState()
val currency by viewModel.currency.observeAsState("")
val description by viewModel.description.observeAsState()
val dateTime by viewModel.dateTime.observeAsState()
val category by viewModel.category.observeAsState()
val account by viewModel.account.observeAsState()
val toAccount by viewModel.toAccount.observeAsState()
val dueDate by viewModel.dueDate.observeAsState()
val amount by viewModel.amount.observeAsState(0.0)
val currency by viewModel.currency.collectAsState()
val description by viewModel.description.collectAsState()
val dateTime by viewModel.dateTime.collectAsState()
val category by viewModel.category.collectAsState()
val account by viewModel.account.collectAsState()
val toAccount by viewModel.toAccount.collectAsState()
val dueDate by viewModel.dueDate.collectAsState()
val amount by viewModel.amount.collectAsState()
val loanData by viewModel.displayLoanHelper.collectAsState()
val backgroundProcessing by viewModel.backgroundProcessingStarted.collectAsState()
val customExchangeRateState by viewModel.customExchangeRateState.collectAsState()

val categories by viewModel.categories.observeAsState(emptyList())
val accounts by viewModel.accounts.observeAsState(emptyList())
val categories by viewModel.categories.collectAsState(emptyList())
val accounts by viewModel.accounts.collectAsState(emptyList())

val hasChanges by viewModel.hasChanges.observeAsState(false)
val hasChanges by viewModel.hasChanges.collectAsState(false)

onScreenStart {
viewModel.start(screen)
Expand Down Expand Up @@ -387,7 +387,11 @@ private fun BoxWithConstraintsScope.UI(
}
} else {
//no changes, pay
ModalCheck(label = if (transactionType == TransactionType.EXPENSE) stringResource(R.string.pay) else stringResource(R.string.get)) {
ModalCheck(
label = if (transactionType == TransactionType.EXPENSE) stringResource(
R.string.pay
) else stringResource(R.string.get)
) {
onPayPlannedPayment()
}
}
Expand Down
Loading

0 comments on commit d9402d5

Please sign in to comment.