Skip to content

Commit

Permalink
Refine horizontal gestures on gallery posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Docile-Alligator committed Oct 28, 2024
1 parent bd37d81 commit 065af14
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2271,27 +2271,6 @@ class PostDetailGalleryViewHolder extends PostDetailBaseViewHolder {
mCardViewColor, mCommentColor, mScale);
binding.galleryRecyclerViewItemPostDetailGallery.setAdapter(adapter);
new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostDetailGallery);
binding.galleryRecyclerViewItemPostDetailGallery.setOnTouchListener((v, motionEvent) -> {
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(true);
}
mActivity.unlockSwipeRightToGoBack();
} else {
if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(false);
}
mActivity.lockSwipeRightToGoBack();
}

return false;
});
LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false);
binding.galleryRecyclerViewItemPostDetailGallery.setLayoutManager(layoutManager);
binding.galleryRecyclerViewItemPostDetailGallery.addOnScrollListener(new RecyclerView.OnScrollListener() {
Expand Down Expand Up @@ -2323,6 +2302,14 @@ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEv
downX = e.getRawX();
downY = e.getRawY();
downTime = System.currentTimeMillis();

if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(false);
}
mActivity.lockSwipeRightToGoBack();
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
Expand All @@ -2334,9 +2321,18 @@ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEv
longPressed = true;
}
}

if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(false);
}
mActivity.lockSwipeRightToGoBack();
break;
case MotionEvent.ACTION_UP:
if (!dragged) {
case MotionEvent.ACTION_CANCEL:
if (e.getActionMasked() == MotionEvent.ACTION_UP && !dragged) {
if (System.currentTimeMillis() - downTime < longClickThreshold) {
int position = getBindingAdapterPosition();
if (position >= 0) {
Expand All @@ -2351,6 +2347,16 @@ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEv
downY = 0;
dragged = false;
longPressed = false;

if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false);
}

if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(true);
}
mActivity.unlockSwipeRightToGoBack();
break;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -2029,19 +2030,6 @@ void setOnClickListeners(MaterialButton upvoteButton,
}
});

itemView.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
if (mFragment.isRecyclerViewItemSwipeable(this)) {
mActivity.unlockSwipeRightToGoBack();
}
} else {
if (mFragment.isRecyclerViewItemSwipeable(this)) {
mActivity.lockSwipeRightToGoBack();
}
}
return false;
});

upvoteButton.setOnClickListener(view -> {
int position = getBindingAdapterPosition();
if (position < 0) {
Expand Down Expand Up @@ -3366,30 +3354,6 @@ public abstract class PostBaseGalleryTypeViewHolder extends PostBaseViewHolder {
adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface,
mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale);
galleryRecyclerView.setAdapter(adapter);
galleryRecyclerView.setOnTouchListener((v, motionEvent) -> {
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false);
}

if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(true);
}
mActivity.unlockSwipeRightToGoBack();
swipeLocked = false;
} else {
if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(false);
}
mActivity.lockSwipeRightToGoBack();
swipeLocked = true;
}

return false;
});
new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView);
galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool);
LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false);
Expand Down Expand Up @@ -3434,7 +3398,7 @@ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEv
swipeLocked = true;
break;
case MotionEvent.ACTION_MOVE:
if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
if (Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
dragged = true;
}

Expand All @@ -3455,7 +3419,8 @@ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEv
swipeLocked = true;
break;
case MotionEvent.ACTION_UP:
if (!dragged) {
case MotionEvent.ACTION_CANCEL:
if (e.getActionMasked() == MotionEvent.ACTION_UP && !dragged) {
if (System.currentTimeMillis() - downTime < longClickThreshold) {
int position = getBindingAdapterPosition();
if (position >= 0) {
Expand Down Expand Up @@ -4089,27 +4054,6 @@ public PostGalleryBaseGalleryTypeViewHolder(@NonNull View itemView,

adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface,
mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale);
recyclerView.setOnTouchListener((v, motionEvent) -> {
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(true);
}
mActivity.unlockSwipeRightToGoBack();
} else {
if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(false);
}
mActivity.lockSwipeRightToGoBack();
}

return false;
});
recyclerView.setAdapter(adapter);
new PagerSnapHelper().attachToRecyclerView(recyclerView);
recyclerView.setRecycledViewPool(mGalleryRecycledViewPool);
Expand Down Expand Up @@ -4144,6 +4088,14 @@ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEv
downX = e.getRawX();
downY = e.getRawY();
downTime = System.currentTimeMillis();

if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(false);
}
mActivity.lockSwipeRightToGoBack();
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
Expand All @@ -4155,18 +4107,35 @@ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEv
longPressed = true;
}
}

if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true);
}
if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(false);
}
mActivity.lockSwipeRightToGoBack();
break;
case MotionEvent.ACTION_UP:
if (!dragged) {
case MotionEvent.ACTION_CANCEL:
if (e.getActionMasked() == MotionEvent.ACTION_UP && !dragged) {
if (System.currentTimeMillis() - downTime < longClickThreshold) {
onClick();
}
}
case MotionEvent.ACTION_CANCEL:
downX = 0;
downY = 0;
dragged = false;
longPressed = false;

if (mActivity.mSliderPanel != null) {
mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false);
}

if (mActivity.mViewPager2 != null) {
mActivity.mViewPager2.setUserInputEnabled(true);
}
mActivity.unlockSwipeRightToGoBack();
}
return false;
}
Expand Down

0 comments on commit 065af14

Please sign in to comment.