From 1d31e1848c21458213198023a153277e9d4d6d29 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 3 Dec 2018 15:46:24 +0100 Subject: [PATCH] Small improvements --- .../java/eu/faircode/email/AdapterFolder.java | 1 - .../eu/faircode/email/AdapterMessage.java | 8 +-- .../java/eu/faircode/email/DaoOperation.java | 4 +- .../eu/faircode/email/EntityOperation.java | 12 ++++ .../eu/faircode/email/FragmentCompose.java | 1 - .../eu/faircode/email/FragmentMessages.java | 18 ++---- .../eu/faircode/email/ServiceSynchronize.java | 61 +++++++++---------- 7 files changed, 48 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 57a874f7c2..a90097f2dc 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -328,7 +328,6 @@ public class AdapterFolder extends RecyclerView.Adapter> getOperationsByMessage(long message); - @Query("SELECT * FROM operation WHERE folder = :folder ORDER BY id") + @Query("SELECT * FROM operation" + + " WHERE folder = :folder" + + " ORDER BY CASE WHEN name = '" + EntityOperation.SYNC + "' THEN 1 ELSE 0 END, id") List getOperationsByFolder(long folder); @Query("SELECT * FROM operation ORDER BY id") diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 6cd4e88d20..ca14f305b2 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -82,6 +82,18 @@ public class EntityOperation { JSONArray jargs = new JSONArray(); jargs.put(value); queue(db, message.folder, message.id, name, jargs); + + if (SEEN.equals(name)) { + db.message().setMessageUiSeen(message.id, (boolean) value); + db.message().setMessageUiIgnored(message.id, true); + } else if (FLAG.equals(name)) + db.message().setMessageUiFlagged(message.id, (boolean) value); + else if (ANSWERED.equals(name)) + db.message().setMessageUiAnswered(message.id, (boolean) value); + else if (MOVE.equals(name)) + db.message().setMessageUiHide(message.id, true); + else if (DELETE.equals(name)) + db.message().setMessageUiHide(message.id, true); } static void queue(DB db, EntityMessage message, String name, Object value1, Object value2) { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 59c75a4673..d9ba47c5f7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1639,7 +1639,6 @@ public class FragmentCompose extends FragmentEx { if (draft.replying != null) { EntityMessage replying = db.message().getMessage(draft.replying); - db.message().setMessageUiAnswered(replying.id, true); EntityOperation.queue(db, replying, EntityOperation.ANSWERED, true); } } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6e0c8d00cf..311857d983 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -744,11 +744,8 @@ public class FragmentMessages extends FragmentEx { for (long id : ids) { EntityMessage message = db.message().getMessage(id); - if (message.ui_seen != seen) { - db.message().setMessageUiSeen(message.id, seen); - db.message().setMessageUiIgnored(message.id, true); + if (message.ui_seen != seen) EntityOperation.queue(db, message, EntityOperation.SEEN, seen); - } } db.setTransactionSuccessful(); @@ -785,10 +782,8 @@ public class FragmentMessages extends FragmentEx { for (long id : ids) { EntityMessage message = db.message().getMessage(id); - if (message.ui_flagged != flagged) { - db.message().setMessageUiFlagged(message.id, flagged); + if (message.ui_flagged != flagged) EntityOperation.queue(db, message, EntityOperation.FLAG, flagged); - } } db.setTransactionSuccessful(); @@ -984,10 +979,8 @@ public class FragmentMessages extends FragmentEx { EntityMessage message = db.message().getMessage(id); if (message.uid == null && !TextUtils.isEmpty(message.error)) // outbox db.message().deleteMessage(id); - else { - db.message().setMessageUiHide(message.id, true); + else EntityOperation.queue(db, message, EntityOperation.DELETE); - } } db.setTransactionSuccessful(); @@ -1601,11 +1594,8 @@ public class FragmentMessages extends FragmentEx { if (!message.content) EntityOperation.queue(db, message, EntityOperation.BODY); - if (!message.ui_seen && !EntityFolder.OUTBOX.equals(folder.type)) { - db.message().setMessageUiSeen(message.id, true); - db.message().setMessageUiIgnored(message.id, true); + if (!message.ui_seen && !EntityFolder.OUTBOX.equals(folder.type)) EntityOperation.queue(db, message, EntityOperation.SEEN, true); - } db.setTransactionSuccessful(); } finally { diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 212e3f2755..afb9338468 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -330,8 +330,6 @@ public class ServiceSynchronize extends LifecycleService { EntityMessage message = db.message().getMessage(id); switch (parts[0]) { case "seen": - db.message().setMessageUiSeen(message.id, true); - db.message().setMessageUiIgnored(message.id, true); EntityOperation.queue(db, message, EntityOperation.SEEN, true); break; @@ -342,7 +340,6 @@ public class ServiceSynchronize extends LifecycleService { if (archive != null) { EntityOperation.queue(db, message, EntityOperation.SEEN, true); EntityOperation.queue(db, message, EntityOperation.MOVE, archive.id); - db.message().setMessageUiHide(message.id, true); } break; @@ -351,7 +348,6 @@ public class ServiceSynchronize extends LifecycleService { if (trash != null) { EntityOperation.queue(db, message, EntityOperation.SEEN, true); EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id); - db.message().setMessageUiHide(message.id, true); } break; @@ -1117,7 +1113,7 @@ public class ServiceSynchronize extends LifecycleService { EntityFolder ofolder = null; IMAPFolder ifolder = null; for (EntityFolder f : folders.keySet()) - if (f.id == folder.id) { + if (f.id.equals(folder.id)) { ofolder = f; ifolder = folders.get(f); break; @@ -1357,10 +1353,9 @@ public class ServiceSynchronize extends LifecycleService { db.message().setMessageError(message.id, null); if (message != null && message.uid == null && - (EntityOperation.SEEN.equals(op.name) || - EntityOperation.DELETE.equals(op.name) || - EntityOperation.MOVE.equals(op.name) || - EntityOperation.HEADERS.equals(op.name))) + !(EntityOperation.ADD.equals(op.name) || + EntityOperation.SEND.equals(op.name) || + EntityOperation.SYNC.equals(op.name))) throw new IllegalArgumentException(op.name + " without uid " + op.args); JSONArray jargs = new JSONArray(op.args); @@ -1370,12 +1365,12 @@ public class ServiceSynchronize extends LifecycleService { if (EntityOperation.SEEN.equals(op.name)) doSeen(folder, ifolder, message, jargs, db); - else if (EntityOperation.ANSWERED.equals(op.name)) - doAnswered(folder, ifolder, message, jargs, db); - else if (EntityOperation.FLAG.equals(op.name)) doFlag(folder, ifolder, message, jargs, db); + else if (EntityOperation.ANSWERED.equals(op.name)) + doAnswered(folder, ifolder, message, jargs, db); + else if (EntityOperation.KEYWORD.equals(op.name)) doKeyword(folder, ifolder, message, jargs, db); @@ -1401,10 +1396,10 @@ public class ServiceSynchronize extends LifecycleService { doAttachment(folder, op, ifolder, message, jargs, db); else if (EntityOperation.SYNC.equals(op.name)) - if (!EntityFolder.OUTBOX.equals(folder.type)) - synchronizeMessages(account, folder, ifolder, state); - else + if (EntityFolder.OUTBOX.equals(folder.type)) db.folder().setFolderError(folder.id, null); + else + synchronizeMessages(account, folder, ifolder, state); else throw new MessagingException("Unknown operation name=" + op.name); @@ -1471,46 +1466,46 @@ public class ServiceSynchronize extends LifecycleService { db.message().setMessageSeen(message.id, seen); } - private void doAnswered(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException { - // Mark message (un)answered - if (!ifolder.getPermanentFlags().contains(Flags.Flag.ANSWERED)) { - db.message().setMessageAnswered(message.id, false); - db.message().setMessageUiAnswered(message.id, false); + private void doFlag(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException { + // Star/unstar message + if (!ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) { + db.message().setMessageFlagged(message.id, false); + db.message().setMessageUiFlagged(message.id, false); return; } - boolean answered = jargs.getBoolean(0); - if (message.answered.equals(answered)) + boolean flagged = jargs.getBoolean(0); + if (message.flagged.equals(flagged)) return; Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); - imessage.setFlag(Flags.Flag.ANSWERED, answered); + imessage.setFlag(Flags.Flag.FLAGGED, flagged); - db.message().setMessageAnswered(message.id, answered); + db.message().setMessageFlagged(message.id, flagged); } - private void doFlag(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException { - // Star/unstar message - if (!ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) { - db.message().setMessageFlagged(message.id, false); - db.message().setMessageUiFlagged(message.id, false); + private void doAnswered(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException { + // Mark message (un)answered + if (!ifolder.getPermanentFlags().contains(Flags.Flag.ANSWERED)) { + db.message().setMessageAnswered(message.id, false); + db.message().setMessageUiAnswered(message.id, false); return; } - boolean flagged = jargs.getBoolean(0); - if (message.flagged.equals(flagged)) + boolean answered = jargs.getBoolean(0); + if (message.answered.equals(answered)) return; Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); - imessage.setFlag(Flags.Flag.FLAGGED, flagged); + imessage.setFlag(Flags.Flag.ANSWERED, answered); - db.message().setMessageFlagged(message.id, flagged); + db.message().setMessageAnswered(message.id, answered); } private void doKeyword(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException {