Add streak counter feature to track consecutive habit completions#29
Closed
AlexGladkov wants to merge 2 commits into
Closed
Add streak counter feature to track consecutive habit completions#29AlexGladkov wants to merge 2 commits into
AlexGladkov wants to merge 2 commits into
Conversation
This commit implements a comprehensive streak tracking system for habits: ## Database Layer - Add currentStreak, longestStreak, and lastCompletedDate fields to HabitEntity - Create Migration8to9 to add streak columns to existing database - Add updateStreakInfo method to HabitDao for updating streak data - Add getCompletedDatesForHabit method to DailyDao for streak calculation ## Domain Layer - Implement CalculateStreakUseCase to compute current streaks based on: - Consecutive completion days - Habit's scheduled days (daysToCheck) - Proper handling of missed scheduled days - Implement UpdateStreakUseCase to update streak information in database - Update SwitchHabitUseCase to recalculate streaks after habit check/uncheck ## Presentation Layer - Add currentStreak and longestStreak to DailyHabit model - Add currentStreak to HabitCardItemModel - Add streak fields to DetailViewState (currentStreak, longestStreak, lastCompletedDate) - Update GetHabitsForTodayUseCase to include streak information from HabitEntity - Update GetDetailInfoUseCase to include streak data in HabitDetail - Update DetailViewModel to populate streak information in view state ## UI Layer - Display streak badge (🔥 count) next to habit title in HabitCardItem when streak > 0 - Add "Streak Statistics" section to DetailView showing: - Current Streak (in tint color) - Longest Streak - Last Completed Date (if available) - Add string resources for streak-related labels ## Dependency Injection - Register CalculateStreakUseCase and UpdateStreakUseCase in DailyModule - Update SwitchHabitUseCase binding to inject UpdateStreakUseCase ## Platform Support - Update all platform-specific DatabaseBuilder files (Android, iOS, JVM) to include Migration8to9 The streak counter motivates users by showing their consecutive completion progress and tracks their best achievement (longest streak). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed a critical bug in streak calculation where the current streak would incorrectly reset to 0 at the start of each scheduled day before the habit was completed. Now the streak calculation skips the target date (today) if it hasn't been completed yet, and counts backwards from yesterday. This ensures users maintain their streak count throughout the day until they actually miss completing a scheduled habit day. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
currentStreakto HabitEntity with migration (v8 to v9)CalculateStreakUseCaseto compute streaks based on habit completion historyUpdateStreakUseCaseto update streaks when habits are toggledImplementation Details
Testing
🤖 Generated with Claude Code