From 2e15a0c72d602fb0b37b14d35b1aafc4f02ecbbe Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 24 Nov 2019 12:33:50 +0100 Subject: [PATCH] Fixed widget update in some circumstances --- .../java/eu/faircode/email/DaoMessage.java | 8 ++++--- .../eu/faircode/email/ServiceSynchronize.java | 22 ++++++++++++++----- .../email/TupleMessageWidgetCount.java | 4 +++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index dd69bdf7b3..4326930443 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -332,13 +332,15 @@ public interface DaoMessage { " ORDER BY message.received") LiveData> liveUnseenNotify(); - @Query("SELECT COUNT(*) AS total" + + @Query("SELECT folder, COUNT(*) AS total" + ", SUM(ui_seen) AS seen" + ", SUM(ui_flagged) AS flagged" + " FROM message" + " WHERE NOT ui_hide" + - " AND message.ui_snoozed IS NULL") - LiveData liveWidgetUnified(); + " AND message.ui_snoozed IS NULL" + + " GROUP BY folder" + + " ORDER BY folder") + LiveData> liveWidgetUnified(); @Query("SELECT message.*" + ", account.name AS accountName" + diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 56aa715fee..2a9d32f9cc 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -247,13 +247,25 @@ public class ServiceSynchronize extends ServiceBase { } }); - db.message().liveWidgetUnified().observe(this, new Observer() { - private TupleMessageWidgetCount last = null; + db.message().liveWidgetUnified().observe(this, new Observer>() { + private List last = null; @Override - public void onChanged(TupleMessageWidgetCount current) { - Log.i("Widget total=" + current.total + " seen=" + current.seen + " flagged=" + current.flagged); - if (last == null || !last.equals(current)) + public void onChanged(List current) { + if (current == null) + current = new ArrayList<>(); + + boolean changed = false; + if (last == null || last.size() != current.size()) + changed = true; + else + for (int i = 0; i < current.size(); i++) + if (!current.get(i).equals(last.get(i))) { + changed = true; + break; + } + + if (changed) WidgetUnified.update(ServiceSynchronize.this); last = current; diff --git a/app/src/main/java/eu/faircode/email/TupleMessageWidgetCount.java b/app/src/main/java/eu/faircode/email/TupleMessageWidgetCount.java index 7e29e9f396..fa8fda8a10 100644 --- a/app/src/main/java/eu/faircode/email/TupleMessageWidgetCount.java +++ b/app/src/main/java/eu/faircode/email/TupleMessageWidgetCount.java @@ -22,6 +22,7 @@ package eu.faircode.email; import androidx.annotation.Nullable; public class TupleMessageWidgetCount { + public long folder; public int total; public int seen; public int flagged; @@ -30,7 +31,8 @@ public class TupleMessageWidgetCount { public boolean equals(@Nullable Object obj) { if (obj instanceof TupleMessageWidgetCount) { TupleMessageWidgetCount other = (TupleMessageWidgetCount) obj; - return (this.total == other.total && + return (this.folder == other.folder && + this.total == other.total && this.seen == other.seen && this.flagged == other.flagged); } else