From ec59befb82b3f4ea69208b25361f10a041fbe29c Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 18 Jul 2019 14:04:14 +0200 Subject: [PATCH] Fixed swipe refresh on fast scroll --- FAQ.md | 1 - .../eu/faircode/email/FragmentMessages.java | 27 ++++++++++--------- .../eu/faircode/email/FragmentOptions.java | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/FAQ.md b/FAQ.md index e729a277bf..347e0ffe1d 100644 --- a/FAQ.md +++ b/FAQ.md @@ -31,7 +31,6 @@ For authorizing: * A [bug in Android](https://issuetracker.google.com/issues/62427912) "*... ActivityRecord not found for ...*" sometimes causes a crash after updating FairEmail. Reinstalling ([source](https://stackoverflow.com/questions/46309428/android-activitythread-reportsizeconfigurations-causes-app-to-freeze-with-black)) migth fix the problem. * Encryption with [YubiKey](https://www.yubico.com/) results into an infinite loop. FairEmail follows the latest version of the [OpenKeychain API](https://github.com/open-keychain/openpgp-api), so this is likely being caused by an external bug. * A bug in the Nova Launcher lets FairEmail crash with a *java.lang.StackOverflowError* when the Nova Launcher has access to the accessibility service. -* Fast scrolling sometimes triggers a swipe refresh. Unfortunately, there is no way to detect that a fast scroll is in progress and to disable swipe refreshing. ## Planned features diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6d0e603f9c..7c76ed28c3 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -192,7 +192,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private boolean date; private boolean threading; - private boolean pull; private boolean swipenav; private boolean autoscroll; private boolean actionbar; @@ -309,11 +308,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - if (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER) - pull = prefs.getBoolean("pull", true); - else - pull = false; - swipenav = prefs.getBoolean("swipenav", true); autoscroll = (prefs.getBoolean("autoscroll", false) || viewType == AdapterMessage.ViewType.THREAD); date = prefs.getBoolean("date", true); @@ -900,12 +894,24 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. fabMore.show(); else fabMore.hide(); - updateSwipeRefresh(); } }); } - updateSwipeRefresh(); + swipeRefresh.setOnChildScrollUpCallback(new SwipeRefreshLayout.OnChildScrollUpCallback() { + @Override + public boolean canChildScrollUp(@NonNull SwipeRefreshLayout parent, @Nullable View child) { + if (viewType != AdapterMessage.ViewType.UNIFIED && viewType != AdapterMessage.ViewType.FOLDER) + return true; + if (!prefs.getBoolean("pull", true)) + return true; + if (swiping) + return true; + if (selectionTracker != null && selectionTracker.hasSelection()) + return true; + return rvMessage.canScrollVertically(-1); + } + }); pgpService = new OpenPgpServiceConnection(getContext(), "org.sufficientlysecure.keychain"); pgpService.bindToService(); @@ -946,10 +952,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. super.onDestroy(); } - private void updateSwipeRefresh() { - swipeRefresh.setEnabled(pull && !swiping && (selectionTracker == null || !selectionTracker.hasSelection())); - } - private void scrollToVisibleItem(LinearLayoutManager llm, boolean bottom) { int pos = llm.findLastVisibleItemPosition(); if (pos == RecyclerView.NO_POSITION) @@ -1294,7 +1296,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. public void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState) { super.onSelectedChanged(viewHolder, actionState); swiping = (actionState == ItemTouchHelper.ACTION_STATE_SWIPE); - updateSwipeRefresh(); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index efe71139fe..72c29d841e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -40,7 +40,7 @@ public class FragmentOptions extends FragmentBase { static String[] OPTIONS_RESTART = new String[]{ "startup", "date", "threading", "avatars", "identicons", "circular", "name_email", "subject_italic", "flags", "preview", "addresses", "attachments_alt", "contrast", "monospaced", "autohtml", "autoimages", "actionbar", - "pull", "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext", + "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext", "subscriptions", "debug", "biometrics" };