From d9e5608b895922b9f148e67a4afbddaff6299b95 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 11 Mar 2020 10:09:52 +0100 Subject: [PATCH] Added send idle status --- .../java/eu/faircode/email/DaoOperation.java | 7 +++- .../java/eu/faircode/email/ServiceSend.java | 14 ++++--- .../java/eu/faircode/email/TupleUnsent.java | 37 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 +- 4 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/TupleUnsent.java diff --git a/app/src/main/java/eu/faircode/email/DaoOperation.java b/app/src/main/java/eu/faircode/email/DaoOperation.java index ac9eb162df..f5d60f9718 100644 --- a/app/src/main/java/eu/faircode/email/DaoOperation.java +++ b/app/src/main/java/eu/faircode/email/DaoOperation.java @@ -87,12 +87,15 @@ public interface DaoOperation { " AND (NOT folder.account IS NULL OR identity.synchronize IS NULL OR identity.synchronize)") LiveData liveStats(); - @Query("SELECT COUNT(operation.id) FROM operation" + + @Query("SELECT" + + " COUNT(operation.id) AS count" + + ", SUM(CASE WHEN operation.state = 'executing' THEN 1 ELSE 0 END) AS busy" + + " FROM operation" + " JOIN message ON message.id = operation.message" + " JOIN identity ON identity.id = message.identity" + " WHERE operation.name = '" + EntityOperation.SEND + "'" + " AND identity.synchronize") - LiveData liveUnsent(); + LiveData liveUnsent(); @Query("SELECT * FROM operation ORDER BY id") List getOperations(); diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 72a5be7825..0d26f0627c 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -63,7 +63,7 @@ import javax.mail.internet.MimeMessage; import static android.os.Process.THREAD_PRIORITY_BACKGROUND; public class ServiceSend extends ServiceBase { - private int lastUnsent = 0; + private TupleUnsent lastUnsent = null; private boolean lastSuitable = false; private PowerManager.WakeLock wlOutbox; @@ -83,10 +83,10 @@ public class ServiceSend extends ServiceBase { // Observe unsent count DB db = DB.getInstance(this); - db.operation().liveUnsent().observe(this, new Observer() { + db.operation().liveUnsent().observe(this, new Observer() { @Override - public void onChanged(Integer unsent) { - if (unsent != null && lastUnsent != unsent) { + public void onChanged(TupleUnsent unsent) { + if (unsent == null || !unsent.equals(lastUnsent)) { lastUnsent = unsent; try { @@ -188,9 +188,11 @@ public class ServiceSend extends ServiceBase { .setCategory(NotificationCompat.CATEGORY_SERVICE) .setVisibility(NotificationCompat.VISIBILITY_SECRET); - if (lastUnsent > 0) + if (lastUnsent != null) builder.setContentText(getResources().getQuantityString( - R.plurals.title_notification_unsent, lastUnsent, lastUnsent)); + R.plurals.title_notification_unsent, lastUnsent.count, lastUnsent.count)); + if (lastUnsent == null || lastUnsent.busy == 0) + builder.setSubText(getString(R.string.title_notification_idle)); if (!lastSuitable) builder.setSubText(getString(R.string.title_notification_waiting)); diff --git a/app/src/main/java/eu/faircode/email/TupleUnsent.java b/app/src/main/java/eu/faircode/email/TupleUnsent.java new file mode 100644 index 0000000000..597a22ffd5 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/TupleUnsent.java @@ -0,0 +1,37 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2020 by Marcel Bokhorst (M66B) +*/ + +import androidx.annotation.Nullable; + +public class TupleUnsent { + public Integer count; + public Integer busy; + + @Override + public boolean equals(@Nullable Object obj) { + if (obj instanceof TupleUnsent) { + TupleUnsent other = (TupleUnsent) obj; + return (this.count.equals(other.count) && + this.busy.equals(other.busy)); + } else + return false; + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1ed6ef9019..7ec1c4e40e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -93,8 +93,9 @@ Creating and using rules is a pro feature. - Waiting for suitable connection Sending messages + Waiting for suitable connection + Idle \'%1$s\' failed \'%1$s\' server alert