aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2022-11-13 05:50:25 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2022-11-13 05:50:25 +0000
commit6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b (patch)
tree6c99af30fc9c3375e5fc2cffb258da1d13c5c9ce /app/src/main
parentb85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5 (diff)
downloadinfinity-for-reddit-6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b.tar
infinity-for-reddit-6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b.tar.gz
infinity-for-reddit-6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b.tar.bz2
infinity-for-reddit-6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b.tar.lz
infinity-for-reddit-6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b.tar.xz
infinity-for-reddit-6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b.tar.zst
infinity-for-reddit-6f2eea90ae8ad00d57e6a04f0f98c1dbd5c01b9b.zip
Fix ItemTouchHelper and gallery swipe gesture fighting each other.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java66
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java1
6 files changed, 66 insertions, 25 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java
index 90364417..b9ffb7fe 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java
@@ -244,6 +244,11 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
@Override
+ public void toggleViewPagerSwipeLock(boolean lock) {
+ binding.accountSavedThingViewPager2.setUserInputEnabled(!lock);
+ }
+
+ @Override
public void postLayoutSelected(int postLayout) {
if (sectionsPagerAdapter != null) {
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + mAccountName, postLayout).apply();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java
index 02c20b77..de0b8947 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java
@@ -400,4 +400,8 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo
public void unlockSwipeRightToGoBack() {
}
+
+ public void toggleViewPagerSwipeLock(boolean lock) {
+
+ }
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java
index cbf34984..c9d61bf8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java
@@ -37,19 +37,16 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
private ArrayList<Post.Gallery> galleryImages;
private boolean blurImage;
private float ratio;
- private OnItemClickListener onItemClickListener;
public PostGalleryTypeImageRecyclerViewAdapter(RequestManager glide, Typeface typeface,
SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy,
- int mColorAccent, int mPrimaryTextColor, float scale,
- OnItemClickListener onItemClickListener) {
+ int mColorAccent, int mPrimaryTextColor, float scale) {
this.glide = glide;
this.typeface = typeface;
this.saveMemoryCenterInisdeDownsampleStrategy = saveMemoryCenterInisdeDownsampleStrategy;
this.mColorAccent = mColorAccent;
this.mPrimaryTextColor = mPrimaryTextColor;
this.mScale = scale;
- this.onItemClickListener = onItemClickListener;
}
@NonNull
@@ -137,10 +134,6 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
binding.progressBarItemGalleryImageInPostFeed.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent));
binding.errorTextViewItemGalleryImageInPostFeed.setTextColor(mPrimaryTextColor);
- binding.imageViewItemGalleryImageInPostFeed.setOnClickListener(view -> {
- onItemClickListener.onClick(getBindingAdapterPosition());
- });
-
binding.errorTextViewItemGalleryImageInPostFeed.setOnClickListener(view -> {
binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE);
binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE);
@@ -148,8 +141,4 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
});
}
}
-
- public interface OnItemClickListener {
- void onClick(int galleryItemIndex);
- }
}
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 81c4c441..6c52426b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -11,8 +11,11 @@ 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;
+import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -32,7 +35,6 @@ import androidx.core.content.ContextCompat;
import androidx.paging.PagingDataAdapter;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
-import androidx.recyclerview.widget.LinearSnapHelper;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
@@ -3138,17 +3140,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
binding.imageIndexTextViewItemPostGalleryType.setBorderColor(mMediaIndicatorBackgroundColor);
adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface,
- mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale,
- galleryItemIndex -> {
- int position = getBindingAdapterPosition();
- if (position < 0) {
- return;
- }
- if (post != null) {
- markPostRead(post, true);
- openMedia(post, galleryItemIndex);
- }
- });
+ mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale);
binding.galleryRecyclerViewItemPostGalleryType.setAdapter(adapter);
new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostGalleryType);
binding.galleryRecyclerViewItemPostGalleryType.setRecycledViewPool(mGalleryRecycledViewPool);
@@ -3169,6 +3161,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
@Override
public void setSwipeLocked(boolean swipeLocked) {
PostGalleryTypeViewHolder.this.swipeLocked = swipeLocked;
+ mActivity.toggleViewPagerSwipeLock(swipeLocked);
}
});
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.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) -> {
swipeLocked = false;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java
index 72d3e9b7..5b62bbfb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java
@@ -38,7 +38,7 @@ public class SwipeLockFrameLayout extends FrameLayout implements SwipeLockView {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
updateSwipeLock(ev);
- return false;
+ return locked;
}
@SuppressLint("ClickableViewAccessibility") // we are just listening to touch events
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 32c98b04..e0423ed0 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;