From c0484de506ce22e020408a54f5ec9b92a4e60d8c Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Sun, 19 Mar 2023 11:20:46 -0300 Subject: [PATCH] feat: add toggle to disable double tap to swipe action --- .../joinmastodon/android/GlobalUserPreferences.java | 3 +++ .../android/fragments/HomeTabFragment.java | 2 +- .../android/fragments/NotificationsFragment.java | 2 +- .../android/fragments/SettingsFragment.java | 5 +++++ .../ic_fluent_double_tap_swipe_right_24_regular.xml | 11 +++++++++++ .../ic_fluent_double_tap_swipe_up_24_regular.xml | 9 +++++++++ mastodon/src/main/res/values/strings_mo.xml | 1 + 7 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_right_24_regular.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_up_24_regular.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index e9e403e1f..74b037be8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -49,6 +49,7 @@ public class GlobalUserPreferences{ public static boolean autoHideFab; public static boolean unreadNotifications; public static boolean defaultToUnlistedReplies; + public static boolean disableDoubleTapToSwipe; public static String publishButtonText; public static ThemePreference theme; public static ColorPreference color; @@ -105,6 +106,7 @@ public class GlobalUserPreferences{ autoHideFab=prefs.getBoolean("autoHideFab", true); unreadNotifications=prefs.getBoolean("unreadNotifications", false); defaultToUnlistedReplies=prefs.getBoolean("defaultToUnlistedReplies", false); + disableDoubleTapToSwipe=prefs.getBoolean("disableDoubleTapToSwipe", false); publishButtonText=prefs.getString("publishButtonText", ""); theme=ThemePreference.values()[prefs.getInt("theme", 0)]; recentLanguages=fromJson(prefs.getString("recentLanguages", "{}"), recentLanguagesType, new HashMap<>()); @@ -158,6 +160,7 @@ public class GlobalUserPreferences{ .putString("publishButtonText", publishButtonText) .putBoolean("bottomEncoding", bottomEncoding) .putBoolean("defaultToUnlistedReplies", defaultToUnlistedReplies) + .putBoolean("disableDoubleTapToSwipe", disableDoubleTapToSwipe) .putInt("theme", theme.ordinal()) .putString("color", color.name()) .putString("recentLanguages", gson.toJson(recentLanguages)) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java index 79c209b5c..8eccd2c25 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -477,7 +477,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab @Override public void scrollToTop(){ - if (((ScrollableToTop) fragments[pager.getCurrentItem()]).isScrolledToTop()) { + if (((ScrollableToTop) fragments[pager.getCurrentItem()]).isScrolledToTop() && !GlobalUserPreferences.disableDoubleTapToSwipe) { int nextPage = (pager.getCurrentItem() + 1) % count; navigateTo(nextPage); return; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java index 4cf60a893..aaed1c26f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java @@ -202,7 +202,7 @@ public class NotificationsFragment extends MastodonToolbarFragment implements Sc @Override public void scrollToTop(){ - if (getFragmentForPage(pager.getCurrentItem()).isScrolledToTop()) { + if (getFragmentForPage(pager.getCurrentItem()).isScrolledToTop() && !GlobalUserPreferences.disableDoubleTapToSwipe) { int nextPage = (pager.getCurrentItem() + 1) % tabViews.length; pager.setCurrentItem(nextPage, true); return; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java index 56a25aebb..910a0bf9d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java @@ -211,6 +211,11 @@ public class SettingsFragment extends MastodonToolbarFragment{ GlobalUserPreferences.save(); needAppRestart=true; })); + items.add(new SwitchItem(R.string.mo_disable_double_tap_to_swipe_between_tabs, R.drawable.ic_fluent_double_tap_swipe_right_24_regular, GlobalUserPreferences.disableDoubleTapToSwipe, i->{ + GlobalUserPreferences.disableDoubleTapToSwipe=i.checked; + GlobalUserPreferences.save(); + needAppRestart=true; + })); items.add(new HeaderItem(R.string.mo_composer_behavior)); diff --git a/mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_right_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_right_24_regular.xml new file mode 100644 index 000000000..246962e19 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_right_24_regular.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_up_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_up_24_regular.xml new file mode 100644 index 000000000..9ba137e44 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_double_tap_swipe_up_24_regular.xml @@ -0,0 +1,9 @@ + + + diff --git a/mastodon/src/main/res/values/strings_mo.xml b/mastodon/src/main/res/values/strings_mo.xml index 0d0e2cacb..03de465a7 100644 --- a/mastodon/src/main/res/values/strings_mo.xml +++ b/mastodon/src/main/res/values/strings_mo.xml @@ -49,6 +49,7 @@ 7 days Open in App + Disable double tap to swipe between tabs \ No newline at end of file