aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-09-15 15:43:26 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-09-15 15:43:26 +0000
commit9444599f4b4db7f41abc8f80c1826467e3cd402a (patch)
treeb249ddb3d841ba6528d1fb4135eaa0cbde2845af /app/src/main
parent7c23be5d2fc583e1aa1aa251287fee4c35f2c751 (diff)
downloadinfinity-for-reddit-9444599f4b4db7f41abc8f80c1826467e3cd402a.tar
infinity-for-reddit-9444599f4b4db7f41abc8f80c1826467e3cd402a.tar.gz
infinity-for-reddit-9444599f4b4db7f41abc8f80c1826467e3cd402a.tar.bz2
infinity-for-reddit-9444599f4b4db7f41abc8f80c1826467e3cd402a.tar.lz
infinity-for-reddit-9444599f4b4db7f41abc8f80c1826467e3cd402a.tar.xz
infinity-for-reddit-9444599f4b4db7f41abc8f80c1826467e3cd402a.tar.zst
infinity-for-reddit-9444599f4b4db7f41abc8f80c1826467e3cd402a.zip
Add an option to enable swipe action. Fix text color in FlairBottomSheetFragment.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FlairBottomSheetRecyclerViewAdapter.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeEnableSwipeActionSwitchEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/xml/swipe_action_preferences.xml5
7 files changed, 44 insertions, 4 deletions
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<FlairBottomSheetRecyclerViewAdapter.FlairViewHolder> {
private Context context;
private ArrayList<Flair> 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<Fl
super(itemView);
ButterKnife.bind(this, itemView);
this.itemView = itemView;
- flairTextView.setTextColor(flairColor);
+ flairTextView.setTextColor(flairTextColor);
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeEnableSwipeActionSwitchEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeEnableSwipeActionSwitchEvent.java
new file mode 100644
index 00000000..5c67246f
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeEnableSwipeActionSwitchEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.Event;
+
+public class ChangeEnableSwipeActionSwitchEvent {
+ public boolean enableSwipeAction;
+
+ public ChangeEnableSwipeActionSwitchEvent(boolean enableSwipeAction) {
+ this.enableSwipeAction = enableSwipeAction;
+ }
+}
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 7a2c5c00..e7807356 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -69,6 +69,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
+import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeMuteNSFWVideoEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
@@ -173,6 +174,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private boolean isShown = false;
private boolean savePostFeedScrolledPosition;
private boolean vibrateWhenActionTriggered;
+ private boolean enableSwipeAction;
private PostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller smoothScroller;
private Window window;
@@ -399,6 +401,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true);
+ enableSwipeAction = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false);
Locale locale = getResources().getConfiguration().locale;
if (postType == PostDataSource.TYPE_SEARCH) {
@@ -729,7 +732,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
});
- touchHelper.attachToRecyclerView(mPostRecyclerView);
+ if (enableSwipeAction) {
+ touchHelper.attachToRecyclerView(mPostRecyclerView);
+ }
mPostRecyclerView.setAdapter(mAdapter);
mPostRecyclerView.setCacheManager(mAdapter);
mPostRecyclerView.setPlayerInitializer(order -> {
@@ -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 @@
<string name="settings_swipe_action_title">Swipe Action</string>
<string name="settings_vibrate_when_action_triggered_title">Vibrate the phone when the action is triggered</string>
<string name="settings_disable_swiping_between_tabs_title">Disable Swiping Between Tabs</string>
+ <string name="settings_enable_swipe_action_title">Enable Swipe Action</string>
<string name="no_link_available">Cannot get the link</string>
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
@@ -2,6 +2,11 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreference
+ app:defaultValue="false"
+ app:key="enable_swipe_action"
+ app:title="@string/settings_enable_swipe_action_title" />
+
+ <SwitchPreference
app:defaultValue="true"
app:key="vibrate_when_action_triggered"
app:title="@string/settings_vibrate_when_action_triggered_title" />