Conversation
The idea behind this is that each habit doesn't have the same scheduled days to complete as others. For example your main goal may be to work out only 3 days a week and not every day. So to keep better the streaks and add more options to the users I thought that this could be a great idea. This is something similar to what was asked in the #18 issue. I think this is the best way to get the option to achieve those options like having something to do 1 day a week. For a habit I think this is the best way, I could extend or add some way to add something to do like once every 2 weeks or monthly, but I think that suits more a task (I'm thinking of adding recurring tasks to the flow module (not yet, but when I remember this I think is the best place to add it)).
Just the UI update to allow this, some minor logical implementations to save the selected scheduled days, including editions.
- The top progress bar only counts habits scheduled for today. - Unscheduled habits for today remain visible for viewing and editing. - The text "Not scheduled for today" is displayed. - The main button is disabled when the habit is not scheduled for today. - Unscheduled days appear dimmed in the calendars. - Unscheduled days cannot be selected or completed. - Numeric habit controls are disabled on unscheduled days. - Historical entries are not deleted. - The repository prevents saving boolean or numeric entries on unscheduled dates, even if attempted outside the UI. - The widget also verifies the schedule before modifying the habit.
- Daily habits carry over the previous behavior. - Unscheduled days neither break nor increment the streak. - Skipping a scheduled occurrence breaks the streak. - A pending current day does not break the streak yet. - Entries logged on unscheduled days are ignored. - Entries made before the habit creation date do not count. - Boolean and numeric habits use the exact same logic. - For numeric habits: - With a goal, the value must reach the goal. - Without a goal, the value must be greater than zero.
After the phase 4 patch, a freshly created daily habit with three consecutive completed days showed, a current streak of 1 instead of 3.
Root cause
----------
The bug was not in the streak iteration itself but in the startedOn
parameter introduced together with HabitStreakCalculator in phase 4.
The calculator dropped every completion dated before habit.createdAt:
.filter { startedOn == null || !it.isBefore(startedOn) }
The natural way to exercise the feature is to create the habit today and then backfill the previous days from the week calendar, so every entry except today's was filtered out and the streak collapsed to 1. The code before the patch counted those entries, so this is a regression introduced by the patch itself.
Fix
---
Remove startedOn from HabitStreakCalculator.current() and .best() and from all six call sites (GetHabitsWithStatusUseCase x2, HabitDetailViewModel x4). Every completion on a scheduled day now counts towards the streak.
All other phase 4 behavior is preserved:
- streaks count scheduled occurrences, not calendar days
- a pending scheduled today keeps the streak alive (grace occurrence)
- unscheduled-day completions are ignored
- numeric habits keep the targetValue threshold (value >= target, or value > 0 without target)
Tests
-----
- Replace current_doesNotCountEntriesBeforeHabitCreation with
current_countsBackfilledEntriesCompletedBeforeCreation and add the matching best() case for the new semantics.
- Verified with the module's real code executed in a standalone harness (fake HabitRepository + flows): all HabitStreakCalculatorTest and GetHabitsWithStatusUseCaseTest cases pass, the reported scenario (daily habit created today + 3 backfilled consecutive days) returns a streak of 3, and the old-habit regression check stays at 3.
Now the Detail state and consequently the stats use the scheduled days to calculate all the graphics. New component to centralize some of these calculations was created.
…led that day. The widget changes the color to be surfaceVariant and if you click on it, it will show a message informing the next scheduled day for that habit.
Make the selector more coherent with the material-3-like style of the app.
Show in the same row some fields to make it feel less overwhelming. Before this the sheet was extremely high because all the fields were stacked up.
Update it and organize it better visually.
Added some achievements to make users happier and more motivated to complete the tasks and habits.
The applied shadow caused some problems with low-end devices. (Especially the emulator, I know that the emulator problem could be something that is not seen in real life phones, but I think this isn't necessary and I don't want to risk anything).
Delete the glossy effect, fixed the title to the top (centered). Finally, make the bottom navigation bar transparent in that screen.
Improved the description of the achievements to make them clearer. Reordered them based on the progress. Also improved the shapes.
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.
The habits now can be scheduled so the statistics and streaks make more sense for some habits ( some people may not need to complete a habit every day, now you can schedule how much days a week you want to complete a habit, being the minimum 1 day).
First completed version of the Achievements, still improvements to add, but minor things, the bulk is done.
Also updated the readme.