quran / quran_android

a quran reading application for android
http://android.quran.com
GNU General Public License v3.0
1.95k stars 881 forks source link

Add reminder notifications #2659

Open OmarNofal opened 2 months ago

OmarNofal commented 2 months ago

It would be great if the app had the ability to send reminders to do the daily werd. Also would be great to have the app remind you to read surah Al-Kahf every Friday.

There is already feature request open but it is too old (2011).

I can start working right away to implement this feature. Please tell me if it is ok.

ahmedre commented 2 months ago

It's planned in sha' Allah, just that unfortunately, life gets in the way sometimes.

OmarNofal commented 2 months ago

No, it is okay. I understand.

I can work on this feature, would that be okay with you?

ahmedre commented 2 months ago

sure, no problem. let's start with a reminders panel in settings, with some defaults that are there but disabled by default (reminder on Friday to read sura Kahf, reminder each day to read wird).

person using the app can edit the times of those and enable/disable them. Let's build it using Compose and make sure the code is in a new module. in phase 2 we can allow adding custom reminders, deleting reminders, etc.

OmarNofal commented 2 months ago

Great.

So I have come up with the following steps:

  1. Create a module :feature:reminders:
  2. Create a worker inside the module which sends the notification depending on the reminder type (wird or surah Al-Kahf)
  3. Create an Activity containing the UI (compose) along with its presenter
  4. When the user toggles any of the 2 reminders, the presenter cancels the existing Worker of that reminder type and creates a new PeriodicWorker
  5. Add the preference key inside the PrefsFragment to open the new Activity

There are still some missing pieces that I am thinking about:

  1. How do I connect this to the exisitng shared prefs file that is created by the PreferencesFragment
  2. Should I create the Worker inside the new module or in the app module?

~Also I am getting the following error when building, should I download something? java.nio.file.AccessDeniedException: C:\Windows\sqlite-3.45.2.0-7930c5d7-092c-43ed-987f-7a80973d6eee-sqlitejdbc.dll.lck~ (never mind, I fixed this error by running as administrator)

ahmedre commented 2 months ago

No need for a worker also - you can just request alarms permission when someone goes to enable the setting and set a precise alarm.

OmarNofal commented 2 months ago

Don't you think requesting the alarms permission to send basic notifications would be too much? I though using a worker would make it easier to handle stuff like persisting Workers when the device reboots and also observing the Worker states using flows which makes it easier to work with in Compose. We can also use setExpedited to make it behave like an exact alarm too

ahmedre commented 2 months ago

A worker would do the job but this is literally an alarm so using alarms makes sense to me for it.

We can avoid the permission request if we make the time approximate instead of exact, within a 15 minute window.