From 87448449771bdf91d44f3332c0aea4e156ffd068 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 11 Jan 2019 17:16:48 +0000 Subject: [PATCH] Added option to auto go to next --- FAQ.md | 1 - .../java/eu/faircode/email/ActivityBase.java | 2 +- .../eu/faircode/email/FragmentMessages.java | 32 ++++++++++++++++--- .../eu/faircode/email/FragmentOptions.java | 12 +++++++ app/src/main/res/layout/fragment_options.xml | 14 +++++++- app/src/main/res/values/strings.xml | 1 + 6 files changed, 54 insertions(+), 8 deletions(-) diff --git a/FAQ.md b/FAQ.md index 3a5fe96ac5..e92fad16a7 100644 --- a/FAQ.md +++ b/FAQ.md @@ -35,7 +35,6 @@ None at this moment. ## Frequently requested features * Swipe left/right to go to previous/next message: besides that swiping left/right is already being used to move messages to archive/trash, swiping also selects message text, so this will not work reliably. You can use the bottom navigation bar instead. -* Automatically go to the next message on deleting a message: since the 'next' message can either be an older or a newer message this would be confusing. You can disable auto closing in the advanced options and use the bottom navigation bar instead. * Rich text editor: besides that very few people would use this on a small mobile device, Android doesn't support a rich text editor and most rich text editor open source projects are abandoned. * Widget to read e-mail: widgets can have limited user interaction only, so a widget to read e-mail would not be very useful. Moreover, it would be not very useful to duplicate functions which are already available in the app. * Executing filter rules: filter rules should be executed on the server because a battery powered device with possibly an unstable internet connection is not suitable for this. diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index ae677eca4c..5e084edd95 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -42,7 +42,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc private static String[] restart = new String[]{ "unified", "threading", "compact", "avatars", "identicons", "preview", "addresses", - "pull", "actionbar", "autoclose", "confirm", "debug" + "pull", "actionbar", "autoclose", "autonext", "confirm", "debug" }; @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index fc7dfcc578..6bd1780879 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -117,6 +117,7 @@ public class FragmentMessages extends FragmentEx { private boolean pull; private boolean actionbar; private boolean autoclose; + private boolean autonext; private boolean addresses; private long primary = -1; @@ -179,6 +180,7 @@ public class FragmentMessages extends FragmentEx { threading = prefs.getBoolean("threading", true); actionbar = prefs.getBoolean("actionbar", true); autoclose = prefs.getBoolean("autoclose", true); + autonext = prefs.getBoolean("autonext", false); addresses = prefs.getBoolean("addresses", true); } @@ -1860,8 +1862,9 @@ public class FragmentMessages extends FragmentEx { @Override public void onChanged(@Nullable PagedList messages) { if (messages == null || - (viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0 && autoclose)) { - finish(); + (viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0 && + (autoclose || autonext))) { + autoCloseNext(); return; } @@ -1921,7 +1924,7 @@ public class FragmentMessages extends FragmentEx { handleExpand(expand.id); } } else { - if (autoCloseCount > 0 && autoclose) { + if (autoCloseCount > 0 && (autoclose || autonext)) { int count = 0; for (int i = 0; i < messages.size(); i++) { TupleMessageEx message = messages.get(i); @@ -1933,11 +1936,11 @@ public class FragmentMessages extends FragmentEx { } Log.i("Auto close=" + count); - // Auto close when: + // Auto close/next when: // - no more non archived/trashed/sent messages if (count == 0) { - finish(); + autoCloseNext(); return; } } @@ -2025,6 +2028,25 @@ public class FragmentMessages extends FragmentEx { }); } + private void autoCloseNext() { + if (autoclose) + finish(); + else if (autonext) { + ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); + ViewModelMessages.Target[] pn = model.getPrevNext(thread); + if (pn[1] == null) + finish(); + else { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast( + new Intent(ActivityView.ACTION_VIEW_THREAD) + .putExtra("account", pn[1].account) + .putExtra("thread", pn[1].thread) + .putExtra("id", pn[1].id)); + } + } + } + private void handleExpand(long id) { Bundle args = new Bundle(); args.putLong("id", id); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 36f48b972e..e69e8aa537 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -70,6 +70,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS private SwitchCompat swSwipe; private SwitchCompat swActionbar; private SwitchCompat swAutoClose; + private SwitchCompat swAutoNext; private SwitchCompat swAutoRead; private SwitchCompat swCollapse; private SwitchCompat swAutoMove; @@ -111,6 +112,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS swSwipe = view.findViewById(R.id.swSwipe); swActionbar = view.findViewById(R.id.swActionbar); swAutoClose = view.findViewById(R.id.swAutoClose); + swAutoNext = view.findViewById(R.id.swAutoNext); swAutoRead = view.findViewById(R.id.swAutoRead); swCollapse = view.findViewById(R.id.swCollapse); swAutoMove = view.findViewById(R.id.swAutoMove); @@ -293,9 +295,19 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("autoclose", checked).apply(); + swAutoNext.setEnabled(!checked); } }); + swAutoNext.setChecked(prefs.getBoolean("autonext", false)); + swAutoNext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("autonext", checked).apply(); + } + }); + swAutoNext.setEnabled(!swAutoClose.isChecked()); + swAutoRead.setChecked(prefs.getBoolean("autoread", false)); swAutoRead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index 4a9f1a1e07..8f1db9fd3d 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -359,6 +359,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swAutoClose" /> + + Swipe actions Conversation action bar Automatically close conversations + Automatically go to next conversation on close conversation Automatically mark messages read on moving messages Collapse messages in conversations on \'back\' Confirm moving messages