Browse Source

Show number of unsent messages

main
M66B 6 years ago
parent
commit
670c0f04ae
4 changed files with 24 additions and 9 deletions
  1. +8
    -4
      app/src/main/java/eu/faircode/email/DaoAccount.java
  2. +9
    -5
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java
  3. +1
    -0
      app/src/main/java/eu/faircode/email/TupleAccountStats.java
  4. +6
    -0
      app/src/main/res/values/strings.xml

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

@ -45,17 +45,21 @@ public interface DaoAccount {
LiveData<EntityAccount> liveAccount(long id); LiveData<EntityAccount> liveAccount(long id);
@Query("SELECT" + @Query("SELECT" +
" (SELECT COUNT(*) FROM account WHERE synchronize) AS accounts" +
", (SELECT COUNT(*) FROM operation" +
" (SELECT COUNT(account.id) FROM account WHERE synchronize) AS accounts" +
", (SELECT COUNT(operation.id) FROM operation" +
" JOIN message ON message.id = operation.message" + " JOIN message ON message.id = operation.message" +
" JOIN account ON account.id = message.account" + " JOIN account ON account.id = message.account" +
" WHERE synchronize) AS operations" + " WHERE synchronize) AS operations" +
", (SELECT COUNT(*) FROM message" +
", (SELECT COUNT(message.id) FROM message" +
" JOIN account ON account.id = message.account" + " JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +
" WHERE NOT message.ui_seen AND NOT message.ui_hide" + " WHERE NOT message.ui_seen AND NOT message.ui_hide" +
" AND (account.seen_until IS NULL OR message.received > account.seen_until)" + " AND (account.seen_until IS NULL OR message.received > account.seen_until)" +
" AND folder.type = '" + EntityFolder.INBOX + "') AS unseen")
" AND folder.type = '" + EntityFolder.INBOX + "') AS unseen" +
", (SELECT COUNT(message.id) FROM message" +
" JOIN folder ON folder.id = message.folder" +
" WHERE NOT message.ui_seen" +
" AND folder.type = '" + EntityFolder.OUTBOX + "') AS unsent")
LiveData<TupleAccountStats> liveStats(); LiveData<TupleAccountStats> liveStats();
@Insert @Insert


+ 9
- 5
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -118,7 +118,7 @@ public class ServiceSynchronize extends LifecycleService {
public void onCreate() { public void onCreate() {
Log.i(Helper.TAG, "Service create"); Log.i(Helper.TAG, "Service create");
super.onCreate(); super.onCreate();
startForeground(NOTIFICATION_SYNCHRONIZE, getNotificationService(0, 0).build());
startForeground(NOTIFICATION_SYNCHRONIZE, getNotificationService(0, 0, 0).build());
// Listen for network changes // Listen for network changes
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
@ -136,7 +136,7 @@ public class ServiceSynchronize extends LifecycleService {
if (stats != null) { if (stats != null) {
NotificationManager nm = getSystemService(NotificationManager.class); NotificationManager nm = getSystemService(NotificationManager.class);
nm.notify(NOTIFICATION_SYNCHRONIZE, nm.notify(NOTIFICATION_SYNCHRONIZE,
getNotificationService(stats.accounts, stats.operations).build());
getNotificationService(stats.accounts, stats.operations, stats.unsent).build());
if (stats.unseen > 0) { if (stats.unseen > 0) {
if (stats.unseen > prev_unseen) { if (stats.unseen > prev_unseen) {
@ -192,7 +192,7 @@ public class ServiceSynchronize extends LifecycleService {
return START_STICKY; return START_STICKY;
} }
private Notification.Builder getNotificationService(int accounts, int operations) {
private Notification.Builder getNotificationService(int accounts, int operations, int unsent) {
// Build pending intent // Build pending intent
Intent intent = new Intent(this, ActivityView.class); Intent intent = new Intent(this, ActivityView.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@ -217,7 +217,11 @@ public class ServiceSynchronize extends LifecycleService {
.setVisibility(Notification.VISIBILITY_SECRET); .setVisibility(Notification.VISIBILITY_SECRET);
if (operations > 0) if (operations > 0)
builder.setContentText(getResources().getQuantityString(R.plurals.title_notification_operations, operations, operations));
builder.setStyle(new Notification.BigTextStyle().setSummaryText(
getResources().getQuantityString(R.plurals.title_notification_operations, operations, operations)));
if (unsent > 0)
builder.setContentText(getResources().getQuantityString(R.plurals.title_notification_unsent, unsent, unsent));
return builder; return builder;
} }
@ -922,7 +926,7 @@ public class ServiceSynchronize extends LifecycleService {
// Update state // Update state
if (message.thread == null) if (message.thread == null)
message.thread = imessage.getMessageID(); message.thread = imessage.getMessageID();
message.sent = new Date().getTime();
message.sent = imessage.getSentDate().getTime();
message.seen = true; message.seen = true;
message.ui_seen = true; message.ui_seen = true;
db.message().updateMessage(message); db.message().updateMessage(message);


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

@ -23,4 +23,5 @@ public class TupleAccountStats {
public Integer accounts; public Integer accounts;
public Integer operations; public Integer operations;
public Integer unseen; public Integer unseen;
public Integer unsent;
} }

+ 6
- 0
app/src/main/res/values/strings.xml View File

@ -23,6 +23,12 @@
<item quantity="other">%1$d new messages</item> <item quantity="other">%1$d new messages</item>
</plurals> </plurals>
<plurals name="title_notification_unsent">
<item quantity="zero"></item>
<item quantity="one">%1$d unsent message</item>
<item quantity="other">%1$d unsent messages</item>
</plurals>
<string name="title_notification_failed">\'%1$s\' failed</string> <string name="title_notification_failed">\'%1$s\' failed</string>
<string name="menu_setup">Setup</string> <string name="menu_setup">Setup</string>


Loading…
Cancel
Save