Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 Fix adding task with alarm doesn't schedule the notification #671

Merged
merged 8 commits into from
May 4, 2024

Conversation

igorescodro
Copy link
Owner

When I implemented this feature, I didn't test it properly. It ended up that a some code connections were missing to enable the alarm to be schedule while the task is being inserted. This PR does the following

  • Moved the logic from TaskAlarmViewModel to a dedicated use case
  • Updated the insertTask query to return the latest inserted entry
  • Updated the AddTask use case to schedule the notifications if an alarm is set
  • Change the encapsulation to leave only the new use case public
  • Updated the unit tests

Having the last inserted row in the Task table will allow the app to
schedule an alarm right after inserting the task. The lack of this
support is what is causing the bug where the alarm is not schedule when
using the botom sheet.
The logic that handles what to do with the alarm, such as
schedule/cancel and set the repeating frequency were moved from the UI
layer to the domain to be reusable.
Now that we have a use case that handles the alarm update, the logic and
tests were simplified in the Ui layer. I don't love the solution to
have to load the task before sending a copy to be modified, but for
now, that's not going to impact the code too much and don't require a
big refactor.
Now that all the structure were ported to be more reusable, the use case
was updated to schedule the alarm and the interval. This fixes the bug
where the alarm was not being scheduled through the bottom sheet.
The UpdateAlarm use case will be the only public one for the other
clients. That allows better control on how to properly update the alarms
without missing any requirement.
Unit tests update with the new injection in AddTask use case and remove
unused test fakes.
To ensure that the "select last row" will work properly after inserting
the task, the code was updated to run inside a transaction. This is
required because it "only works on the connection where the write
happened". Despite working fine in Android, this was not working on iOS.

Source: sqldelight/sqldelight#1828
@igorescodro igorescodro merged commit 09f3017 into main May 4, 2024
4 checks passed
@igorescodro igorescodro deleted the fix/alarm-bottom-sheet branch May 4, 2024 15:55
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.

1 participant