I’m building a daily habit tracker app and trying to implement a per-habit streak counter using native Adalo actions. I was able to do an action for very first completion for this habit / new streak begins and if the streak continues from yesterday. I also wanted to add another action for when the streak was broken (missed more than one day)
I appreciate you sending this to me. I actually saw this and tried to apply it myself on my app but it didn’t work. I have StreakCount and LastCompletedDate on my User Database collection and created an action to the Toggle component for when the user starts the streak and continues the streak for the next day to reflect on the Text component I added. But after 24 hours, it didn’t update the streak I’ve been looking it up online and trying the suggestions from the forums, however, it didn’t work.
If you store the data in Users collection - you can update the required fields automatically at the time of app launch (action on the Home screen itself). I can think of the following logic:
you add a property “StreakExpiration”, type DateTime.
you add a property “StreakCounter”, type Number.
when you complete an activity, you increase StreakCounter by one and you set StreakExpiration to “two days from now”. This should in storing 12:00 AM of the day after next day, in the client device’s timezone.
→ you could also use other logic, e.g. current time + 1 (if you want to add 1 day to the time of activity execution)
on the Home screen, you add on-screen enter action, which sets StreakCounter to 0.
you make this action conditional: it should be executed only when Current Time is after StreakExpiration (or when StreakExpiration is before Current Time).
As a result, the counter will be reset only if a user doesn’t mark the activity completed at a certain day. I’m not touching other subjects like limiting activity reporting to 1/day or managing different activity types.
Also: I don’t have an opportunity to build this in Adalo now, so I can’t guarantee 100% that it works; but the approach should be correct. And I’d recommend testing this in native builds as the current time may work differently on Android and iOS.