mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-04 07:17:12 +01:00
Add an option to disable vibration when swipe action is triggered.
This commit is contained in:
parent
4870d2bee6
commit
908cd0aaab
@ -0,0 +1,9 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.Event;
|
||||||
|
|
||||||
|
public class ChangeVibrateWhenActionTriggeredEvent {
|
||||||
|
public boolean vibrateWhenActionTriggered;
|
||||||
|
|
||||||
|
public ChangeVibrateWhenActionTriggeredEvent(boolean vibrateWhenActionTriggered) {
|
||||||
|
this.vibrateWhenActionTriggered = vibrateWhenActionTriggered;
|
||||||
|
}
|
||||||
|
}
|
@ -79,6 +79,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeStartAutoplayVisibleAreaOffsetEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeStartAutoplayVisibleAreaOffsetEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
|
||||||
@ -171,6 +172,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
private boolean hasPost = false;
|
private boolean hasPost = false;
|
||||||
private boolean isShown = false;
|
private boolean isShown = false;
|
||||||
private boolean savePostFeedScrolledPosition;
|
private boolean savePostFeedScrolledPosition;
|
||||||
|
private boolean vibrateWhenActionTriggered;
|
||||||
private PostRecyclerViewAdapter mAdapter;
|
private PostRecyclerViewAdapter mAdapter;
|
||||||
private RecyclerView.SmoothScroller smoothScroller;
|
private RecyclerView.SmoothScroller smoothScroller;
|
||||||
private Window window;
|
private Window window;
|
||||||
@ -396,6 +398,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
|
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
|
||||||
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
|
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
|
||||||
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
|
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
|
||||||
|
vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true);
|
||||||
Locale locale = getResources().getConfiguration().locale;
|
Locale locale = getResources().getConfiguration().locale;
|
||||||
|
|
||||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||||
@ -640,7 +643,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
backgroundRight = new ColorDrawable(customThemeWrapper.getUpvoted());
|
backgroundRight = new ColorDrawable(customThemeWrapper.getUpvoted());
|
||||||
drawableLeft = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_downward_black_24dp, null);
|
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);
|
drawableRight = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_upward_black_24dp, null);
|
||||||
int screenBottom = window.getDecorView().getHeight();
|
|
||||||
touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
|
touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
|
||||||
boolean exceedThreshold = false;
|
boolean exceedThreshold = false;
|
||||||
|
|
||||||
@ -681,7 +683,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
|
if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
|
||||||
if (!exceedThreshold) {
|
if (!exceedThreshold) {
|
||||||
exceedThreshold = true;
|
exceedThreshold = true;
|
||||||
if (v != null) {
|
if (vibrateWhenActionTriggered && v != null) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
v.vibrate(VibrationEffect.createOneShot(10, 175));
|
v.vibrate(VibrationEffect.createOneShot(10, 175));
|
||||||
} else {
|
} else {
|
||||||
@ -706,7 +708,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
|
if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
|
||||||
if (!exceedThreshold) {
|
if (!exceedThreshold) {
|
||||||
exceedThreshold = true;
|
exceedThreshold = true;
|
||||||
if (v != null) {
|
if (vibrateWhenActionTriggered && v != null) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
v.vibrate(VibrationEffect.createOneShot(10, 175));
|
v.vibrate(VibrationEffect.createOneShot(10, 175));
|
||||||
} else {
|
} else {
|
||||||
@ -1169,6 +1171,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
savePostFeedScrolledPosition = changeSavePostFeedScrolledPositionEvent.savePostFeedScrolledPosition;
|
savePostFeedScrolledPosition = changeSavePostFeedScrolledPositionEvent.savePostFeedScrolledPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChangeVibrateWhenActionTriggeredEvent(ChangeVibrateWhenActionTriggeredEvent changeVibrateWhenActionTriggeredEvent) {
|
||||||
|
vibrateWhenActionTriggered = changeVibrateWhenActionTriggeredEvent.vibrateWhenActionTriggered;
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshAdapter() {
|
private void refreshAdapter() {
|
||||||
int previousPosition = -1;
|
int previousPosition = -1;
|
||||||
if (mLinearLayoutManager != null) {
|
if (mLinearLayoutManager != null) {
|
||||||
|
@ -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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -121,6 +121,7 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String GIF_DOWNLOAD_LOCATION = "gif_download_location";
|
public static final String GIF_DOWNLOAD_LOCATION = "gif_download_location";
|
||||||
public static final String VIDEO_DOWNLOAD_LOCATION = "video_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 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_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
||||||
public static final String MAIN_PAGE_TAB_1_TITLE = "_main_page_tab_1_title";
|
public static final String MAIN_PAGE_TAB_1_TITLE = "_main_page_tab_1_title";
|
||||||
|
@ -478,6 +478,8 @@
|
|||||||
<string name="settings_gif_download_location_title">Gif Download Location</string>
|
<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_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_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>
|
<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="block_user_failed">Failed to block user</string>
|
||||||
|
|
||||||
<string name="view_full_comment_markdown">View Full Markdown</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>
|
</resources>
|
||||||
|
@ -39,4 +39,8 @@
|
|||||||
app:key="swap_tap_and_long_in_comments"
|
app:key="swap_tap_and_long_in_comments"
|
||||||
app:title="@string/settings_swap_tap_and_long_title" />
|
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>
|
</PreferenceScreen>
|
9
app/src/main/res/xml/swipe_action_preferences.xml
Normal file
9
app/src/main/res/xml/swipe_action_preferences.xml
Normal file
@ -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>
|
Loading…
Reference in New Issue
Block a user