mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-15 04:37:12 +01:00
Fix ItemTouchHelper and gallery swipe gesture fighting each other.
This commit is contained in:
parent
b85ed3c867
commit
6f2eea90ae
@ -243,6 +243,11 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toggleViewPagerSwipeLock(boolean lock) {
|
||||||
|
binding.accountSavedThingViewPager2.setUserInputEnabled(!lock);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postLayoutSelected(int postLayout) {
|
public void postLayoutSelected(int postLayout) {
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
|
@ -400,4 +400,8 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo
|
|||||||
public void unlockSwipeRightToGoBack() {
|
public void unlockSwipeRightToGoBack() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleViewPagerSwipeLock(boolean lock) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,19 +37,16 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
private ArrayList<Post.Gallery> galleryImages;
|
private ArrayList<Post.Gallery> galleryImages;
|
||||||
private boolean blurImage;
|
private boolean blurImage;
|
||||||
private float ratio;
|
private float ratio;
|
||||||
private OnItemClickListener onItemClickListener;
|
|
||||||
|
|
||||||
public PostGalleryTypeImageRecyclerViewAdapter(RequestManager glide, Typeface typeface,
|
public PostGalleryTypeImageRecyclerViewAdapter(RequestManager glide, Typeface typeface,
|
||||||
SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy,
|
SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy,
|
||||||
int mColorAccent, int mPrimaryTextColor, float scale,
|
int mColorAccent, int mPrimaryTextColor, float scale) {
|
||||||
OnItemClickListener onItemClickListener) {
|
|
||||||
this.glide = glide;
|
this.glide = glide;
|
||||||
this.typeface = typeface;
|
this.typeface = typeface;
|
||||||
this.saveMemoryCenterInisdeDownsampleStrategy = saveMemoryCenterInisdeDownsampleStrategy;
|
this.saveMemoryCenterInisdeDownsampleStrategy = saveMemoryCenterInisdeDownsampleStrategy;
|
||||||
this.mColorAccent = mColorAccent;
|
this.mColorAccent = mColorAccent;
|
||||||
this.mPrimaryTextColor = mPrimaryTextColor;
|
this.mPrimaryTextColor = mPrimaryTextColor;
|
||||||
this.mScale = scale;
|
this.mScale = scale;
|
||||||
this.onItemClickListener = onItemClickListener;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -137,10 +134,6 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
binding.progressBarItemGalleryImageInPostFeed.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent));
|
binding.progressBarItemGalleryImageInPostFeed.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent));
|
||||||
binding.errorTextViewItemGalleryImageInPostFeed.setTextColor(mPrimaryTextColor);
|
binding.errorTextViewItemGalleryImageInPostFeed.setTextColor(mPrimaryTextColor);
|
||||||
|
|
||||||
binding.imageViewItemGalleryImageInPostFeed.setOnClickListener(view -> {
|
|
||||||
onItemClickListener.onClick(getBindingAdapterPosition());
|
|
||||||
});
|
|
||||||
|
|
||||||
binding.errorTextViewItemGalleryImageInPostFeed.setOnClickListener(view -> {
|
binding.errorTextViewItemGalleryImageInPostFeed.setOnClickListener(view -> {
|
||||||
binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE);
|
binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE);
|
||||||
binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE);
|
binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE);
|
||||||
@ -148,8 +141,4 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnItemClickListener {
|
|
||||||
void onClick(int galleryItemIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,11 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
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.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@ -32,7 +35,6 @@ import androidx.core.content.ContextCompat;
|
|||||||
import androidx.paging.PagingDataAdapter;
|
import androidx.paging.PagingDataAdapter;
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.LinearSnapHelper;
|
|
||||||
import androidx.recyclerview.widget.PagerSnapHelper;
|
import androidx.recyclerview.widget.PagerSnapHelper;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
@ -3138,17 +3140,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
binding.imageIndexTextViewItemPostGalleryType.setBorderColor(mMediaIndicatorBackgroundColor);
|
binding.imageIndexTextViewItemPostGalleryType.setBorderColor(mMediaIndicatorBackgroundColor);
|
||||||
|
|
||||||
adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface,
|
adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface,
|
||||||
mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale,
|
mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale);
|
||||||
galleryItemIndex -> {
|
|
||||||
int position = getBindingAdapterPosition();
|
|
||||||
if (position < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (post != null) {
|
|
||||||
markPostRead(post, true);
|
|
||||||
openMedia(post, galleryItemIndex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
binding.galleryRecyclerViewItemPostGalleryType.setAdapter(adapter);
|
binding.galleryRecyclerViewItemPostGalleryType.setAdapter(adapter);
|
||||||
new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostGalleryType);
|
new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostGalleryType);
|
||||||
binding.galleryRecyclerViewItemPostGalleryType.setRecycledViewPool(mGalleryRecycledViewPool);
|
binding.galleryRecyclerViewItemPostGalleryType.setRecycledViewPool(mGalleryRecycledViewPool);
|
||||||
@ -3169,6 +3161,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
@Override
|
@Override
|
||||||
public void setSwipeLocked(boolean swipeLocked) {
|
public void setSwipeLocked(boolean swipeLocked) {
|
||||||
PostGalleryTypeViewHolder.this.swipeLocked = swipeLocked;
|
PostGalleryTypeViewHolder.this.swipeLocked = swipeLocked;
|
||||||
|
mActivity.toggleViewPagerSwipeLock(swipeLocked);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
binding.galleryRecyclerViewItemPostGalleryType.setLayoutManager(layoutManager);
|
binding.galleryRecyclerViewItemPostGalleryType.setLayoutManager(layoutManager);
|
||||||
@ -3184,6 +3177,55 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
binding.imageIndexTextViewItemPostGalleryType.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size()));
|
binding.imageIndexTextViewItemPostGalleryType.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
binding.galleryRecyclerViewItemPostGalleryType.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
|
||||||
|
private float downX;
|
||||||
|
private float downY;
|
||||||
|
private boolean dragged;
|
||||||
|
private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
|
||||||
|
int action = e.getAction();
|
||||||
|
switch (action) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
downX = e.getRawX();
|
||||||
|
downY = e.getRawY();
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
|
||||||
|
dragged = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
if (!dragged) {
|
||||||
|
int index = layoutManager.findFirstVisibleItemPosition();
|
||||||
|
int position = getBindingAdapterPosition();
|
||||||
|
if (position >= 0) {
|
||||||
|
if (post != null) {
|
||||||
|
markPostRead(post, true);
|
||||||
|
openMedia(post, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
downX = 0;
|
||||||
|
downY = 0;
|
||||||
|
dragged = false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
binding.getRoot().setOnTouchListener((view, motionEvent) -> {
|
binding.getRoot().setOnTouchListener((view, motionEvent) -> {
|
||||||
swipeLocked = false;
|
swipeLocked = false;
|
||||||
|
@ -38,7 +38,7 @@ public class SwipeLockFrameLayout extends FrameLayout implements SwipeLockView {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
updateSwipeLock(ev);
|
updateSwipeLock(ev);
|
||||||
return false;
|
return locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility") // we are just listening to touch events
|
@SuppressLint("ClickableViewAccessibility") // we are just listening to touch events
|
||||||
|
@ -16,6 +16,7 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.HapticFeedbackConstants;
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
Loading…
Reference in New Issue
Block a user