Fixed widget update in some circumstances

pull/168/head
M66B 5 years ago
parent 52d2ad5364
commit 2e15a0c72d

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

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

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

Loading…
Cancel
Save