fix broken long click

This commit is contained in:
sk 2022-12-19 16:32:45 +01:00 committed by LucasGGamerM
parent 09a0faacba
commit 6c6fb05a7a
1 changed files with 24 additions and 17 deletions

View File

@ -6,12 +6,11 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -51,6 +50,9 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
private final ImageView share; private final ImageView share;
private static final Animation opacityOut, opacityIn; private static final Animation opacityOut, opacityIn;
private View touchingView = null;
private final Runnable longClickRunnable = () -> { if (touchingView != null) touchingView.performLongClick(); };
private final View.AccessibilityDelegate buttonAccessibilityDelegate=new View.AccessibilityDelegate(){ private final View.AccessibilityDelegate buttonAccessibilityDelegate=new View.AccessibilityDelegate(){
@Override @Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info){ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info){
@ -128,6 +130,26 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
} }
} }
private boolean onButtonTouch(View v, MotionEvent event){
int action = event.getAction();
// 20dp to center in middle of icon, because: (icon width = 24dp) / 2 + (paddingStart = 8dp)
v.setPivotX(V.dp(20));
long eventDuration = event.getEventTime() - event.getDownTime();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
touchingView = null;
v.removeCallbacks(longClickRunnable);
v.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
if (action == MotionEvent.ACTION_UP && eventDuration < ViewConfiguration.getLongPressTimeout()) v.performClick();
else v.startAnimation(opacityIn);
} else if (action == MotionEvent.ACTION_DOWN) {
touchingView = v;
v.postDelayed(longClickRunnable, ViewConfiguration.getLongPressTimeout());
v.startAnimation(opacityOut);
v.animate().scaleX(0.85f).scaleY(0.85f).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(75).start();
}
return true;
}
private void onReplyClick(View v){ private void onReplyClick(View v){
v.startAnimation(opacityIn); v.startAnimation(opacityIn);
Bundle args=new Bundle(); Bundle args=new Bundle();
@ -136,21 +158,6 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
Nav.go(item.parentFragment.getActivity(), ComposeFragment.class, args); Nav.go(item.parentFragment.getActivity(), ComposeFragment.class, args);
} }
private boolean onButtonTouch(View v, MotionEvent event){
int action = event.getAction();
// 20dp to center in middle of icon, because: (icon width = 24dp) / 2 + (paddingStart = 8dp)
v.setPivotX(V.dp(20));
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
v.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
if (action == MotionEvent.ACTION_UP) v.performClick();
else v.startAnimation(opacityIn);
} else if (action == MotionEvent.ACTION_DOWN) {
v.startAnimation(opacityOut);
v.animate().scaleX(0.85f).scaleY(0.85f).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(75).start();
}
return true;
}
private void onBoostClick(View v){ private void onBoostClick(View v){
boost.setSelected(!item.status.reblogged); boost.setSelected(!item.status.reblogged);
AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setReblogged(item.status, !item.status.reblogged, r->{ AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setReblogged(item.status, !item.status.reblogged, r->{