From 43440e3b074bd235b65c69d9744b6daf680a9517 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 22 Sep 2019 14:42:43 +0200 Subject: [PATCH] Simplification/fix --- .../main/java/eu/faircode/email/DaoMessage.java | 2 +- .../java/eu/faircode/email/ServiceSynchronize.java | 14 +++++++------- .../java/eu/faircode/email/TupleMessageStats.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 250617ef83..7b387fafa3 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -248,7 +248,7 @@ public interface DaoMessage { " WHERE message.id = :id") LiveData liveMessage(long id); - @Query("SELECT COUNT(message.id) AS unseen, SUM(message.ui_ignored) AS ignored" + + @Query("SELECT COUNT(message.id) AS unseen, SUM(ABS(notifying)) AS notifying" + " FROM message" + " JOIN account ON account.id = message.account" + " JOIN folder ON folder.id = message.folder" + diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 8f3561ae5f..aff1b45352 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -150,7 +150,7 @@ public class ServiceSynchronize extends ServiceBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); db.message().liveUnseen().observe(this, new Observer() { - private TupleMessageStats lastStats = null; + private Integer lastUnseen = null; @Override public void onChanged(TupleMessageStats stats) { @@ -158,14 +158,14 @@ public class ServiceSynchronize extends ServiceBase { stats = new TupleMessageStats(); boolean unseen_ignored = prefs.getBoolean("unseen_ignored", false); - if (!unseen_ignored || stats.ignored == null) - stats.ignored = 0; + Integer unseen = (unseen_ignored ? stats.notifying : stats.unseen); + if (unseen == null) + unseen = 0; - if (!stats.equals(lastStats)) { + if (lastUnseen == null || !lastUnseen.equals(unseen)) { Log.i("Stats " + stats); - lastStats = stats; - - setUnseen(stats.unseen - stats.ignored); + lastUnseen = unseen; + setUnseen(unseen); } } }); diff --git a/app/src/main/java/eu/faircode/email/TupleMessageStats.java b/app/src/main/java/eu/faircode/email/TupleMessageStats.java index f15e1e2448..7726a71672 100644 --- a/app/src/main/java/eu/faircode/email/TupleMessageStats.java +++ b/app/src/main/java/eu/faircode/email/TupleMessageStats.java @@ -25,15 +25,15 @@ import androidx.annotation.Nullable; import java.util.Objects; public class TupleMessageStats { - public Integer unseen = 0; - public Integer ignored = 0; + public Integer unseen; + public Integer notifying; @Override public boolean equals(@Nullable Object obj) { if (obj instanceof TupleMessageStats) { TupleMessageStats other = (TupleMessageStats) obj; return (Objects.equals(this.unseen, other.unseen) && - Objects.equals(this.ignored, other.ignored)); + Objects.equals(this.notifying, other.notifying)); } else return false; } @@ -41,6 +41,6 @@ public class TupleMessageStats { @NonNull @Override public String toString() { - return "unseen=" + unseen + " ignored=" + ignored; + return "unseen=" + unseen + " notify=" + notifying; } }