Habits — Android
A habit tracker with streaks, weekly targets and reminders that stay quiet once you have already done the thing.
Gallery
-
At the top is how much of today’s list is done. English is scheduled for weekdays only, so on Saturday it does not count. Water is counted: the ring is 5 of 8 full -
The “why” note sits in plain view, to reread when you feel like giving up. In the calendar a tap ticks a day, and a long press opens the amount or an excused day -
The weekday breakdown shows the weak spot: Tuesday gets done 58% of the time, the other days 75 to 92% -
A “three times a week” target counts its streak in weeks and its rate as good weeks out of eight. The dark theme follows the system setting -
If the phone has not allowed exact alarms, the screen says plainly that the reminder may be late and links to the setting -
Habit colours are mid-bright: the white tick reads on the fill, and the fill reads on both light and dark backgrounds
About the project
A habit is ticked off or counted: eight glasses of water, twenty pages. Schedules differ too: every day, weekdays only, or “three times a week on any days”. A weekly target keeps its streak in weeks, so a missed Tuesday breaks nothing as long as three runs are in by Sunday.
Illness or a trip can be marked as an excused day. It does not break the streak and does not spoil the completion rate. The habit card shows the current and best streak, the rate over 30 days, a month calendar, a heat map of the year and the completion rate by weekday, so you can see which day slips most often.
The reminder arrives at the chosen time only if the habit is not ticked yet, and you can tick it right from the notification. All data lives in a file on the phone, and the app has no internet access. A copy can be saved to a file and restored on another phone.
What is inside
- Three kinds of schedule: every day, chosen weekdays, and an “N times a week” target whose streak counts in weeks
- Ticked off or counted with a unit: “5 of 8 glasses”, and going over the target shows too
- An excused day neither breaks the streak nor counts toward the rate, and in the first week the target only counts the days after the start
- An unfinished today does not spoil the stats: the day is still going, so streak and rate ignore it until it is done
- All the streak and rate arithmetic lives in plain Kotlin with no Android in it, covered by 17 unit tests on the JVM
- No reminder if the habit is already ticked; the notification has a “Done” or “+1” button to tick it there
- Without the exact-alarm permission the reminder gets a 10-minute window instead of drifting half an hour; alarms are set again after a reboot or a time zone change
- Days are stored as a number counted from 1970-01-01: easy to subtract and compare, with the time zone only involved when turning “now” into a day
- The file is written atomically through a temporary one on a background thread; on restore the app first shows how many habits the copy holds, and refuses a foreign or damaged file
- No internet access in the manifest; a 1.5 MB release build: R8, resource shrinking, Views and ViewBinding instead of Compose