From e45e2295920ad983be7782a01b16135aff92737a Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 5 May 2023 22:56:45 +0200 Subject: [PATCH] Set swipe velocity threshold --- .../main/java/eu/faircode/email/ApplicationEx.java | 13 +++++++++++++ .../java/eu/faircode/email/FragmentMessages.java | 12 ++++++++++-- .../eu/faircode/email/FragmentOptionsBehavior.java | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 281dd76857..62351287d8 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -700,6 +700,19 @@ public class ApplicationEx extends Application editor.putBoolean("plain_only_reply", true); } else if (version < 2046) editor.remove("message_junk"); + else if (version < 2069) { + if (prefs.contains("swipe_sensitivity") && !prefs.contains("swipe_sensitivity_updated")) { + int swipe_sensitivity = prefs.getInt("swipe_sensitivity", FragmentOptionsBehavior.DEFAULT_SWIPE_SENSITIVITY); + if (swipe_sensitivity > 0) { + swipe_sensitivity--; + if (swipe_sensitivity == FragmentOptionsBehavior.DEFAULT_SWIPE_SENSITIVITY) + editor.remove("swipe_sensitivity"); + else + editor.putInt("swipe_sensitivity", swipe_sensitivity - 1) + .putBoolean("swipe_sensitivity_updated", true); + } + } + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG) editor.remove("background_service"); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index a50f2815b2..b45975e068 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2748,14 +2748,22 @@ public class FragmentMessages extends FragmentBase @Override public float getSwipeEscapeVelocity(float defaultValue) { + return super.getSwipeEscapeVelocity(defaultValue) * getSwipeSensitivityFactor(); + } + + @Override + public float getSwipeVelocityThreshold(float defaultValue) { + return super.getSwipeVelocityThreshold(defaultValue) * getSwipeSensitivityFactor(); + } + + private int getSwipeSensitivityFactor() { int swipe_sensitivity = FragmentOptionsBehavior.DEFAULT_SWIPE_SENSITIVITY; Context context = getContext(); if (context != null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); swipe_sensitivity = prefs.getInt("swipe_sensitivity", swipe_sensitivity); } - return super.getSwipeEscapeVelocity(defaultValue) * - (FragmentOptionsBehavior.MAX_SWIPE_SENSITIVITY - swipe_sensitivity + 1); + return (FragmentOptionsBehavior.MAX_SWIPE_SENSITIVITY - swipe_sensitivity + 1); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index e9c9570c6b..ca025b0321 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -107,7 +107,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private boolean accessibility; final static int MAX_SWIPE_SENSITIVITY = 10; - final static int DEFAULT_SWIPE_SENSITIVITY = 7; + final static int DEFAULT_SWIPE_SENSITIVITY = 6; final static int REQUEST_DEFAULT_FOLDER = 1;