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

Commit

Permalink
Merge pull request #410 from Vishwa-Raghavendra/fix-issue-358
Browse files Browse the repository at this point in the history
Bug-Fix #358 : Fixed Previous month transactions disappearing
  • Loading branch information
ILIYANGERMANOV authored Jan 9, 2022
2 parents 42161be + fb72c1d commit f49693e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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
import java.time.LocalDateTime

data class TimePeriod(
val month: Month? = null,
val year: Int? = null,
val fromToRange: FromToTimeRange? = null,
val lastNRange: LastNTimeRange? = null,
) {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,19 +143,21 @@ 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!!
)
}
}

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!!
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -316,21 +313,23 @@ 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
)
}
}

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
)
}
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f49693e

Please sign in to comment.