diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index a46f846661..88139c8fdd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -74,6 +74,7 @@ public class GlobalUserPreferences{ public static boolean doubleTapToSearch; public static boolean doubleTapToSwipe; public static boolean confirmBeforeReblog; + public static boolean hapticFeedback; public static boolean replyLineAboveHeader; public static boolean swapBookmarkWithBoostAction; public static boolean mentionRebloggerAutomatically; @@ -154,6 +155,7 @@ public static void load(){ doubleTapToSwipe =prefs.getBoolean("doubleTapToSwipe", true); replyLineAboveHeader=prefs.getBoolean("replyLineAboveHeader", true); confirmBeforeReblog=prefs.getBoolean("confirmBeforeReblog", false); + hapticFeedback=prefs.getBoolean("hapticFeedback", true); swapBookmarkWithBoostAction=prefs.getBoolean("swapBookmarkWithBoostAction", false); mentionRebloggerAutomatically=prefs.getBoolean("mentionRebloggerAutomatically", false); showPostsWithoutAlt=prefs.getBoolean("showPostsWithoutAlt", true); @@ -225,6 +227,7 @@ public static void save(){ .putBoolean("replyLineAboveHeader", replyLineAboveHeader) .putBoolean("confirmBeforeReblog", confirmBeforeReblog) .putBoolean("swapBookmarkWithBoostAction", swapBookmarkWithBoostAction) + .putBoolean("hapticFeedback", hapticFeedback) .putBoolean("mentionRebloggerAutomatically", mentionRebloggerAutomatically) .putBoolean("showDividers", showDividers) .putBoolean("relocatePublishButton", relocatePublishButton) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java index c783b3cfcf..dc4e0c72a8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.settings; +import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; @@ -39,7 +40,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment impleme private CheckableListItem remoteLoadingItem, showBoostsItem, showRepliesItem, loadNewPostsItem, seeNewPostsBtnItem, overlayMediaItem; // MOSHIDON - private CheckableListItem mentionRebloggerAutomaticallyItem, showPostsWithoutAltItem; + private CheckableListItem mentionRebloggerAutomaticallyItem, hapticFeedbackItem, showPostsWithoutAltItem; @Override public void onCreate(Bundle savedInstanceState){ @@ -75,6 +76,11 @@ public void onCreate(Bundle savedInstanceState){ replyVisibilityItem=new ListItem<>(R.string.sk_settings_reply_visibility, getReplyVisibilityString(), R.drawable.ic_fluent_chat_24_regular, this::onReplyVisibilityClick) ); + // add a haptic feedback item for devices running Android 11 and below, + // as some OEMs do not implement the system setting haptic feedback setting + if(Build.VERSION.SDK_INT<=Build.VERSION_CODES.R) + items.add(hapticFeedbackItem=new CheckableListItem<>(R.string.mo_haptic_feedback, R.string.mo_setting_haptic_feedback_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.hapticFeedback, R.drawable.ic_fluent_phone_vibrate_24_regular, i->toggleCheckableItem(hapticFeedbackItem), true)); + loadNewPostsItem.checkedChangeListener=checked->onLoadNewPostsClick(); seeNewPostsBtnItem.isEnabled=loadNewPostsItem.checked; @@ -211,6 +217,7 @@ protected void onHidden(){ GlobalUserPreferences.showNewPostsButton=seeNewPostsBtnItem.checked; GlobalUserPreferences.allowRemoteLoading=remoteLoadingItem.checked; GlobalUserPreferences.mentionRebloggerAutomatically=mentionRebloggerAutomaticallyItem.checked; + GlobalUserPreferences.hapticFeedback=hapticFeedbackItem.checked; GlobalUserPreferences.showPostsWithoutAlt=showPostsWithoutAltItem.checked; GlobalUserPreferences.save(); AccountLocalPreferences lp=getLocalPrefs(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java index c7b2dc3f87..e4dbdcc7fa 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java @@ -434,6 +434,8 @@ private void applyInteraction(View v, Consumer interactionConsumer) { } private static void vibrateForAction(View view, boolean isPositive) { + if (!GlobalUserPreferences.hapticFeedback) return; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { view.performHapticFeedback(isPositive ? HapticFeedbackConstants.CONFIRM : HapticFeedbackConstants.REJECT); return;