diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 618de39247..e8feef711f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -556,6 +556,23 @@ public class FragmentMessages extends FragmentBase { boolean swipenav = prefs.getBoolean("swipenav", true); if (swipenav) { Log.i("Swipe navigation"); + + final SwipeListener swipeListener = new SwipeListener(getContext(), new SwipeListener.ISwipeListener() { + @Override + public boolean onSwipeRight() { + if (previous != null) + navigate(previous, true); + return (previous != null); + } + + @Override + public boolean onSwipeLeft() { + if (next != null) + navigate(next, false); + return (next != null); + } + }); + rvMessage.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent ev) { @@ -1003,22 +1020,6 @@ public class FragmentMessages extends FragmentBase { } }; - private SwipeListener swipeListener = new SwipeListener(getContext(), new SwipeListener.ISwipeListener() { - @Override - public boolean onSwipeRight() { - if (previous != null) - navigate(previous, true); - return (previous != null); - } - - @Override - public boolean onSwipeLeft() { - if (next != null) - navigate(next, false); - return (next != null); - } - }); - private void onActionMove(String folderType) { Bundle args = new Bundle(); args.putLong("account", account); diff --git a/app/src/main/java/eu/faircode/email/SwipeListener.java b/app/src/main/java/eu/faircode/email/SwipeListener.java index f3b177709f..6f3e7c3c14 100644 --- a/app/src/main/java/eu/faircode/email/SwipeListener.java +++ b/app/src/main/java/eu/faircode/email/SwipeListener.java @@ -10,10 +10,10 @@ import androidx.annotation.NonNull; public class SwipeListener implements View.OnTouchListener { private final GestureDetector gestureDetector; - public SwipeListener(Context context, final ISwipeListener listener) { + SwipeListener(final Context context, final ISwipeListener listener) { gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { - private static final int MOVE_THRESHOLD = 100; - private static final int SPEED_THRESHOLD = 100; + private final int MOVE_THRESHOLD = Helper.dp2pixels(context, 100); // dp + private final int SPEED_THRESHOLD = Helper.dp2pixels(context, 100); // dp @Override public boolean onFling(MotionEvent me1, MotionEvent me2, float vx, float vy) { @@ -21,9 +21,10 @@ public class SwipeListener implements View.OnTouchListener { return false; boolean consumed = false; - float dx = me2.getX() - me1.getX(); - float dy = me2.getY() - me1.getY(); + int dx = Math.round(me2.getX() - me1.getX()); + int dy = Math.round(me2.getY() - me1.getY()); if (Math.abs(dx) > Math.abs(dy)) { + Log.i("Swipe dx=" + dx + "/" + MOVE_THRESHOLD + " vx=" + vx + "/" + SPEED_THRESHOLD); if (Math.abs(dx) > MOVE_THRESHOLD && Math.abs(vx) > SPEED_THRESHOLD) try { if (dx > 0)