From f8c21cdce4263c0bd87c98d20f3175321f8e8745 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 25 Oct 2018 06:36:35 +0000 Subject: [PATCH] Made multiple select a pro feature --- .../eu/faircode/email/FragmentMessages.java | 194 +++++++++--------- 1 file changed, 100 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index ac6c7d81..2029585e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -549,120 +549,126 @@ public class FragmentMessages extends FragmentEx { fabMove.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Bundle args = new Bundle(); - args.putLong("folder", folder); - - new SimpleTask>() { - @Override - protected List onLoad(Context context, Bundle args) { - long folder = args.getLong("folder"); - DB db = DB.getInstance(context); + if (Helper.isPro(getContext())) { + Bundle args = new Bundle(); + args.putLong("folder", folder); - EntityFolder source = db.folder().getFolder(folder); - List folders = db.folder().getFolders(source.account); - List targets = new ArrayList<>(); - for (EntityFolder f : folders) - if (!f.id.equals(folder) && !EntityFolder.DRAFTS.equals(f.type)) - targets.add(f); + new SimpleTask>() { + @Override + protected List onLoad(Context context, Bundle args) { + long folder = args.getLong("folder"); + DB db = DB.getInstance(context); + + EntityFolder source = db.folder().getFolder(folder); + List folders = db.folder().getFolders(source.account); + List targets = new ArrayList<>(); + for (EntityFolder f : folders) + if (!f.id.equals(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(targets, new Comparator() { + @Override + public int compare(EntityFolder f1, EntityFolder f2) { + 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); + } + }); - final Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc + return targets; + } - Collections.sort(targets, new Comparator() { - @Override - public int compare(EntityFolder f1, EntityFolder f2) { - 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); + @Override + protected void onLoaded(final Bundle args, List folders) { + PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor); + + int order = 0; + for (EntityFolder folder : folders) { + String name = (folder.display == null + ? Helper.localizeFolderName(getContext(), folder.name) + : folder.display); + popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, name); } - }); - return targets; - } + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(final MenuItem target) { + MutableSelection selection = new MutableSelection<>(); + selectionTracker.copySelection(selection); - @Override - protected void onLoaded(final Bundle args, List folders) { - PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor); + long[] ids = new long[selection.size()]; + int i = 0; + for (Long id : selection) + ids[i++] = id; - int order = 0; - for (EntityFolder folder : folders) { - String name = (folder.display == null - ? Helper.localizeFolderName(getContext(), folder.name) - : folder.display); - popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, name); - } - - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(final MenuItem target) { - MutableSelection selection = new MutableSelection<>(); - selectionTracker.copySelection(selection); - - long[] ids = new long[selection.size()]; - int i = 0; - for (Long id : selection) - ids[i++] = id; + selectionTracker.clearSelection(); - selectionTracker.clearSelection(); + args.putLongArray("ids", ids); + args.putLong("target", target.getItemId()); - args.putLongArray("ids", ids); - args.putLong("target", target.getItemId()); + new SimpleTask() { + @Override + protected Void onLoad(Context context, Bundle args) { + long[] ids = args.getLongArray("ids"); + long target = args.getLong("target"); - new SimpleTask() { - @Override - protected Void onLoad(Context context, Bundle args) { - long[] ids = args.getLongArray("ids"); - long target = args.getLong("target"); + DB db = DB.getInstance(context); + try { + db.beginTransaction(); - DB db = DB.getInstance(context); - try { - db.beginTransaction(); - - for (long id : ids) { - EntityMessage message = db.message().getMessage(id); - List messages = - db.message().getMessageByThread(message.account, message.thread); - for (EntityMessage threaded : messages) { - if (threaded.folder.equals(message.folder)) { - db.message().setMessageUiHide(threaded.id, true); - EntityOperation.queue(db, threaded, EntityOperation.MOVE, target); + for (long id : ids) { + EntityMessage message = db.message().getMessage(id); + List messages = + db.message().getMessageByThread(message.account, message.thread); + for (EntityMessage threaded : messages) { + if (threaded.folder.equals(message.folder)) { + db.message().setMessageUiHide(threaded.id, true); + EntityOperation.queue(db, threaded, EntityOperation.MOVE, target); + } } } - } - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } - EntityOperation.process(context); + EntityOperation.process(context); - return null; - } + return null; + } - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getContext(), ex); - } - }.load(FragmentMessages.this, args); + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getContext(), ex); + } + }.load(FragmentMessages.this, args); - return true; - } - }); + return true; + } + }); - popupMenu.show(); - } + popupMenu.show(); + } - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getContext(), ex); - } - }.load(FragmentMessages.this, args); + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getContext(), ex); + } + }.load(FragmentMessages.this, args); + } else { + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); + fragmentTransaction.commit(); + } } });