From 428734bddeb7eea9b63d6d8e965d27beb9e7bc93 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 25 Sep 2020 23:38:31 +0800 Subject: Setting swipe action threshold is available. --- .../Event/ChangeSwipeActionThresholdEvent.java | 9 +++++++++ .../infinityforreddit/Fragment/PostFragment.java | 6 ++++++ .../Settings/SwipeActionPreferenceFragment.java | 10 ++++++++++ .../infinityforreddit/Utils/SharedPreferencesUtils.java | 3 +-- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeSwipeActionThresholdEvent.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeSwipeActionThresholdEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeSwipeActionThresholdEvent.java new file mode 100644 index 00000000..d040e0fe --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeSwipeActionThresholdEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangeSwipeActionThresholdEvent { + public float swipeActionThreshold; + + public ChangeSwipeActionThresholdEvent(float swipeActionThreshold) { + this.swipeActionThreshold = swipeActionThreshold; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 5918ddb1..fcf7db71 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -81,6 +81,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVote import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeStartAutoplayVisibleAreaOffsetEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeSwipeActionThresholdEvent; import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent; @@ -1228,6 +1229,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onChangeSwipeActionThresholdEvent(ChangeSwipeActionThresholdEvent changeSwipeActionThresholdEvent) { + swipeActionThreshold = changeSwipeActionThresholdEvent.swipeActionThreshold; + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java index c9d2908c..78844f06 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Settings; import android.os.Bundle; +import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; @@ -9,6 +10,7 @@ import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.Event.ChangeDisableSwipingBetweenTabsEvent; import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeSwipeActionThresholdEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; @@ -22,6 +24,7 @@ public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat { SwitchPreference enableSwipeActionSwitch = findPreference(SharedPreferencesUtils.ENABLE_SWIPE_ACTION); SwitchPreference vibrateWhenActionTriggeredSwitch = findPreference(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED); SwitchPreference disableSwipingBetweenTabsSwitch = findPreference(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS); + ListPreference swipeActionThresholdListPreference = findPreference(SharedPreferencesUtils.SWIPE_ACTION_THRESHOLD); if (enableSwipeActionSwitch != null) { enableSwipeActionSwitch.setOnPreferenceChangeListener((preference, newValue) -> { @@ -42,5 +45,12 @@ public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + if (swipeActionThresholdListPreference != null) { + swipeActionThresholdListPreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeSwipeActionThresholdEvent(Float.parseFloat((String) newValue))); + return true; + }); + } } } \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 2c48bc67..99f90024 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -119,6 +119,7 @@ public class SharedPreferencesUtils { public static final String VIBRATE_WHEN_ACTION_TRIGGERED = "vibrate_when_action_triggered"; public static final String DISABLE_SWIPING_BETWEEN_TABS = "disable_swiping_between_tabs"; public static final String ENABLE_SWIPE_ACTION = "enable_swipe_action"; + public static final String SWIPE_ACTION_THRESHOLD = "swipe_action_threshold"; public static final String PULL_TO_REFRESH = "pull_to_refresh"; public static final String REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER = "require_auth_to_account_section"; public static final String LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT = "long_press_to_hide_toolbar_in_compact_layout"; @@ -164,7 +165,6 @@ public class SharedPreferencesUtils { public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3 = "other_activities_bottom_app_bar_option_3"; public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4 = "other_activities_bottom_app_bar_option_4"; public static final String OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB = "other_activities_bottom_app_bar_fab"; - public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS = 0; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS = 1; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX = 2; @@ -174,7 +174,6 @@ public class SharedPreferencesUtils { public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE = 2; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT = 3; public static final int MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH = 4; - public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME = 0; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS = 1; public static final int OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX = 2; -- cgit v1.2.3