Skip to content

Commit 9a97fc6

Browse files
committed
Remove past and future Habit Statuses
- Removed Skipped status because NotDue status means the same - Removed FutureDateAlreadyCompleted and PastDateAlreadyCompleted because their essence is the same - The information about the date being future or past is conveyed through isPastDate field in CalendarDateData
1 parent c10c331 commit 9a97fc6

File tree

7 files changed

+29
-43
lines changed

7 files changed

+29
-43
lines changed

core/domain/src/main/java/com/rendox/routinetracker/core/domain/completion_history/HabitStatusComputerImpl.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class HabitStatusComputerImpl : HabitStatusComputer {
1919
*
2020
* The result also depends on whether the validation date is in the past or in the future. For
2121
* example, when the habit has some backlog, but the validation date is in the past, the invoke
22-
* function will return not [HabitStatus.Backlog], but [HabitStatus.Skipped] instead. That's because
22+
* function will return not [HabitStatus.Backlog], but [HabitStatus.NotDue] instead. That's because
2323
* the user deliberately chose to skip the habit on that day. Nonetheless, if the validation date is
2424
* in the future, the invoke function will return [HabitStatus.Backlog] so that the user can adjust
2525
* their schedule to sort out this backlog later.
@@ -92,8 +92,7 @@ internal class HabitStatusComputerImpl : HabitStatusComputer {
9292
completionHistory = completionHistory,
9393
vacationHistory = vacationHistory,
9494
)
95-
if (alreadyCompleted && validationDate <= today) return HabitStatus.PastDateAlreadyCompleted
96-
if (alreadyCompleted && validationDate > today) return HabitStatus.FutureDateAlreadyCompleted
95+
if (alreadyCompleted) return HabitStatus.AlreadyCompleted
9796

9897
if (validationDate < today) {
9998
val wasCompletedLater = checkIfWasCompletedLater(
@@ -123,7 +122,7 @@ internal class HabitStatusComputerImpl : HabitStatusComputer {
123122
return HabitStatus.OverCompleted
124123
}
125124
if (habitIsOnVacationAtTheMomentOfValidationDate) return HabitStatus.OnVacation
126-
return if (validationDate <= today) HabitStatus.Skipped else HabitStatus.NotDue
125+
return HabitStatus.NotDue
127126
}
128127
}
129128

core/domain/src/test/java/com/rendox/routinetracker/core/domain/completion_history/HabitStatusComputerImplTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class HabitStatusComputerImplTest {
306306
),
307307
vacationHistory = emptyList(),
308308
)
309-
).isEqualTo(HabitStatus.PastDateAlreadyCompleted)
309+
).isEqualTo(HabitStatus.AlreadyCompleted)
310310
}
311311

312312
@ParameterizedTest
@@ -466,8 +466,8 @@ class HabitStatusComputerImplTest {
466466
)
467467
}
468468
val expectedStatuses = listOf(
469-
HabitStatus.FutureDateAlreadyCompleted,
470-
HabitStatus.FutureDateAlreadyCompleted,
469+
HabitStatus.AlreadyCompleted,
470+
HabitStatus.AlreadyCompleted,
471471
)
472472
assertThat(resultingStatuses).containsExactlyElementsIn(expectedStatuses)
473473
}
@@ -528,7 +528,7 @@ class HabitStatusComputerImplTest {
528528
HabitStatus.NotDue,
529529
),
530530
arrayOf(
531-
"future date, already completed, assert status is FutureDateAlreadyCompleted",
531+
"future date, already completed, assert status is AlreadyCompleted",
532532
LocalDate(2023, 12, 13),
533533
LocalDate(2023, 12, 9),
534534
1F,
@@ -538,7 +538,7 @@ class HabitStatusComputerImplTest {
538538
LocalDate(2023, 12, 8),
539539
LocalDate(2023, 12, 9),
540540
),
541-
HabitStatus.FutureDateAlreadyCompleted,
541+
HabitStatus.AlreadyCompleted,
542542
),
543543
arrayOf(
544544
"past date, due, not completed, assert status is Failed",
@@ -599,7 +599,7 @@ class HabitStatusComputerImplTest {
599599
LocalDate(2023, 12, 8),
600600
LocalDate(2023, 12, 11),
601601
),
602-
HabitStatus.PastDateAlreadyCompleted,
602+
HabitStatus.AlreadyCompleted,
603603
),
604604
arrayOf(
605605
"over completed and sorted out backlog on 2023-12-13, assert CompletedLater on 2023-12-06",
@@ -631,7 +631,7 @@ class HabitStatusComputerImplTest {
631631
LocalDate(2023, 12, 18),
632632
5F,
633633
arrayOf(LocalDate(2023, 12, 13)),
634-
HabitStatus.PastDateAlreadyCompleted,
634+
HabitStatus.AlreadyCompleted,
635635
),
636636
arrayOf(
637637
"date before habit start date, assert status is NotStarted",
@@ -647,7 +647,7 @@ class HabitStatusComputerImplTest {
647647
LocalDate(2024, 1, 1),
648648
0F,
649649
emptyArray<LocalDate>(),
650-
HabitStatus.Skipped,
650+
HabitStatus.NotDue,
651651
),
652652
)
653653
}

