From 718e5797ff492ab932aee41910f91569f248f6f6 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 17 Jun 2020 10:03:25 +0200 Subject: [PATCH] Added mark all read --- .../eu/faircode/email/FragmentMessages.java | 50 +++++++++++++++++++ app/src/main/res/menu/menu_messages.xml | 5 ++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 56 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 0b0c8beb5f..5e056ee01d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -3512,6 +3512,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. language_detection && folder && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q); menu.findItem(R.id.menu_select_all).setVisible(folder); menu.findItem(R.id.menu_select_found).setVisible(viewType == AdapterMessage.ViewType.SEARCH); + menu.findItem(R.id.menu_mark_all_read).setVisible(folder); menu.findItem(R.id.menu_force_sync).setVisible(viewType == AdapterMessage.ViewType.UNIFIED); menu.findItem(R.id.menu_force_send).setVisible(outbox); @@ -3633,6 +3634,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. onMenuSelectAll(); return true; + case R.id.menu_mark_all_read: + onMenuMarkAllRead(); + return true; + case R.id.menu_force_sync: onMenuForceSync(); return true; @@ -3828,6 +3833,51 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. }); } + private void onMenuMarkAllRead() { + ViewModelMessages model = new ViewModelProvider(getActivity()).get(ViewModelMessages.class); + model.getIds(getContext(), getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(List ids) { + Bundle args = new Bundle(); + args.putLongArray("ids", Helper.toLongArray(ids)); + + new SimpleTask() { + @Override + protected void onPreExecute(Bundle args) { + ToastEx.makeText(getContext(), R.string.title_executing, Toast.LENGTH_LONG).show(); + } + + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + long[] ids = args.getLongArray("ids"); + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + for (long id : ids) { + EntityMessage message = db.message().getMessage(id); + if (message != null) + EntityOperation.queue(context, message, EntityOperation.SEEN, true); + } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentMessages.this, args, "message:read"); + } + }); + } + private void onMenuForceSync() { ServiceSynchronize.reload(getContext(), null, true, "force sync"); ToastEx.makeText(getContext(), R.string.title_executing, Toast.LENGTH_LONG).show(); diff --git a/app/src/main/res/menu/menu_messages.xml b/app/src/main/res/menu/menu_messages.xml index 36768bd1d1..3c58419539 100644 --- a/app/src/main/res/menu/menu_messages.xml +++ b/app/src/main/res/menu/menu_messages.xml @@ -128,6 +128,11 @@ android:title="@string/title_select_found" app:showAsAction="never" /> + + Select language Select all Select found + Mark all read Force sync Force send