Fixed ItemTouchHelper conflict with Slidr.

This commit is contained in:
Docile-Alligator 2023-04-29 00:09:43 +08:00
parent d65a355bdc
commit ee86148209
4 changed files with 86 additions and 21 deletions

View File

@ -2227,6 +2227,19 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
});
itemView.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
if (mFragment.isRecyclerViewItemSwipeable(PostBaseViewHolder.this)) {
mActivity.unlockSwipeRightToGoBack();
}
} else {
if (mFragment.isRecyclerViewItemSwipeable(PostBaseViewHolder.this)) {
mActivity.lockSwipeRightToGoBack();
}
}
return false;
});
userTextView.setOnClickListener(view -> {
if (canStartActivity) {
int position = getBindingAdapterPosition();
@ -3241,15 +3254,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
});
rootView.setOnTouchListener((view, motionEvent) -> {
swipeLocked = false;
return false;
});
bottomConstraintLayout.setOnTouchListener((view, motionEvent) -> {
swipeLocked = false;
return false;
});
noPreviewImageView.setOnClickListener(view -> {
int position = getBindingAdapterPosition();
if (position < 0) {
@ -3572,6 +3576,19 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
return true;
});
itemView.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
if (mFragment.isRecyclerViewItemSwipeable(PostCompactBaseViewHolder.this)) {
mActivity.unlockSwipeRightToGoBack();
}
} else {
if (mFragment.isRecyclerViewItemSwipeable(PostCompactBaseViewHolder.this)) {
mActivity.lockSwipeRightToGoBack();
}
}
return false;
});
nameTextView.setOnClickListener(view -> {
int position = getBindingAdapterPosition();
if (position < 0) {

View File

@ -11,6 +11,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -2332,6 +2333,19 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
});
itemView.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
if (mFragment.isRecyclerViewItemSwipeable(PostBaseViewHolder.this)) {
mActivity.unlockSwipeRightToGoBack();
}
} else {
if (mFragment.isRecyclerViewItemSwipeable(PostBaseViewHolder.this)) {
mActivity.lockSwipeRightToGoBack();
}
}
return false;
});
userTextView.setOnClickListener(view -> {
if (!canStartActivity) {
return;
@ -3379,15 +3393,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
});
rootView.setOnTouchListener((view, motionEvent) -> {
swipeLocked = false;
return false;
});
bottomConstraintLayout.setOnTouchListener((view, motionEvent) -> {
swipeLocked = false;
return false;
});
noPreviewImageView.setOnClickListener(view -> {
int position = getBindingAdapterPosition();
if (position < 0) {
@ -3714,6 +3719,19 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
return true;
});
itemView.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
if (mFragment.isRecyclerViewItemSwipeable(PostCompactBaseViewHolder.this)) {
mActivity.unlockSwipeRightToGoBack();
}
} else {
if (mFragment.isRecyclerViewItemSwipeable(PostCompactBaseViewHolder.this)) {
mActivity.lockSwipeRightToGoBack();
}
}
return false;
});
nameTextView.setOnClickListener(view -> {
int position = getBindingAdapterPosition();
if (position < 0) {

View File

@ -209,6 +209,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
private boolean isLazyModePaused = false;
private boolean hasPost = false;
private boolean rememberMutingOptionInPostFeed;
private boolean swipeActionEnabled;
private Boolean masterMutingOption;
private HistoryPostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller smoothScroller;
@ -563,6 +564,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
});
if (nColumns == 1 && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false)) {
swipeActionEnabled = true;
touchHelper.attachToRecyclerView(mPostRecyclerView);
}
mPostRecyclerView.setAdapter(mAdapter);
@ -1011,6 +1013,18 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
}
}
public boolean isRecyclerViewItemSwipeable(RecyclerView.ViewHolder viewHolder) {
if (swipeActionEnabled) {
if (viewHolder instanceof HistoryPostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) {
return !((HistoryPostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) viewHolder).isSwipeLocked();
}
return true;
}
return false;
}
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
ItemSnapshotList<Post> posts = mAdapter.snapshot();
@ -1199,7 +1213,8 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
@Subscribe
public void onChangeEnableSwipeActionSwitchEvent(ChangeEnableSwipeActionSwitchEvent changeEnableSwipeActionSwitchEvent) {
if (touchHelper != null) {
if (getNColumns(getResources()) == 1 && touchHelper != null) {
swipeActionEnabled = changeEnableSwipeActionSwitchEvent.enableSwipeAction;
if (changeEnableSwipeActionSwitchEvent.enableSwipeAction) {
touchHelper.attachToRecyclerView(mPostRecyclerView);
} else {

View File

@ -16,6 +16,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -233,6 +234,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private boolean hasPost = false;
private boolean savePostFeedScrolledPosition;
private boolean rememberMutingOptionInPostFeed;
private boolean swipeActionEnabled;
private Boolean masterMutingOption;
private PostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller smoothScroller;
@ -1064,7 +1066,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (((PostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) viewHolder).isSwipeLocked()) {
return makeMovementFlags(0, 0);
}
}
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
return makeMovementFlags(0, swipeFlags);
@ -1153,6 +1154,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
});
if (nColumns == 1 && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SWIPE_ACTION, false)) {
swipeActionEnabled = true;
touchHelper.attachToRecyclerView(mPostRecyclerView);
}
mPostRecyclerView.setAdapter(mAdapter);
@ -1978,7 +1980,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe
public void onChangeEnableSwipeActionSwitchEvent(ChangeEnableSwipeActionSwitchEvent changeEnableSwipeActionSwitchEvent) {
if (touchHelper != null) {
if (getNColumns(getResources()) == 1 && touchHelper != null) {
swipeActionEnabled = changeEnableSwipeActionSwitchEvent.enableSwipeAction;
if (changeEnableSwipeActionSwitchEvent.enableSwipeAction) {
touchHelper.attachToRecyclerView(mPostRecyclerView);
} else {
@ -2219,6 +2222,18 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
public boolean isRecyclerViewItemSwipeable(RecyclerView.ViewHolder viewHolder) {
if (swipeActionEnabled) {
if (viewHolder instanceof PostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) {
return !((PostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) viewHolder).isSwipeLocked();
}
return true;
}
return false;
}
private static abstract class LazyModeRunnable implements Runnable {
private int currentPosition = -1;