feat: Add haptic feedback on boost/favourite/bookmark

This commit is contained in:
Schuyler Cebulskie
2023-06-16 20:34:13 -04:00
parent 1810821983
commit ede7305fe9
6 changed files with 38 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ public class GlobalUserPreferences{
public static boolean doubleTapToSwipe;
public static boolean compactReblogReplyLine;
public static boolean confirmBeforeReblog;
public static boolean hapticFeedback;
public static boolean replyLineAboveHeader;
public static boolean swapBookmarkWithBoostAction;
public static boolean loadRemoteAccountFollowers;
@@ -139,6 +140,7 @@ public class GlobalUserPreferences{
replyLineAboveHeader=prefs.getBoolean("replyLineAboveHeader", true);
compactReblogReplyLine=prefs.getBoolean("compactReblogReplyLine", true);
confirmBeforeReblog=prefs.getBoolean("confirmBeforeReblog", false);
hapticFeedback=prefs.getBoolean("hapticFeedback", true);
swapBookmarkWithBoostAction=prefs.getBoolean("swapBookmarkWithBoostAction", false);
loadRemoteAccountFollowers=prefs.getBoolean("loadRemoteAccountFollowers", true);
mentionRebloggerAutomatically=prefs.getBoolean("mentionRebloggerAutomatically", false);

View File

@@ -1,5 +1,6 @@
package org.joinmastodon.android.fragments.settings;
import android.os.Build;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.ViewGroup;
@@ -63,6 +64,10 @@ public class BehaviourFragment extends SettingsBaseFragment{
GlobalUserPreferences.save();
needAppRestart=true;
}));
items.add(new SwitchItem(R.string.mo_haptic_feedback, R.string.mo_setting_haptic_feedback, R.drawable.ic_fluent_phone_vibrate_24_filled, GlobalUserPreferences.hapticFeedback, i -> {
GlobalUserPreferences.hapticFeedback = i.checked;
GlobalUserPreferences.save();
}, Build.VERSION.SDK_INT >= Build.VERSION_CODES.R));
items.add(new SwitchItem(R.string.sk_settings_confirm_before_reblog, R.drawable.ic_fluent_checkmark_circle_24_regular, GlobalUserPreferences.confirmBeforeReblog, i->{
GlobalUserPreferences.confirmBeforeReblog=i.checked;
GlobalUserPreferences.save();

View File

@@ -264,6 +264,15 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
this.onChanged=onChanged;
}
public SwitchItem(@StringRes int title, @StringRes int summary, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged, boolean enabled){
this.title=getString(title);
this.summary=getString(summary);
this.icon=icon;
this.checked=checked;
this.onChanged=onChanged;
this.enabled=enabled;
}
public SwitchItem(@StringRes int title, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged, boolean enabled){
this.title=getString(title);
this.icon=icon;

View File

@@ -5,7 +5,9 @@ import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -244,6 +246,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
if(status == null)
return;
boost.setSelected(!status.reblogged);
vibrateForAction(boost, !status.reblogged);
AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setReblogged(status, !status.reblogged, null, r->boostConsumer(v, r));
}
);
@@ -361,6 +364,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
if(status == null)
return;
favorite.setSelected(!status.favourited);
vibrateForAction(favorite, !status.favourited);
AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setFavorited(status, !status.favourited, r->{
if (status.favourited) {
v.startAnimation(GlobalUserPreferences.reduceMotion ? opacityIn : animSet);
@@ -406,6 +410,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
if(status == null)
return;
bookmark.setSelected(!status.bookmarked);
vibrateForAction(bookmark, !status.bookmarked);
AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setBookmarked(status, !status.bookmarked, r->{
v.startAnimation(opacityIn);
});
@@ -459,5 +464,11 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
return R.string.button_share;
return 0;
}
private static void vibrateForAction(View view, boolean isPositive) {
if (!GlobalUserPreferences.hapticFeedback) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return;
view.performHapticFeedback(isPositive ? HapticFeedbackConstants.CONFIRM : HapticFeedbackConstants.REJECT);
}
}
}