From f645c8b396948803dfbae20db80a8bf36d1d1255 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 30 Jan 2019 14:41:21 +0000 Subject: [PATCH] Removed auto next on close --- FAQ.md | 1 + .../eu/faircode/email/FragmentMessages.java | 71 +++++-------------- .../eu/faircode/email/FragmentOptions.java | 12 ---- .../eu/faircode/email/ViewModelMessages.java | 5 +- app/src/main/res/layout/fragment_options.xml | 14 +--- 5 files changed, 22 insertions(+), 81 deletions(-) diff --git a/FAQ.md b/FAQ.md index 44988b35d9..f066b03d62 100644 --- a/FAQ.md +++ b/FAQ.md @@ -36,6 +36,7 @@ Anything on this list is in random order and *might* be added in the near future ## 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 next message: after closing a conversation thread it is not possible anymore to reliably determine the next conversation thread without delays. Note that most apps implementing something similar work with individual messages instead of conversations and don't support two way synchronization. * 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. * Badge count: there is no standard Android API for this and third party solutions might stop working anytime. For example *ShortcutBadger* [has lots of problems](https://github.com/leolin310148/ShortcutBadger/issues). You can use the provided widget instead. diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index d46cbe9e90..316c3139c5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -117,7 +117,6 @@ public class FragmentMessages extends FragmentBase { private boolean pull; private boolean actionbar; private boolean autoclose; - private boolean autonext; private boolean addresses; private long primary = -1; @@ -129,7 +128,6 @@ public class FragmentMessages extends FragmentBase { private AdapterMessage.ViewType viewType; private SelectionTracker selectionTracker = null; - private Long last_next = null; private int autoCloseCount = 0; private boolean autoExpand = true; private Map> values = new HashMap<>(); @@ -188,7 +186,6 @@ public class FragmentMessages extends FragmentBase { 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); } @@ -292,11 +289,15 @@ public class FragmentMessages extends FragmentBase { @Override public void onNext(boolean exists, Long id) { - if (id != null) - last_next = id; bottom_navigation.getMenu().findItem(R.id.action_next).setIntent(new Intent().putExtra("id", id)); bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(id != null); } + + @Override + public void onDeleted() { + bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(false); + bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(false); + } }); } } else { @@ -1846,9 +1847,8 @@ public class FragmentMessages extends FragmentBase { @Override public void onChanged(@Nullable PagedList messages) { if (messages == null || - (viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0 && - (autoclose || autonext))) { - handleAutoClose(); + (viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0 && autoclose)) { + finish(); return; } @@ -1947,7 +1947,7 @@ public class FragmentMessages extends FragmentBase { handleExpand(expand.id); } } else { - if (autoCloseCount > 0 && (autoclose || autonext)) { + if (autoCloseCount > 0 && autoclose) { int count = 0; for (int i = 0; i < messages.size(); i++) { TupleMessageEx message = messages.get(i); @@ -1964,7 +1964,7 @@ public class FragmentMessages extends FragmentBase { // - no more non archived/trashed/sent messages if (count == 0) { - handleAutoClose(); + finish(); return; } } @@ -2079,40 +2079,6 @@ public class FragmentMessages extends FragmentBase { }.execute(this, args, "messages:expand"); } - private void handleAutoClose() { - if (autoclose) - finish(); - else if (autonext) { - if (last_next != null) { - Log.i("Navigating to last next=" + last_next); - navigate(last_next); - return; - } - - ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); - model.observePrevNext(getViewLifecycleOwner(), thread, new ViewModelMessages.IPrevNext() { - private boolean once = false; - - @Override - public void onPrevious(boolean exists, Long id) { - // Do nothing - } - - @Override - public void onNext(boolean exists, Long id) { - if (once) - return; - once = true; - - if (id != null) - navigate(id); - if (!exists) - finish(); - } - }); - } - } - private void navigate(long id) { Bundle args = new Bundle(); args.putLong("id", id); @@ -2125,17 +2091,14 @@ public class FragmentMessages extends FragmentBase { @Override protected void onExecuted(Bundle args, EntityMessage message) { - if (message == null) { - finish(); - return; + if (message != null) { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast( + new Intent(ActivityView.ACTION_VIEW_THREAD) + .putExtra("account", message.account) + .putExtra("thread", message.thread) + .putExtra("id", message.id)); } - - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); - lbm.sendBroadcast( - new Intent(ActivityView.ACTION_VIEW_THREAD) - .putExtra("account", message.account) - .putExtra("thread", message.thread) - .putExtra("id", message.id)); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index b1f15388cf..c8abea5e4d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -74,7 +74,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private SwitchCompat swPull; private SwitchCompat swActionbar; private SwitchCompat swAutoClose; - private SwitchCompat swAutoNext; private SwitchCompat swAutoRead; private SwitchCompat swCollapse; private SwitchCompat swAutoMove; @@ -134,7 +133,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swPull = view.findViewById(R.id.swPull); 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); @@ -291,14 +289,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("autoclose", checked).apply(); - swAutoNext.setEnabled(!checked); - } - }); - - swAutoNext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("autonext", checked).apply(); } }); @@ -459,8 +449,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swPull.setChecked(prefs.getBoolean("pull", true)); swActionbar.setChecked(prefs.getBoolean("actionbar", true)); swAutoClose.setChecked(prefs.getBoolean("autoclose", true)); - swAutoNext.setChecked(prefs.getBoolean("autonext", false)); - swAutoNext.setEnabled(!swAutoClose.isChecked()); swAutoRead.setChecked(prefs.getBoolean("autoread", false)); swCollapse.setChecked(prefs.getBoolean("collapse", false)); swAutoMove.setChecked(!prefs.getBoolean("automove", false)); diff --git a/app/src/main/java/eu/faircode/email/ViewModelMessages.java b/app/src/main/java/eu/faircode/email/ViewModelMessages.java index 0203ec2153..4ed7243fb1 100644 --- a/app/src/main/java/eu/faircode/email/ViewModelMessages.java +++ b/app/src/main/java/eu/faircode/email/ViewModelMessages.java @@ -117,8 +117,7 @@ public class ViewModelMessages extends ViewModel { } Log.w("Observe previous/next gone thread=" + thread); - reportNext(intf, false, null); - reportPrevious(intf, false, null); + intf.onDeleted(); } }); } @@ -137,5 +136,7 @@ public class ViewModelMessages extends ViewModel { void onPrevious(boolean exists, Long id); void onNext(boolean exists, Long id); + + void onDeleted(); } } diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index 3cf8d2a020..be9546ecc5 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -386,18 +386,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swAutoClose" /> - -