Fixed widget update in some circumstances

This commit is contained in:
M66B 2019-11-24 12:33:50 +01:00
parent 52d2ad5364
commit 2e15a0c72d
3 changed files with 25 additions and 9 deletions

View File

@ -332,13 +332,15 @@ public interface DaoMessage {
" ORDER BY message.received") " ORDER BY message.received")
LiveData<List<TupleMessageEx>> liveUnseenNotify(); LiveData<List<TupleMessageEx>> liveUnseenNotify();
@Query("SELECT COUNT(*) AS total" + @Query("SELECT folder, COUNT(*) AS total" +
", SUM(ui_seen) AS seen" + ", SUM(ui_seen) AS seen" +
", SUM(ui_flagged) AS flagged" + ", SUM(ui_flagged) AS flagged" +
" FROM message" + " FROM message" +
" WHERE NOT ui_hide" + " WHERE NOT ui_hide" +
" AND message.ui_snoozed IS NULL") " AND message.ui_snoozed IS NULL" +
LiveData<TupleMessageWidgetCount> liveWidgetUnified(); " GROUP BY folder" +
" ORDER BY folder")
LiveData<List<TupleMessageWidgetCount>> liveWidgetUnified();
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.name AS accountName" + ", account.name AS accountName" +

View File

@ -247,13 +247,25 @@ public class ServiceSynchronize extends ServiceBase {
} }
}); });
db.message().liveWidgetUnified().observe(this, new Observer<TupleMessageWidgetCount>() { db.message().liveWidgetUnified().observe(this, new Observer<List<TupleMessageWidgetCount>>() {
private TupleMessageWidgetCount last = null; private List<TupleMessageWidgetCount> last = null;
@Override @Override
public void onChanged(TupleMessageWidgetCount current) { public void onChanged(List<TupleMessageWidgetCount> current) {
Log.i("Widget total=" + current.total + " seen=" + current.seen + " flagged=" + current.flagged); if (current == null)
if (last == null || !last.equals(current)) 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); WidgetUnified.update(ServiceSynchronize.this);
last = current; last = current;

View File

@ -22,6 +22,7 @@ package eu.faircode.email;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class TupleMessageWidgetCount { public class TupleMessageWidgetCount {
public long folder;
public int total; public int total;
public int seen; public int seen;
public int flagged; public int flagged;
@ -30,7 +31,8 @@ public class TupleMessageWidgetCount {
public boolean equals(@Nullable Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof TupleMessageWidgetCount) { if (obj instanceof TupleMessageWidgetCount) {
TupleMessageWidgetCount other = (TupleMessageWidgetCount) obj; TupleMessageWidgetCount other = (TupleMessageWidgetCount) obj;
return (this.total == other.total && return (this.folder == other.folder &&
this.total == other.total &&
this.seen == other.seen && this.seen == other.seen &&
this.flagged == other.flagged); this.flagged == other.flagged);
} else } else