core/model/src/main/java/com/rendox/routinetracker/core/model/HabitStatus.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,11 @@ enum class HabitStatus {
1313
/** The habit is not due on this day because of its frequency */
1414
NotDue,
1515

16-
/** The user didn't complete the day and didn't need to, because of the habit's frequency. */
17-
Skipped,
18-
1916
/**
2017
* Although the habit is due on this date, which is in the past, the user may skip it
2118
* because they had over completed one of the days earlier.
2219
*/
23-
PastDateAlreadyCompleted,
24-
25-
/**
26-
* Although the habit is due on this date, which is in the future, the user may skip it
27-
* because they had over completed one of the days earlier.
28-
*/
29-
FutureDateAlreadyCompleted,
20+
AlreadyCompleted,
3021

3122
/**
3223
* The routine was due but the user failed to complete it on that day.
@@ -76,9 +67,4 @@ val dueOrCompletedStatuses = listOf(
7667
HabitStatus.Completed,
7768
HabitStatus.OverCompleted,
7869
HabitStatus.SortedOutBacklog,
79-
)
80-
81-
val nonExistentStatuses = listOf(
82-
HabitStatus.NotStarted,
83-
HabitStatus.Finished,
8470
)

core/ui/src/main/java/com/rendox/routinetracker/core/ui/helpers/HabitStatusGetDisplayName.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ fun HabitStatus.getStringResourceId(): Int = when (this) {
77
HabitStatus.Planned -> R.string.habit_status_planned
88
HabitStatus.Backlog -> R.string.habit_status_backlog
99
HabitStatus.NotDue -> R.string.habit_status_not_due
10-
HabitStatus.Skipped -> R.string.habit_status_not_due
11-
HabitStatus.PastDateAlreadyCompleted -> R.string.habit_status_already_completed
12-
HabitStatus.FutureDateAlreadyCompleted -> R.string.habit_status_already_completed
10+
HabitStatus.AlreadyCompleted -> R.string.habit_status_already_completed
1311
HabitStatus.CompletedLater -> R.string.habit_status_completed_later
1412
HabitStatus.Completed -> R.string.habit_status_completed
1513
HabitStatus.PartiallyCompleted -> R.string.habit_status_partially_completed

feature/agenda/src/main/java/com/rendox/routinetracker/feature/agenda/AgendaList.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ private fun StatusCheckmark(
177177
}
178178

179179
HabitStatus.Planned, HabitStatus.OnVacation, HabitStatus.NotDue,
180-
HabitStatus.Backlog, HabitStatus.PastDateAlreadyCompleted,
181-
HabitStatus.FutureDateAlreadyCompleted, HabitStatus.CompletedLater,
182-
HabitStatus.NotStarted, HabitStatus.Finished, HabitStatus.Skipped -> {
180+
HabitStatus.Backlog, HabitStatus.AlreadyCompleted,
181+
HabitStatus.CompletedLater, HabitStatus.NotStarted, HabitStatus.Finished -> {
183182
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(8.dp)
184183
icon = null
185184
iconColor = null

feature/routine_details/src/main/java/com/rendox/routinetracker/routine_details/RoutineDetailsScreenViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class RoutineDetailsScreenViewModel(
138138
status = completionData.habitStatus,
139139
includedInStreak = streaksFlow.value.any { it.contains(date) },
140140
numOfTimesCompleted = completionData.numOfTimesCompleted,
141+
isPastDate = date <= todayFlow.value,
141142
)
142143
}
143144
_calendarDatesFlow.update {
@@ -209,5 +210,6 @@ data class CalendarDateData(
209210
val status: HabitStatus,
210211
val includedInStreak: Boolean,
211212
val numOfTimesCompleted: Float,
213+
val isPastDate: Boolean,
212214
)
213215

feature/routine_details/src/main/java/com/rendox/routinetracker/routine_details/calendar/RoutineCalendar.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fun RoutineCalendar(
5757
habitStatus = calendarDate?.status,
5858
includedInStreak = calendarDate?.includedInStreak ?: false,
5959
onClick = onDateClick,
60+
isPastDate = calendarDate?.isPastDate ?: false,
6061
)
6162
},
6263
)
@@ -68,6 +69,7 @@ private fun RoutineStatusDay(
6869
day: CalendarDay,
6970
habitStatus: HabitStatus?,
7071
includedInStreak: Boolean,
72+
isPastDate: Boolean,
7173
onClick: (date: LocalDate) -> Unit,
7274
) {
7375
val completedStroke = MaterialTheme.routineStatusColors.completedStroke
@@ -91,16 +93,14 @@ private fun RoutineStatusDay(
9193
null -> Color.Transparent
9294
HabitStatus.Planned -> pendingColor
9395
HabitStatus.Backlog -> pendingColor
94-
HabitStatus.PastDateAlreadyCompleted -> skippedBackground
95-
HabitStatus.FutureDateAlreadyCompleted -> Color.Transparent
96-
HabitStatus.NotDue -> Color.Transparent
96+
HabitStatus.AlreadyCompleted -> if (isPastDate) skippedBackground else Color.Transparent
97+
HabitStatus.NotDue -> if (isPastDate) skippedBackground else Color.Transparent
9798
HabitStatus.OnVacation -> MaterialTheme.routineStatusColors.vacationBackground
9899
HabitStatus.Failed -> failedBackground
99100
HabitStatus.Completed -> completedBackground
100101
HabitStatus.PartiallyCompleted -> completedBackground
101102
HabitStatus.OverCompleted -> completedBackground
102103
HabitStatus.SortedOutBacklog -> completedBackground
103-
HabitStatus.Skipped -> skippedBackground
104104
HabitStatus.CompletedLater -> skippedBackground
105105
HabitStatus.NotStarted -> Color.Transparent
106106
HabitStatus.Finished -> Color.Transparent
@@ -113,16 +113,14 @@ private fun RoutineStatusDay(
113113
null -> Color.Transparent
114114
HabitStatus.Planned -> pendingColor
115115
HabitStatus.Backlog -> pendingColor
116-
HabitStatus.PastDateAlreadyCompleted -> skippedStroke
117-
HabitStatus.FutureDateAlreadyCompleted -> Color.Transparent
118-
HabitStatus.NotDue -> Color.Transparent
116+
HabitStatus.AlreadyCompleted -> if (isPastDate) skippedStroke else Color.Transparent
117+
HabitStatus.NotDue -> if (isPastDate) skippedStroke else Color.Transparent
119118
HabitStatus.OnVacation -> MaterialTheme.routineStatusColors.vacationStroke
120119
HabitStatus.Failed -> failedStroke
121120
HabitStatus.Completed -> completedStroke
122121
HabitStatus.PartiallyCompleted -> completedStroke
123122
HabitStatus.OverCompleted -> completedStroke
124123
HabitStatus.SortedOutBacklog -> completedStroke
125-
HabitStatus.Skipped -> skippedStroke
126124
HabitStatus.CompletedLater -> skippedStroke
127125
HabitStatus.NotStarted -> Color.Transparent
128126
HabitStatus.Finished -> Color.Transparent
@@ -151,7 +149,11 @@ private fun RoutineStatusDay(
151149
.background(color = backgroundColor, shape = CircleShape)
152150
.border(border = BorderStroke(width = 2.dp, color = strokeColor), shape = CircleShape)
153151
.then(
154-
if (habitStatus == null || day.position in arrayOf(DayPosition.InDate, DayPosition.OutDate)) Modifier
152+
if (habitStatus == null || day.position in arrayOf(
153+
DayPosition.InDate,
154+
DayPosition.OutDate
155+
)
156+
) Modifier
155157
else Modifier.clickable { onClick(day.date.toKotlinLocalDate()) }
156158
)
157159
) {
@@ -165,4 +167,4 @@ private fun RoutineStatusDay(
165167
},
166168
)
167169
}
168-
}
170+
}

0 commit comments

Comments
 (0)