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 | 190 +++++++++--------- 1 file changed, 98 insertions(+), 92 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index ac6c7d8101..2029585e25 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); + if (Helper.isPro(getContext())) { + 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); + 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); + 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 + 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); - } - }); + 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); + } + }); - return targets; - } - - @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); + } - selectionTracker.clearSelection(); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(final MenuItem target) { + MutableSelection selection = new MutableSelection<>(); + selectionTracker.copySelection(selection); - args.putLongArray("ids", ids); - args.putLong("target", target.getItemId()); + long[] ids = new long[selection.size()]; + int i = 0; + for (Long id : selection) + ids[i++] = id; - new SimpleTask() { - @Override - protected Void onLoad(Context context, Bundle args) { - long[] ids = args.getLongArray("ids"); - long target = args.getLong("target"); + selectionTracker.clearSelection(); - DB db = DB.getInstance(context); - try { - db.beginTransaction(); + args.putLongArray("ids", ids); + args.putLong("target", target.getItemId()); - 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); + 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(); + + 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); + + return null; } - EntityOperation.process(context); + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getContext(), ex); + } + }.load(FragmentMessages.this, args); - return null; - } + return true; + } + }); - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getContext(), ex); - } - }.load(FragmentMessages.this, args); + popupMenu.show(); + } - return true; - } - }); - - 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(); + } } });