mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-29 11:15:51 +00:00
Made swipe listener screen density aware
This commit is contained in:
parent
bbe2c76ee8
commit
910a7a1f5d
2 changed files with 23 additions and 21 deletions
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue