Skip to content

Add streak counter feature to track consecutive habit completions#29

Closed
AlexGladkov wants to merge 2 commits into
mainfrom
feature/add-streak-counter-feature-d9249841
Closed

Add streak counter feature to track consecutive habit completions#29
AlexGladkov wants to merge 2 commits into
mainfrom
feature/add-streak-counter-feature-d9249841

Conversation

@AlexGladkov

Copy link
Copy Markdown
Owner

Summary

  • Implemented streak counter functionality to track consecutive days of habit completion
  • Added new database column currentStreak to HabitEntity with migration (v8 to v9)
  • Created CalculateStreakUseCase to compute streaks based on habit completion history
  • Created UpdateStreakUseCase to update streaks when habits are toggled
  • Enhanced habit UI to display current streak with fire emoji indicator
  • Added streak information to habit detail view
  • Fixed edge case to prevent streak reset when current day is not yet completed

Implementation Details

  • Streak calculation uses habit completion dates to find consecutive completed days
  • Streak updates automatically when users toggle habit completion
  • UI shows streak count with "🔥" emoji when streak ≥ 1
  • Detail view displays current streak in a dedicated info section
  • Database migration safely adds the new column with default value of 0

Testing

  • Verified streak calculation logic for various completion patterns
  • Tested streak updates on habit toggle
  • Confirmed UI displays streaks correctly
  • Validated database migration

🤖 Generated with Claude Code

claude and others added 2 commits January 28, 2026 19:28
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants