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

Commit

Permalink
Refactor HomeViewModel.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 14, 2022
1 parent e4545ba commit 76b24d6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ivy.design.l0_system.Theme
import com.ivy.design.navigation.Navigation
import com.ivy.fp.action.fixUnit
import com.ivy.fp.action.then
import com.ivy.fp.action.thenFinishWith
import com.ivy.fp.viewmodel.FRPViewModel
import com.ivy.wallet.domain.action.account.AccountsAct
import com.ivy.wallet.domain.action.category.CategoriesAct
Expand Down Expand Up @@ -64,21 +65,21 @@ class HomeViewModel @Inject constructor(
override suspend fun handleEvent(event: HomeEvent): suspend () -> HomeState = when (event) {
HomeEvent.Start -> start()
HomeEvent.BalanceClick -> onBalanceClick()
is HomeEvent.DismissCustomerJourneyCard -> dismissCustomerJourneyCard(event.card)
HomeEvent.HiddenBalanceClick -> onHiddenBalanceClick()
is HomeEvent.PayOrGetPlanned -> payOrGetPlanned(event.transaction)
is HomeEvent.SkipPlanned -> skipPlanned(event.transaction)
is HomeEvent.SetPeriod -> setPeriod(event.period)
HomeEvent.SelectNextMonth -> nextMonth()
HomeEvent.SelectPreviousMonth -> previousMonth()
is HomeEvent.SetUpcomingExpanded -> setUpcomingExpanded(event.expanded)
is HomeEvent.SetOverdueExpanded -> setOverdueExpanded(event.expanded)
is HomeEvent.SetBuffer -> setBuffer(event.buffer).fixUnit()
is HomeEvent.SetCurrency -> setCurrency(event.currency).fixUnit()
HomeEvent.SwitchTheme -> switchTheme().fixUnit()
is HomeEvent.SetUpcomingExpanded -> setUpcomingExpanded(event.expanded)
is HomeEvent.SetOverdueExpanded -> setOverdueExpanded(event.expanded)
is HomeEvent.SetPeriod -> setPeriod(event.period)
is HomeEvent.DismissCustomerJourneyCard -> dismissCustomerJourneyCard(event.card)
}

suspend fun start(): suspend () -> HomeState =
private suspend fun start(): suspend () -> HomeState =
suspend {
val startDay = startDayOfMonthAct(Unit)
ivyContext.initSelectedPeriodInMemory(
Expand All @@ -88,7 +89,7 @@ class HomeViewModel @Inject constructor(

private suspend fun reload(
period: TimePeriod = ivyContext.selectedPeriod
): HomeState = (suspend {
): HomeState = suspend {
val settings = settingsAct(Unit)
val hideCurrentBalance = shouldHideBalanceAct(Unit)
Triple(period, settings, hideCurrentBalance)
Expand Down Expand Up @@ -192,13 +193,13 @@ class HomeViewModel @Inject constructor(
overdueTrns = result.overdueTrns
)
}
} then {
} thenFinishWith {
updateState {
it.copy(
customerJourneyCards = ioThread { customerJourneyLogic.loadCards() }
)
}
}).invoke()
}

private fun loadNewTheme(theme: Theme) {
ivyContext.switchTheme(theme = theme)
Expand Down

0 comments on commit 76b24d6

Please sign in to comment.