-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New way of habit status computation (merge PR #6)
- Loading branch information
Showing
117 changed files
with
3,565 additions
and
7,288 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
## 2024-01-07 | ||
|
||
- Updated the core functionality of the app to compute habit statuses on the go instead of caching them in the database. This change improves the robustness and clarity of the code. | ||
- Refactored 'Routine' to 'Habit' across the application for better semantics. | ||
- Improved performance by computing each date in a separate coroutine and introduced pagination for the RoutineCalendarScreen. | ||
- Fixed various minor bugs and performance issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
build-logic/convention/build/kotlin/compileKotlin/cacheable/last-build.bin
Binary file not shown.
Binary file not shown.
79 changes: 27 additions & 52 deletions
79
...ava/com/rendox/routinetracker/core/data/completion_history/CompletionHistoryRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,41 @@ | ||
package com.rendox.routinetracker.core.data.completion_history | ||
|
||
import com.rendox.routinetracker.core.logic.time.LocalDateRange | ||
import com.rendox.routinetracker.core.model.CompletionHistoryEntry | ||
import com.rendox.routinetracker.core.model.HistoricalStatus | ||
import com.rendox.routinetracker.core.model.Habit | ||
import kotlinx.datetime.LocalDate | ||
|
||
interface CompletionHistoryRepository { | ||
suspend fun getNumOfTimesCompletedInPeriod( | ||
habitId: Long, | ||
minDate: LocalDate?, | ||
maxDate: LocalDate?, | ||
): Double | ||
|
||
suspend fun getHistoryEntries( | ||
routineId: Long, | ||
dates: LocalDateRange, | ||
): List<CompletionHistoryEntry> | ||
|
||
suspend fun getHistoryEntryByDate( | ||
routineId: Long, | ||
date: LocalDate, | ||
): CompletionHistoryEntry? | ||
|
||
suspend fun insertHistoryEntry( | ||
id: Long? = null, | ||
routineId: Long, | ||
entry: CompletionHistoryEntry, | ||
) | ||
|
||
suspend fun deleteHistoryEntry( | ||
routineId: Long, | ||
date: LocalDate, | ||
) | ||
|
||
suspend fun updateHistoryEntryByDate( | ||
routineId: Long, | ||
date: LocalDate, | ||
newStatus: HistoricalStatus? = null, | ||
newScheduleDeviation: Float? = null, | ||
newTimesCompleted: Float? = null, | ||
) | ||
|
||
suspend fun getFirstHistoryEntry(routineId: Long): CompletionHistoryEntry? | ||
suspend fun getLastHistoryEntry(routineId: Long): CompletionHistoryEntry? | ||
|
||
suspend fun checkIfStatusWasCompletedLater(routineId: Long, date: LocalDate): Boolean | ||
suspend fun deleteCompletedLaterBackupEntry(routineId: Long, date: LocalDate) | ||
|
||
suspend fun getFirstHistoryEntryByStatus( | ||
routineId: Long, | ||
matchingStatuses: List<HistoricalStatus>, | ||
suspend fun getRecordByDate(habitId: Long, date: LocalDate): Habit.CompletionRecord? | ||
suspend fun getLastCompletedRecord( | ||
habitId: Long, | ||
minDate: LocalDate? = null, | ||
maxDate: LocalDate? = null, | ||
): CompletionHistoryEntry? | ||
): Habit.CompletionRecord? | ||
|
||
suspend fun getLastHistoryEntryByStatus( | ||
routineId: Long, | ||
matchingStatuses: List<HistoricalStatus>, | ||
suspend fun getFirstCompletedRecord( | ||
habitId: Long, | ||
minDate: LocalDate? = null, | ||
maxDate: LocalDate? = null, | ||
): CompletionHistoryEntry? | ||
): Habit.CompletionRecord? | ||
|
||
suspend fun getTotalTimesCompletedInPeriod( | ||
routineId: Long, startDate: LocalDate, endDate: LocalDate | ||
): Double | ||
suspend fun getRecordsInPeriod( | ||
habitId: Long, | ||
minDate: LocalDate?, | ||
maxDate: LocalDate?, | ||
): List<Habit.CompletionRecord> | ||
|
||
suspend fun getScheduleDeviationInPeriod( | ||
routineId: Long, startDate: LocalDate, endDate: LocalDate | ||
): Double | ||
suspend fun insertCompletion( | ||
habitId: Long, | ||
completionRecord: Habit.CompletionRecord, | ||
) | ||
|
||
suspend fun deleteCompletionByDate( | ||
habitId: Long, | ||
date: LocalDate, | ||
) | ||
} |
125 changes: 34 additions & 91 deletions
125
...com/rendox/routinetracker/core/data/completion_history/CompletionHistoryRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,59 @@ | ||
package com.rendox.routinetracker.core.data.completion_history | ||
|
||
import com.rendox.routinetracker.core.database.completion_history.CompletionHistoryLocalDataSource | ||
import com.rendox.routinetracker.core.logic.time.LocalDateRange | ||
import com.rendox.routinetracker.core.model.CompletionHistoryEntry | ||
import com.rendox.routinetracker.core.model.HistoricalStatus | ||
import com.rendox.routinetracker.core.model.Habit | ||
import kotlinx.datetime.LocalDate | ||
|
||
class CompletionHistoryRepositoryImpl( | ||
private val localDataSource: CompletionHistoryLocalDataSource, | ||
) : CompletionHistoryRepository { | ||
|
||
override suspend fun getHistoryEntries( | ||
routineId: Long, | ||
dates: LocalDateRange | ||
): List<CompletionHistoryEntry> { | ||
return localDataSource.getHistoryEntries(routineId, dates) | ||
} | ||
|
||
override suspend fun getHistoryEntryByDate( | ||
routineId: Long, | ||
date: LocalDate | ||
): CompletionHistoryEntry? { | ||
return localDataSource.getHistoryEntryByDate(routineId, date) | ||
} | ||
|
||
override suspend fun insertHistoryEntry( | ||
id: Long?, | ||
routineId: Long, | ||
entry: CompletionHistoryEntry, | ||
) { | ||
localDataSource.insertHistoryEntry( | ||
id = id, | ||
routineId = routineId, | ||
entry = entry, | ||
private val localDataSource: CompletionHistoryLocalDataSource | ||
): CompletionHistoryRepository { | ||
override suspend fun getNumOfTimesCompletedInPeriod( | ||
habitId: Long, | ||
minDate: LocalDate?, | ||
maxDate: LocalDate? | ||
): Double { | ||
return localDataSource.getNumOfTimesCompletedInPeriod( | ||
habitId, minDate, maxDate | ||
) | ||
} | ||
|
||
override suspend fun deleteHistoryEntry(routineId: Long, date: LocalDate) { | ||
localDataSource.deleteHistoryEntry(routineId, date) | ||
} | ||
|
||
override suspend fun updateHistoryEntryByDate( | ||
routineId: Long, | ||
date: LocalDate, | ||
newStatus: HistoricalStatus?, | ||
newScheduleDeviation: Float?, | ||
newTimesCompleted: Float?, | ||
) { | ||
localDataSource.updateHistoryEntryByDate( | ||
routineId = routineId, | ||
date = date, | ||
newStatus = newStatus, | ||
newScheduleDeviation = newScheduleDeviation, | ||
newTimesCompleted = newTimesCompleted, | ||
override suspend fun getRecordByDate(habitId: Long, date: LocalDate): Habit.CompletionRecord? { | ||
return localDataSource.getRecordByDate( | ||
habitId, date | ||
) | ||
} | ||
|
||
override suspend fun getFirstHistoryEntry(routineId: Long): CompletionHistoryEntry? { | ||
return localDataSource.getFirstHistoryEntry(routineId) | ||
} | ||
|
||
override suspend fun getLastHistoryEntry(routineId: Long): CompletionHistoryEntry? { | ||
return localDataSource.getLastHistoryEntry(routineId) | ||
} | ||
|
||
override suspend fun checkIfStatusWasCompletedLater(routineId: Long, date: LocalDate): Boolean { | ||
return localDataSource.checkIfStatusWasCompletedLater(routineId, date) | ||
} | ||
|
||
override suspend fun deleteCompletedLaterBackupEntry(routineId: Long, date: LocalDate) { | ||
localDataSource.deleteCompletedLaterBackupEntry(routineId, date) | ||
override suspend fun getLastCompletedRecord( | ||
habitId: Long, | ||
minDate: LocalDate?, | ||
maxDate: LocalDate?, | ||
): Habit.CompletionRecord? { | ||
return localDataSource.getLastCompletedRecord(habitId, minDate, maxDate) | ||
} | ||
|
||
override suspend fun getFirstHistoryEntryByStatus( | ||
routineId: Long, | ||
matchingStatuses: List<HistoricalStatus>, | ||
override suspend fun getFirstCompletedRecord( | ||
habitId: Long, | ||
minDate: LocalDate?, | ||
maxDate: LocalDate?, | ||
): CompletionHistoryEntry? { | ||
return localDataSource.getFirstHistoryEntryByStatus( | ||
routineId = routineId, | ||
matchingStatuses = matchingStatuses, | ||
minDate = minDate, | ||
maxDate = maxDate, | ||
) | ||
): Habit.CompletionRecord? { | ||
return localDataSource.getFirstCompletedRecord(habitId, minDate, maxDate) | ||
} | ||
|
||
override suspend fun getLastHistoryEntryByStatus( | ||
routineId: Long, | ||
matchingStatuses: List<HistoricalStatus>, | ||
override suspend fun getRecordsInPeriod( | ||
habitId: Long, | ||
minDate: LocalDate?, | ||
maxDate: LocalDate?, | ||
): CompletionHistoryEntry? = localDataSource.getLastHistoryEntryByStatus( | ||
routineId = routineId, | ||
matchingStatuses = matchingStatuses, | ||
minDate = minDate, | ||
maxDate = maxDate, | ||
) | ||
|
||
override suspend fun getTotalTimesCompletedInPeriod( | ||
routineId: Long, startDate: LocalDate, endDate: LocalDate | ||
): Double { | ||
return localDataSource.getTotalTimesCompletedInPeriod( | ||
routineId, startDate, endDate | ||
): List<Habit.CompletionRecord> { | ||
return localDataSource.getRecordsInPeriod( | ||
habitId, minDate, maxDate | ||
) | ||
} | ||
|
||
override suspend fun getScheduleDeviationInPeriod( | ||
routineId: Long, startDate: LocalDate, endDate: LocalDate | ||
): Double { | ||
return localDataSource.getScheduleDeviationInPeriod( | ||
routineId, startDate, endDate | ||
) | ||
override suspend fun insertCompletion(habitId: Long, completionRecord: Habit.CompletionRecord) { | ||
localDataSource.insertCompletion(habitId, completionRecord) | ||
} | ||
|
||
override suspend fun deleteCompletionByDate(habitId: Long, date: LocalDate) { | ||
localDataSource.deleteCompletionByDate(habitId, date) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.