mirror of
https://github.com/andwati/ledga.git
synced 2026-10-18 03:12:55 +00:00
v1.5.1: add 3 Months period to Home spending filter
This commit is contained in:
@@ -27,8 +27,8 @@ android {
|
||||
applicationId = "com.ledga.app"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 18
|
||||
versionName = "1.5.0"
|
||||
versionCode = 19
|
||||
versionName = "1.5.1"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import androidx.compose.ui.unit.dp
|
||||
enum class Period(val label: String) {
|
||||
TODAY("Today"),
|
||||
THIS_WEEK("This Week"),
|
||||
THIS_MONTH("Month")
|
||||
THIS_MONTH("Month"),
|
||||
LAST_3_MONTHS("3 Months")
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -177,6 +177,7 @@ fun HomeScreen(
|
||||
Period.TODAY -> "SPENT TODAY"
|
||||
Period.THIS_WEEK -> "SPENT THIS WEEK"
|
||||
Period.THIS_MONTH -> "SPENT THIS MONTH"
|
||||
Period.LAST_3_MONTHS -> "SPENT IN 3 MONTHS"
|
||||
}
|
||||
Text(
|
||||
text = overlineLabel,
|
||||
|
||||
@@ -192,6 +192,7 @@ class HomeViewModel @Inject constructor(
|
||||
Period.TODAY -> DateUtils.getStartOfDay(now)
|
||||
Period.THIS_WEEK -> DateUtils.getStartOfWeek(now)
|
||||
Period.THIS_MONTH -> DateUtils.getStartOfMonth(now)
|
||||
Period.LAST_3_MONTHS -> DateUtils.getStartOf3MonthsAgo(now)
|
||||
}
|
||||
flowOf(start to now)
|
||||
}
|
||||
|
||||
@@ -90,6 +90,18 @@ object DateUtils {
|
||||
}.timeInMillis
|
||||
}
|
||||
|
||||
/** Start of the day three calendar months back — for the "3 Months" period. */
|
||||
fun getStartOf3MonthsAgo(timestamp: Long = System.currentTimeMillis()): Long {
|
||||
return Calendar.getInstance().apply {
|
||||
timeInMillis = timestamp
|
||||
add(Calendar.MONTH, -3)
|
||||
set(Calendar.HOUR_OF_DAY, 0)
|
||||
set(Calendar.MINUTE, 0)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
}.timeInMillis
|
||||
}
|
||||
|
||||
private fun isSameDay(a: Calendar, b: Calendar): Boolean {
|
||||
return a.get(Calendar.YEAR) == b.get(Calendar.YEAR) &&
|
||||
a.get(Calendar.DAY_OF_YEAR) == b.get(Calendar.DAY_OF_YEAR)
|
||||
|
||||
Reference in New Issue
Block a user