Skip to content

Commit

Permalink
revert: readd haptic feedback setting on Android 11 and lower
Browse files Browse the repository at this point in the history
Some OEMs do not implement a systemwide setting for touch feedback.

This reverts commit e0a793e.
  • Loading branch information
FineFindus committed May 28, 2024
1 parent e2e8173 commit fa0efe1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package org.joinmastodon.android.fragments.settings;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.session.AccountLocalPreferences;
Expand All @@ -22,10 +32,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import java.util.stream.Stream;

public class SettingsBehaviorFragment extends BaseSettingsFragment<Void> implements HasAccountID{
private ListItem<Void> languageItem;
Expand All @@ -39,7 +46,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment<Void> impleme
private CheckableListItem<Void> remoteLoadingItem, showBoostsItem, showRepliesItem, loadNewPostsItem, seeNewPostsBtnItem, overlayMediaItem;

// MOSHIDON
private CheckableListItem<Void> mentionRebloggerAutomaticallyItem, showPostsWithoutAltItem;
private CheckableListItem<Void> mentionRebloggerAutomaticallyItem, hapticFeedbackItem, showPostsWithoutAltItem;

@Override
public void onCreate(Bundle savedInstanceState){
Expand Down Expand Up @@ -75,6 +82,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;

Expand Down Expand Up @@ -211,6 +223,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ private void applyInteraction(View v, Consumer<Status> 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;
Expand Down

0 comments on commit fa0efe1

Please sign in to comment.