aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVibrateWhenActionTriggeredEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/values/strings.xml4
-rw-r--r--app/src/main/res/xml/gestures_and_buttons_preference.xml4
-rw-r--r--app/src/main/res/xml/swipe_action_preferences.xml9
7 files changed, 66 insertions, 3 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVibrateWhenActionTriggeredEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVibrateWhenActionTriggeredEvent.java
new file mode 100644
index 00000000..bef491d6
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVibrateWhenActionTriggeredEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.Event;
+
+public class ChangeVibrateWhenActionTriggeredEvent {
+ public boolean vibrateWhenActionTriggered;
+
+ public ChangeVibrateWhenActionTriggeredEvent(boolean vibrateWhenActionTriggered) {
+ this.vibrateWhenActionTriggered = vibrateWhenActionTriggered;
+ }
+}
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 f334b7fa..0d8c99ad 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -79,6 +79,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeStartAutoplayVisibleAreaOffsetEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent;
+import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
@@ -171,6 +172,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private boolean hasPost = false;
private boolean isShown = false;
private boolean savePostFeedScrolledPosition;
+ private boolean vibrateWhenActionTriggered;
private PostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller smoothScroller;
private Window window;
@@ -396,6 +398,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
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);
Locale locale = getResources().getConfiguration().locale;
if (postType == PostDataSource.TYPE_SEARCH) {
@@ -640,7 +643,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
backgroundRight = new ColorDrawable(customThemeWrapper.getUpvoted());
drawableLeft = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_downward_black_24dp, null);
drawableRight = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_upward_black_24dp, null);
- int screenBottom = window.getDecorView().getHeight();
touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
boolean exceedThreshold = false;
@@ -681,7 +683,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
if (!exceedThreshold) {
exceedThreshold = true;
- if (v != null) {
+ if (vibrateWhenActionTriggered && v != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(10, 175));
} else {
@@ -706,7 +708,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
if (!exceedThreshold) {
exceedThreshold = true;
- if (v != null) {
+ if (vibrateWhenActionTriggered && v != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(10, 175));
} else {
@@ -1169,6 +1171,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
savePostFeedScrolledPosition = changeSavePostFeedScrolledPositionEvent.savePostFeedScrolledPosition;
}
+ @Subscribe
+ public void onChangeVibrateWhenActionTriggeredEvent(ChangeVibrateWhenActionTriggeredEvent changeVibrateWhenActionTriggeredEvent) {
+ vibrateWhenActionTriggered = changeVibrateWhenActionTriggeredEvent.vibrateWhenActionTriggered;
+ }
+
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
new file mode 100644
index 00000000..80358559
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SwipeActionPreferenceFragment.java
@@ -0,0 +1,29 @@
+package ml.docilealligator.infinityforreddit.Settings;
+
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.SwitchPreference;
+
+import org.greenrobot.eventbus.EventBus;
+
+import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+
+public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.swipe_action_preferences, rootKey);
+
+ SwitchPreference vibrateWhenActionTriggeredSwitch = findPreference(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED);
+
+ if (vibrateWhenActionTriggeredSwitch != null) {
+ vibrateWhenActionTriggeredSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeVibrateWhenActionTriggeredEvent((Boolean) 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 dccf3e1b..50ab5e5a 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 GIF_DOWNLOAD_LOCATION = "gif_download_location";
public static final String VIDEO_DOWNLOAD_LOCATION = "video_download_location";
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 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 0cb693f3..882a9dc4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -478,6 +478,8 @@
<string name="settings_gif_download_location_title">Gif Download Location</string>
<string name="settings_video_download_location_title">Video Download Location</string>
<string name="settings_separate_folder_for_each_subreddit">Separate Folder for Each Subreddit</string>
+ <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="no_link_available">Cannot get the link</string>
@@ -877,5 +879,7 @@
<string name="block_user_failed">Failed to block user</string>
<string name="view_full_comment_markdown">View Full Markdown</string>
+ <!-- TODO: Remove or change this placeholder text -->
+ <string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
diff --git a/app/src/main/res/xml/gestures_and_buttons_preference.xml b/app/src/main/res/xml/gestures_and_buttons_preference.xml
index 7a279247..7b883826 100644
--- a/app/src/main/res/xml/gestures_and_buttons_preference.xml
+++ b/app/src/main/res/xml/gestures_and_buttons_preference.xml
@@ -39,4 +39,8 @@
app:key="swap_tap_and_long_in_comments"
app:title="@string/settings_swap_tap_and_long_title" />
+ <Preference
+ app:title="@string/settings_swipe_action_title"
+ app:fragment="ml.docilealligator.infinityforreddit.Settings.SwipeActionPreferenceFragment" />
+
</PreferenceScreen> \ No newline at end of file
diff --git a/app/src/main/res/xml/swipe_action_preferences.xml b/app/src/main/res/xml/swipe_action_preferences.xml
new file mode 100644
index 00000000..daba347b
--- /dev/null
+++ b/app/src/main/res/xml/swipe_action_preferences.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <SwitchPreference
+ app:defaultValue="true"
+ app:key="vibrate_when_action_triggered"
+ app:title="@string/settings_vibrate_when_action_triggered_title" />
+
+</PreferenceScreen> \ No newline at end of file