aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-04-28 16:09:43 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-04-28 16:09:43 +0000
commitee86148209a8ebeadd3cc891da1d4c2b000973bd (patch)
treef979b30af2c91d50378ef8a47859b26a14e5945d
parentd65a355bdce31a7c3659477ae786712f433b609c (diff)
downloadinfinity-for-reddit-ee86148209a8ebeadd3cc891da1d4c2b000973bd.tar
infinity-for-reddit-ee86148209a8ebeadd3cc891da1d4c2b000973bd.tar.gz
infinity-for-reddit-ee86148209a8ebeadd3cc891da1d4c2b000973bd.tar.bz2
infinity-for-reddit-ee86148209a8ebeadd3cc891da1d4c2b000973bd.tar.lz
infinity-for-reddit-ee86148209a8ebeadd3cc891da1d4c2b000973bd.tar.xz
infinity-for-reddit-ee86148209a8ebeadd3cc891da1d4c2b000973bd.tar.zst
infinity-for-reddit-ee86148209a8ebeadd3cc891da1d4c2b000973bd.zip
Fixed ItemTouchHelper conflict with Slidr.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java35
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java36
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java19
4 files changed, 86 insertions, 21 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
index 4b4a86a9..88e83e30 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
@@ -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) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
index ee94325f..f3612e1e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -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) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
index e85e2b2a..bdb0b004 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
@@ -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 {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index d41894a3..766eadf1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -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;