diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-14 16:22:57 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-14 16:22:57 +0000 |
commit | 908cd0aaab5ebea29428dd2ad82dc77ed90616aa (patch) | |
tree | d7752d2db92f66a64aac86a2fe700c40e8c3837d /app/src/main/java | |
parent | 4870d2bee64e454faf0f6a43269d0e00aaba52e7 (diff) | |
download | infinity-for-reddit-908cd0aaab5ebea29428dd2ad82dc77ed90616aa.tar infinity-for-reddit-908cd0aaab5ebea29428dd2ad82dc77ed90616aa.tar.gz infinity-for-reddit-908cd0aaab5ebea29428dd2ad82dc77ed90616aa.tar.bz2 infinity-for-reddit-908cd0aaab5ebea29428dd2ad82dc77ed90616aa.tar.lz infinity-for-reddit-908cd0aaab5ebea29428dd2ad82dc77ed90616aa.tar.xz infinity-for-reddit-908cd0aaab5ebea29428dd2ad82dc77ed90616aa.tar.zst infinity-for-reddit-908cd0aaab5ebea29428dd2ad82dc77ed90616aa.zip |
Add an option to disable vibration when swipe action is triggered.
Diffstat (limited to 'app/src/main/java')
4 files changed, 49 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"; |