Add Snooze messages until a chosen time and show a follow-up reminder when they return. Bump version V0.1.17

This commit is contained in:
2026-10-07 00:55:14 +03:00
parent 520056d27c
commit a1b8bca066
25 changed files with 796 additions and 59 deletions
@@ -181,6 +181,21 @@ class MailIdleService : Service() {
MailFallbackWorker.cancel(context)
}
fun checkSnoozeReminders(context: Context) {
AndroidAccountVault.initialize(context)
val accounts = AndroidAccountVault.accounts()
for (index in 0 until accounts.length()) {
val account = accounts.getJSONObject(index)
val reminders = AndroidAccountVault.takeDueSnoozes(
account.optString("id"),
System.currentTimeMillis()
)
for (reminderIndex in 0 until reminders.length()) {
notifySnoozeReminder(context, account, reminders.getJSONObject(reminderIndex))
}
}
}
fun notifyNewMail(context: Context, account: JSONObject, count: Int) {
if (count <= 0) return
val appContext = context.applicationContext
@@ -223,5 +238,54 @@ class MailIdleService : Service() {
android.util.Log.w(TAG, "Notification permission is unavailable", error)
}
}
fun notifySnoozeReminder(context: Context, account: JSONObject, reminder: JSONObject) {
val appContext = context.applicationContext
val email = account.optString("email")
val manager = appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
manager.getNotificationChannel(MAIL_CHANNEL_ID) == null) {
manager.createNotificationChannel(NotificationChannel(
MAIL_CHANNEL_ID,
"Mail reminders",
NotificationManager.IMPORTANCE_DEFAULT
))
}
val notification = NotificationCompat.Builder(appContext, MAIL_CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_dialog_email)
.setContentTitle("Mail reminder")
.setContentText(reminder.optString("subject").ifBlank { "A snoozed message is due" })
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(appPendingIntentFor(appContext))
.build()
try {
NotificationManagerCompat.from(appContext).notify(
(email + reminder.optLong("uid")).hashCode(),
notification
)
} catch (error: SecurityException) {
android.util.Log.w(TAG, "Reminder notification permission is unavailable", error)
}
val update = JSONObject()
.put("accountId", account.optString("id"))
.put("snoozeReminder", true)
.put("foldersChanged", org.json.JSONArray()
.put("Snoozed")
.put(reminder.optString("folder", "Inbox")))
appContext.sendBroadcast(Intent(ACTION_MAIL_SYNC)
.setPackage(appContext.packageName)
.putExtra(EXTRA_SYNC_UPDATE, update.toString()))
}
private fun appPendingIntentFor(context: Context): PendingIntent {
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
?: Intent(context, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
return PendingIntent.getActivity(
context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}
}
}