From 9444599f4b4db7f41abc8f80c1826467e3cd402a Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 15 Sep 2020 23:43:26 +0800 Subject: Add an option to enable swipe action. Fix text color in FlairBottomSheetFragment. --- .../Adapter/FlairBottomSheetRecyclerViewAdapter.java | 6 +++--- .../Event/ChangeEnableSwipeActionSwitchEvent.java | 9 +++++++++ .../infinityforreddit/Fragment/PostFragment.java | 18 +++++++++++++++++- .../Settings/SwipeActionPreferenceFragment.java | 8 ++++++++ .../Utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/swipe_action_preferences.xml | 5 +++++ 7 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeEnableSwipeActionSwitchEvent.java (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FlairBottomSheetRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FlairBottomSheetRecyclerViewAdapter.java index 3f7f9892..0f016b53 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FlairBottomSheetRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FlairBottomSheetRecyclerViewAdapter.java @@ -26,13 +26,13 @@ import ml.docilealligator.infinityforreddit.R; public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter { private Context context; private ArrayList flairs; - private int flairColor; + private int flairTextColor; private ItemClickListener itemClickListener; public FlairBottomSheetRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper, ItemClickListener itemClickListener) { this.context = context; - flairColor = customThemeWrapper.getFlairBackgroundColor(); + flairTextColor = customThemeWrapper.getPrimaryTextColor(); this.itemClickListener = itemClickListener; } @@ -108,7 +108,7 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter { @@ -1186,6 +1191,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator { vibrateWhenActionTriggered = changeVibrateWhenActionTriggeredEvent.vibrateWhenActionTriggered; } + @Subscribe + public void onChangeEnableSwipeActionSwitchEvent(ChangeEnableSwipeActionSwitchEvent changeEnableSwipeActionSwitchEvent) { + if (touchHelper != null) { + if (changeEnableSwipeActionSwitchEvent.enableSwipeAction) { + touchHelper.attachToRecyclerView(mPostRecyclerView); + } else { + touchHelper.attachToRecyclerView(null); + } + } + } + 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 115cd4d3..c9d2908c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java @@ -8,6 +8,7 @@ import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.Event.ChangeDisableSwipingBetweenTabsEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; @@ -18,9 +19,16 @@ public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.swipe_action_preferences, rootKey); + SwitchPreference enableSwipeActionSwitch = findPreference(SharedPreferencesUtils.ENABLE_SWIPE_ACTION); SwitchPreference vibrateWhenActionTriggeredSwitch = findPreference(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED); SwitchPreference disableSwipingBetweenTabsSwitch = findPreference(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS); + if (enableSwipeActionSwitch != null) { + enableSwipeActionSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeEnableSwipeActionSwitchEvent((Boolean) newValue)); + return true; + }); + } if (vibrateWhenActionTriggeredSwitch != null) { vibrateWhenActionTriggeredSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeVibrateWhenActionTriggeredEvent((Boolean) newValue)); 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 338afe81..8612369f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -121,6 +121,7 @@ public class SharedPreferencesUtils { public static final String SEPARATE_FOLDER_FOR_EACH_SUBREDDIT = "separate_folder_for_each_subreddit"; 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 MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_1_TITLE = "_main_page_tab_1_title"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 46edd1fd..b881e2d9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -481,6 +481,7 @@ Swipe Action Vibrate the phone when the action is triggered Disable Swiping Between Tabs + Enable Swipe Action Cannot get the link diff --git a/app/src/main/res/xml/swipe_action_preferences.xml b/app/src/main/res/xml/swipe_action_preferences.xml index 8cf502b8..423035a7 100644 --- a/app/src/main/res/xml/swipe_action_preferences.xml +++ b/app/src/main/res/xml/swipe_action_preferences.xml @@ -1,6 +1,11 @@ + +