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")
LiveData<List<TupleMessageEx>> 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<TupleMessageWidgetCount> liveWidgetUnified();
" AND message.ui_snoozed IS NULL" +
" GROUP BY folder" +
" ORDER BY folder")
LiveData<List<TupleMessageWidgetCount>> liveWidgetUnified();
@Query("SELECT message.*" +
", account.name AS accountName" +

View File

@ -247,13 +247,25 @@ public class ServiceSynchronize extends ServiceBase {
}
});
db.message().liveWidgetUnified().observe(this, new Observer<TupleMessageWidgetCount>() {
private TupleMessageWidgetCount last = null;
db.message().liveWidgetUnified().observe(this, new Observer<List<TupleMessageWidgetCount>>() {
private List<TupleMessageWidgetCount> 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<TupleMessageWidgetCount> 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;

View File

@ -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