diff --git a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt index 155ff7996e..8a5b8ee07d 100644 --- a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.base.asLiveData +import com.ivy.wallet.base.dateNowUTC import com.ivy.wallet.base.ioThread import com.ivy.wallet.logic.PlannedPaymentsLogic import com.ivy.wallet.logic.WalletLogic @@ -62,18 +63,20 @@ class BalanceViewModel @Inject constructor( fun nextMonth() { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { start( - period = month.incrementMonthPeriod(ivyContext, 1L), + period = month.incrementMonthPeriod(ivyContext, 1L, year = year), ) } } fun previousMonth() { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { start( - period = month.incrementMonthPeriod(ivyContext, -1L), + period = month.incrementMonthPeriod(ivyContext, -1L, year = year), ) } } diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 18df055e54..10abe69fa5 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.base.TestIdlingResource import com.ivy.wallet.base.asLiveData +import com.ivy.wallet.base.dateNowUTC import com.ivy.wallet.base.ioThread import com.ivy.wallet.logic.CustomerJourneyLogic import com.ivy.wallet.logic.PlannedPaymentsLogic @@ -275,18 +276,20 @@ class HomeViewModel @Inject constructor( fun nextMonth() { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { load( - period = month.incrementMonthPeriod(ivyContext, 1L), + period = month.incrementMonthPeriod(ivyContext, 1L, year = year), ) } } fun previousMonth() { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { load( - period = month.incrementMonthPeriod(ivyContext, -1L), + period = month.incrementMonthPeriod(ivyContext, -1L, year = year), ) } } diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/TimePeriod.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/TimePeriod.kt index a21c906594..f2f82ab4f3 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/TimePeriod.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/TimePeriod.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.ui.onboarding.model +import android.util.Log import com.ivy.wallet.base.* import com.ivy.wallet.ui.theme.modal.model.Month import java.time.LocalDate @@ -7,6 +8,7 @@ import java.time.LocalDateTime data class TimePeriod( val month: Month? = null, + val year: Int? = null, val fromToRange: FromToTimeRange? = null, val lastNRange: LastNTimeRange? = null, ) { @@ -54,7 +56,7 @@ data class TimePeriod( ): FromToTimeRange { return when { month != null -> { - val date = month.toDate() + val date = if (year!=null) month.toDate().withYear(year) else month.toDate() val (from, to) = if (startDateOfMonth != 1) { customStartDayOfMonthPeriodRange( date = date, diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt index b958682354..3a0d6c8f12 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.base.asLiveData +import com.ivy.wallet.base.dateNowUTC import com.ivy.wallet.base.ioThread import com.ivy.wallet.logic.WalletCategoryLogic import com.ivy.wallet.logic.WalletLogic @@ -142,9 +143,10 @@ class PieChartStatisticViewModel @Inject constructor( fun nextMonth() { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { load( - period = month.incrementMonthPeriod(ivyContext, 1L), + period = month.incrementMonthPeriod(ivyContext, 1L,year), type = type.value!! ) } @@ -152,9 +154,10 @@ class PieChartStatisticViewModel @Inject constructor( fun previousMonth() { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { load( - period = month.incrementMonthPeriod(ivyContext, -1L), + period = month.incrementMonthPeriod(ivyContext, -1L,year), type = type.value!! ) } diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt index 8d5c1ce7f5..f4ee5fe15e 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt @@ -3,10 +3,7 @@ package com.ivy.wallet.ui.statistic.level2 import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.base.TestIdlingResource -import com.ivy.wallet.base.asLiveData -import com.ivy.wallet.base.ioThread -import com.ivy.wallet.base.isNotNullOrBlank +import com.ivy.wallet.base.* import com.ivy.wallet.logic.* import com.ivy.wallet.logic.currency.ExchangeRatesLogic import com.ivy.wallet.model.TransactionHistoryItem @@ -316,10 +313,11 @@ class ItemStatisticViewModel @Inject constructor( fun nextMonth(screen: Screen.ItemStatistic) { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { start( screen = screen, - period = month.incrementMonthPeriod(ivyContext, 1L), + period = month.incrementMonthPeriod(ivyContext, 1L,year), reset = false ) } @@ -327,10 +325,11 @@ class ItemStatisticViewModel @Inject constructor( fun previousMonth(screen: Screen.ItemStatistic) { val month = period.value?.month + val year = period.value?.year ?: dateNowUTC().year if (month != null) { start( screen = screen, - period = month.incrementMonthPeriod(ivyContext, -1L), + period = month.incrementMonthPeriod(ivyContext, -1L,year), reset = false ) } diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt index 1ed1f3f487..4cf1056843 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.ui.theme.modal.model +import android.util.Log import com.ivy.wallet.base.dateNowUTC import com.ivy.wallet.ui.IvyContext import com.ivy.wallet.ui.onboarding.model.TimePeriod @@ -34,10 +35,15 @@ data class Month( .withMonth(monthValue) - fun incrementMonthPeriod(ivyContext: IvyContext, increment: Long): TimePeriod { - val incrementedMonth = toDate().plusMonths(increment) + fun incrementMonthPeriod( + ivyContext: IvyContext, + increment: Long, + year: Int + ): TimePeriod { + val incrementedMonth = toDate().withYear(year).plusMonths(increment) val incrementedPeriod = TimePeriod( - month = fromMonthValue(incrementedMonth.monthValue) + month = fromMonthValue(incrementedMonth.monthValue), + year = incrementedMonth.year ) ivyContext.updateSelectedPeriodInMemory(incrementedPeriod) return incrementedPeriod