1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-25 09:17:58 +00:00

Fixed/simplified widget update

This commit is contained in:
M66B 2019-11-18 10:14:37 +01:00
parent f209d219fd
commit d24fb17cb2
5 changed files with 60 additions and 60 deletions

View file

@ -332,8 +332,16 @@ public interface DaoMessage {
" ORDER BY message.received")
LiveData<List<TupleMessageEx>> liveUnseenNotify();
String widget_unified = "SELECT message.*" +
", account.name AS accountName, folder.unified AS folderUnified" +
@Query("SELECT 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();
@Query("SELECT message.*" +
", account.name AS accountName" +
", SUM(1 - message.ui_seen) AS unseen" +
", COUNT(message.id) - SUM(message.ui_flagged) AS unflagged" +
", MAX(message.received) AS dummy" +
@ -341,6 +349,7 @@ public interface DaoMessage {
" JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE account.`synchronize`" +
" AND ((:folder IS NULL AND folder.unified) OR folder.id = :folder)" +
" AND NOT message.ui_hide" +
" AND message.ui_snoozed IS NULL" +
" AND (NOT :unseen OR NOT message.ui_seen)" +
@ -348,15 +357,9 @@ public interface DaoMessage {
" GROUP BY account.id" +
", CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
" ORDER BY message.received DESC" +
" LIMIT 100";
@Query(widget_unified)
" LIMIT 100")
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
LiveData<List<TupleMessageWidget>> liveWidgetUnified(boolean threading, boolean unseen, boolean flagged);
@Query(widget_unified)
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
List<TupleMessageWidget> getWidgetUnified(boolean threading, boolean unseen, boolean flagged);
List<TupleMessageWidget> getWidgetUnified(Long folder, boolean threading, boolean unseen, boolean flagged);
@Query("SELECT uid FROM message" +
" WHERE folder = :folder" +

View file

@ -247,31 +247,16 @@ public class ServiceSynchronize extends ServiceBase {
}
});
db.message().liveWidgetUnified(false, false, false).observe(this, new Observer<List<TupleMessageWidget>>() {
private List<TupleMessageWidget> last = null;
db.message().liveWidgetUnified().observe(this, new Observer<TupleMessageWidgetCount>() {
private TupleMessageWidgetCount last = null;
@Override
public void onChanged(List<TupleMessageWidget> messages) {
if (messages == null)
messages = new ArrayList<>();
boolean changed = false;
if (last != null && last.size() == messages.size()) {
for (int i = 0; i < last.size(); i++) {
TupleMessageWidget m1 = last.get(i);
TupleMessageWidget m2 = messages.get(i);
if (!m1.equals(m2)) {
changed = true;
break;
}
}
} else
changed = true;
last = messages;
if (changed)
public void onChanged(TupleMessageWidgetCount current) {
Log.i("Widget total=" + current.total + " seen=" + current.seen + " flagged=" + current.flagged);
if (last == null || !last.equals(current))
WidgetUnified.update(ServiceSynchronize.this);
last = current;
}
});
}

View file

@ -19,29 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import java.util.Objects;
public class TupleMessageWidget extends EntityMessage {
public String accountName;
public boolean folderUnified;
public int unseen;
public int unflagged;
@Override
public boolean equals(Object obj) {
if (obj instanceof TupleMessageWidget) {
TupleMessageWidget other = (TupleMessageWidget) obj;
return (this.id.equals(other.id) &&
this.account.equals(other.account) &&
Objects.equals(this.accountName, other.accountName) &&
this.folder.equals(other.folder) &&
this.folderUnified == other.folderUnified &&
MessageHelper.equal(this.from, other.from) &&
this.received.equals(other.received) &&
Objects.equals(this.subject, other.subject) &&
this.unseen == other.unseen &&
this.unflagged == other.unflagged);
}
return false;
}
}

View file

@ -0,0 +1,39 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import androidx.annotation.Nullable;
public class TupleMessageWidgetCount {
public int total;
public int seen;
public int flagged;
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof TupleMessageWidgetCount) {
TupleMessageWidgetCount other = (TupleMessageWidgetCount) obj;
return (this.total == other.total &&
this.seen == other.seen &&
this.flagged == other.flagged);
} else
return false;
}
}

View file

@ -80,14 +80,8 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground);
colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead);
messages.clear();
DB db = DB.getInstance(context);
List<TupleMessageWidget> wmessages = db.message().getWidgetUnified(threading, unseen, flagged);
for (TupleMessageWidget wmessage : wmessages)
if ((account < 0 || wmessage.account == account) &&
(folder < 0 ? wmessage.folderUnified : wmessage.folder == folder))
messages.add(wmessage);
messages = db.message().getWidgetUnified(folder < 0 ? null : folder, threading, unseen, flagged);
}
@Override