Browse Source

Added basic new email notification

main
M66B 6 years ago
parent
commit
210cf6ee20
4 changed files with 30 additions and 17 deletions
  1. +8
    -2
      app/src/main/java/eu/faircode/email/DaoAccount.java
  2. +16
    -12
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java
  3. +1
    -0
      app/src/main/java/eu/faircode/email/TupleAccountStats.java
  4. +5
    -3
      app/src/main/res/values/strings.xml

+ 8
- 2
app/src/main/java/eu/faircode/email/DaoAccount.java View File

@ -49,8 +49,14 @@ public interface DaoAccount {
LiveData<EntityAccount> 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<TupleAccountStats> liveStats();
@Insert(onConflict = OnConflictStrategy.REPLACE)


+ 16
- 12
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -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),


+ 1
- 0
app/src/main/java/eu/faircode/email/TupleAccountStats.java View File

@ -22,4 +22,5 @@ package eu.faircode.email;
public class TupleAccountStats {
public Integer accounts;
public Integer operations;
public Integer unseen;
}

+ 5
- 3
app/src/main/res/values/strings.xml View File

@ -2,11 +2,13 @@
<string name="app_name">Safe email</string>
<string name="channel_service">Service</string>
<string name="channel_notification">Notifications</string>
<string name="channel_error">Errors</string>
<string name="title_synchronizing">Synchronizing %1$d account(s)</string>
<string name="title_operations">%1$d operation(s) pending</string>
<string name="title_failed">\'%1$s\' failed</string>
<string name="title_notification_synchronizing">Synchronizing %1$d account(s)</string>
<string name="title_notification_operations">%1$d operation(s) pending</string>
<string name="title_notification_unseen">%1$d new message(s)</string>
<string name="title_notification_failed">\'%1$s\' failed</string>
<string name="menu_folders">Folders</string>
<string name="menu_setup">Setup</string>


Loading…
Cancel
Save