diff --git a/app/src/main/java/eu/faircode/email/DaoAccount.java b/app/src/main/java/eu/faircode/email/DaoAccount.java index b4dce43a..a6d906bf 100644 --- a/app/src/main/java/eu/faircode/email/DaoAccount.java +++ b/app/src/main/java/eu/faircode/email/DaoAccount.java @@ -49,8 +49,14 @@ public interface DaoAccount { LiveData liveFirstAccount(); @Query("SELECT" + - " (SELECT COUNT(*) FROM account WHERE synchronize) AS accounts," + - " (SELECT COUNT(*) FROM operation JOIN message ON message.id = operation.message JOIN account ON account.id = message.account WHERE synchronize) AS operations") + " (SELECT COUNT(*) FROM account WHERE synchronize) AS accounts" + + ", (SELECT COUNT(*) FROM operation" + + " JOIN message ON message.id = operation.message" + + " JOIN account ON account.id = message.account" + + " WHERE synchronize) AS operations" + + ", (SELECT COUNT(*) FROM message" + + " JOIN folder ON folder.id = message.folder" + + " WHERE NOT ui_seen AND folder.type = '" + EntityFolder.TYPE_INBOX + "') AS unseen") LiveData liveStats(); @Insert(onConflict = OnConflictStrategy.REPLACE) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index e6bea520..79b76dc3 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -120,7 +120,7 @@ public class ServiceSynchronize extends LifecycleService { public void onCreate() { Log.i(Helper.TAG, "Service create"); super.onCreate(); - startForeground(NOTIFICATION_SYNCHRONIZE, getNotification(0, -1).build()); + startForeground(NOTIFICATION_SYNCHRONIZE, getNotification(0, -1, 0).build()); // Listen for network changes ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); @@ -134,7 +134,7 @@ public class ServiceSynchronize extends LifecycleService { public void onChanged(@Nullable TupleAccountStats stats) { if (stats != null) { NotificationManager nm = getSystemService(NotificationManager.class); - nm.notify(NOTIFICATION_SYNCHRONIZE, getNotification(stats.accounts, stats.operations).build()); + nm.notify(NOTIFICATION_SYNCHRONIZE, getNotification(stats.accounts, stats.operations, stats.unseen).build()); } } }); @@ -165,7 +165,7 @@ public class ServiceSynchronize extends LifecycleService { return START_STICKY; } - private Notification.Builder getNotification(int acounts, int operations) { + private Notification.Builder getNotification(int accounts, int operations, int unseen) { // Build pending intent Intent intent = new Intent(this, ActivityView.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -175,24 +175,22 @@ public class ServiceSynchronize extends LifecycleService { // Build notification Notification.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - builder = new Notification.Builder(this, "service"); + builder = new Notification.Builder(this, unseen == 0 ? "service" : "notification"); else builder = new Notification.Builder(this); builder .setSmallIcon(R.drawable.baseline_mail_outline_24) - .setContentTitle(getString(R.string.title_synchronizing, acounts)) - .setContentText(getString(R.string.title_operations, operations)) + .setContentTitle(getString(R.string.title_notification_synchronizing, accounts)) + .setContentText(getString(R.string.title_notification_unseen, unseen)) .setContentIntent(pi) + .setStyle(new Notification.BigTextStyle().setSummaryText(getString(R.string.title_operations, operations))) .setAutoCancel(false) - .setShowWhen(false) - .setPriority(Notification.PRIORITY_MIN) + .setShowWhen(unseen > 0) + .setPriority(unseen == 0 ? Notification.PRIORITY_MIN : Notification.PRIORITY_DEFAULT) .setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET); - if (operations >= 0) - builder.setContentText(getString(R.string.title_operations, operations)); - return builder; } @@ -212,7 +210,7 @@ public class ServiceSynchronize extends LifecycleService { builder .setSmallIcon(android.R.drawable.stat_notify_error) - .setContentTitle(getString(R.string.title_failed, action)) + .setContentTitle(getString(R.string.title_notification_failed, action)) .setContentText(Helper.formatThrowable(ex)) .setContentIntent(pi) .setAutoCancel(false) @@ -1148,6 +1146,12 @@ public class ServiceSynchronize extends LifecycleService { service.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); nm.createNotificationChannel(service); + NotificationChannel notification = new NotificationChannel( + "notification", + context.getString(R.string.channel_notification), + NotificationManager.IMPORTANCE_DEFAULT); + nm.createNotificationChannel(notification); + NotificationChannel error = new NotificationChannel( "error", context.getString(R.string.channel_error), diff --git a/app/src/main/java/eu/faircode/email/TupleAccountStats.java b/app/src/main/java/eu/faircode/email/TupleAccountStats.java index eb057a5c..815ef9f0 100644 --- a/app/src/main/java/eu/faircode/email/TupleAccountStats.java +++ b/app/src/main/java/eu/faircode/email/TupleAccountStats.java @@ -22,4 +22,5 @@ package eu.faircode.email; public class TupleAccountStats { public Integer accounts; public Integer operations; + public Integer unseen; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 70d98f02..25cf5370 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,11 +2,13 @@ Safe email Service + Notifications Errors - Synchronizing %1$d account(s) - %1$d operation(s) pending - \'%1$s\' failed + Synchronizing %1$d account(s) + %1$d operation(s) pending + %1$d new message(s) + \'%1$s\' failed Folders Setup