From b084626e382729e97e319eafbdf87ff81df6704c Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 28 Oct 2018 13:35:12 +0000 Subject: [PATCH] Move anywhere --- .../eu/faircode/email/AdapterMessage.java | 51 +++++++------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 596efd36..2970dd00 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -411,7 +411,6 @@ public class AdapterMessage extends PagedListAdapter>() { @Override protected List onLoad(Context context, Bundle args) { - EntityMessage message; - List folders; - DB db = DB.getInstance(context); - try { - db.beginTransaction(); - - message = db.message().getMessage(args.getLong("id")); - folders = db.folder().getUserFolders(message.account); - - for (int i = 0; i < folders.size(); i++) - if (folders.get(i).id.equals(message.folder)) { - folders.remove(i); - break; - } - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } + EntityMessage message = db.message().getMessage(args.getLong("id")); + List folders = db.folder().getFolders(message.account); + List targets = new ArrayList<>(); + for (EntityFolder f : folders) + if (!f.id.equals(message.folder) && !EntityFolder.DRAFTS.equals(f.type)) + targets.add(f); final Collator collator = Collator.getInstance(Locale.getDefault()); collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc - Collections.sort(folders, new Comparator() { + Collections.sort(targets, new Comparator() { @Override public int compare(EntityFolder f1, EntityFolder f2) { - return collator.compare(f1.name, f2.name); + int s = Integer.compare( + EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type), + EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type)); + if (s != 0) + return s; + return collator.compare( + f1.name == null ? "" : f1.name, + f2.name == null ? "" : f2.name); } }); - EntityFolder sent = db.folder().getFolderByType(message.account, EntityFolder.SENT); - if (sent != null && !message.folder.equals(sent.id)) - folders.add(0, sent); - - EntityFolder inbox = db.folder().getFolderByType(message.account, EntityFolder.INBOX); - if (inbox != null && !message.folder.equals(inbox.id)) - folders.add(0, inbox); - - return folders; + return targets; } @Override