mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +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);
|
boolean swipenav = prefs.getBoolean("swipenav", true);
|
||||||
if (swipenav) {
|
if (swipenav) {
|
||||||
Log.i("Swipe navigation");
|
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() {
|
rvMessage.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent ev) {
|
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) {
|
private void onActionMove(String folderType) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("account", account);
|
args.putLong("account", account);
|
||||||
|
|
|
@ -10,10 +10,10 @@ import androidx.annotation.NonNull;
|
||||||
public class SwipeListener implements View.OnTouchListener {
|
public class SwipeListener implements View.OnTouchListener {
|
||||||
private final GestureDetector gestureDetector;
|
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() {
|
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
|
||||||
private static final int MOVE_THRESHOLD = 100;
|
private final int MOVE_THRESHOLD = Helper.dp2pixels(context, 100); // dp
|
||||||
private static final int SPEED_THRESHOLD = 100;
|
private final int SPEED_THRESHOLD = Helper.dp2pixels(context, 100); // dp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onFling(MotionEvent me1, MotionEvent me2, float vx, float vy) {
|
public boolean onFling(MotionEvent me1, MotionEvent me2, float vx, float vy) {
|
||||||
|
@ -21,9 +21,10 @@ public class SwipeListener implements View.OnTouchListener {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
boolean consumed = false;
|
boolean consumed = false;
|
||||||
float dx = me2.getX() - me1.getX();
|
int dx = Math.round(me2.getX() - me1.getX());
|
||||||
float dy = me2.getY() - me1.getY();
|
int dy = Math.round(me2.getY() - me1.getY());
|
||||||
if (Math.abs(dx) > Math.abs(dy)) {
|
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)
|
if (Math.abs(dx) > MOVE_THRESHOLD && Math.abs(vx) > SPEED_THRESHOLD)
|
||||||
try {
|
try {
|
||||||
if (dx > 0)
|
if (dx > 0)
|
||||||
|
|
Loading…
Reference in a new issue