From bd37d81bfc85cf429c5781bfc7f003027c2c4644 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:09:55 -0400 Subject: Refine markdown table scrolling. Refine horizontal gestures. --- .../activities/ViewPostDetailActivity.java | 14 +++ .../adapters/CommentsRecyclerViewAdapter.java | 4 +- .../adapters/PostDetailRecyclerViewAdapter.java | 38 ++++--- .../PostGalleryTypeImageRecyclerViewAdapter.java | 18 +--- .../adapters/PostRecyclerViewAdapter.java | 72 ++++++++++--- .../customviews/TableHorinzontalScrollView.java | 112 +++++++++++++++++++++ .../fragments/PostFragmentBase.java | 10 +- .../markdown/CustomMarkwonAdapter.java | 34 ------- app/src/main/res/layout/adapter_table_block.xml | 4 +- 9 files changed, 218 insertions(+), 88 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/TableHorinzontalScrollView.java (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index d89f0bd1..117f96e2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -868,6 +868,20 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } + @Override + public void lockSwipeRightToGoBack() { + if (mSliderPanel != null) { + mSliderPanel.lock(); + } + } + + @Override + public void unlockSwipeRightToGoBack() { + if (mSliderPanel != null) { + mSliderPanel.unlock(); + } + } + private class SectionsPagerAdapter extends FragmentStateAdapter { public SectionsPagerAdapter(@NonNull FragmentActivity fragmentActivity) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 42dd48ee..0021c8e3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -1379,12 +1379,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter {}); + mCardViewColor, mCommentColor, mScale); binding.galleryRecyclerViewItemPostDetailGallery.setAdapter(adapter); new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostDetailGallery); binding.galleryRecyclerViewItemPostDetailGallery.setOnTouchListener((v, motionEvent) -> { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); } @@ -2311,7 +2310,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + if (Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { dragged = true; } + if (!dragged && !longPressed) { + if (System.currentTimeMillis() - downTime >= longClickThreshold) { + itemView.performLongClick(); + longPressed = true; + } + } break; case MotionEvent.ACTION_UP: if (!dragged) { - int position = getBindingAdapterPosition(); - if (position >= 0) { - if (mPost != null) { - openMedia(mPost, layoutManager.findFirstVisibleItemPosition()); + if (System.currentTimeMillis() - downTime < longClickThreshold) { + int position = getBindingAdapterPosition(); + if (position >= 0) { + if (mPost != null) { + openMedia(mPost, layoutManager.findFirstVisibleItemPosition()); + } } } } @@ -2339,6 +2350,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { - itemClickListener.OnItemLongClick(galleryImages.get(getBindingAdapterPosition())); - return true; - }); - if (typeface != null) { binding.errorTextViewItemGalleryImageInPostFeed.setTypeface(typeface); } @@ -226,8 +216,4 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte }); } } - - public interface ItemClickListener { - void OnItemLongClick(Post.Gallery galleryImage); - } } 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 72022ea9..c230751a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -108,8 +108,6 @@ import ml.docilealligator.infinityforreddit.databinding.ItemPostVideoTypeAutopla import ml.docilealligator.infinityforreddit.databinding.ItemPostVideoTypeAutoplayLegacyControllerBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostWithPreviewBinding; import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment; -import ml.docilealligator.infinityforreddit.fragments.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragmentBase; import ml.docilealligator.infinityforreddit.post.FetchStreamableVideo; import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; @@ -3366,11 +3364,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter itemView.performLongClick()); + mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale); galleryRecyclerView.setAdapter(adapter); galleryRecyclerView.setOnTouchListener((v, motionEvent) -> { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); } @@ -3413,7 +3410,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { dragged = true; } + + if (!dragged && !longPressed) { + if (System.currentTimeMillis() - downTime >= longClickThreshold) { + itemView.performLongClick(); + longPressed = true; + } + } + + if (mActivity.mSliderPanel != null) { + mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); + } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } + mActivity.lockSwipeRightToGoBack(); + swipeLocked = true; break; case MotionEvent.ACTION_UP: if (!dragged) { - int position = getBindingAdapterPosition(); - if (position >= 0) { - if (post != null) { - markPostRead(post, true); - openMedia(post, layoutManager.findFirstVisibleItemPosition()); + if (System.currentTimeMillis() - downTime < longClickThreshold) { + int position = getBindingAdapterPosition(); + if (position >= 0) { + if (post != null) { + markPostRead(post, true); + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } } } } @@ -3442,6 +3470,17 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter {}); + mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale); recyclerView.setOnTouchListener((v, motionEvent) -> { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { if (mActivity.mSliderPanel != null) { mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); } @@ -4096,6 +4134,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + if (Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { dragged = true; } - if (!dragged) { + if (!dragged && !longPressed) { if (System.currentTimeMillis() - downTime >= longClickThreshold) { onLongClick(); + longPressed = true; } } break; @@ -4126,7 +4166,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { + ViewParent parent = getParent(); + while (parent != null) { + if (parent instanceof CustomToroContainer) { + toroContainer = (CustomToroContainer) parent; + } else if (parent instanceof ViewPager2) { + viewPager2 = (ViewPager2) parent; + } else if (parent instanceof SliderPanel) { + sliderPanel = (SliderPanel) parent; + } + + parent = parent.getParent(); + } + }); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + boolean allowScroll = true; + + switch (ev.getActionMasked()) { + case MotionEvent.ACTION_DOWN: + lastX = ev.getX(); + lastY = ev.getY(); + + if (toroContainer != null) { + toroContainer.requestDisallowInterceptTouchEvent(true); + } + if (viewPager2 != null) { + viewPager2.setUserInputEnabled(false); + } + if (sliderPanel != null) { + sliderPanel.requestDisallowInterceptTouchEvent(true); + } + break; + case MotionEvent.ACTION_UP: + if (toroContainer != null) { + toroContainer.requestDisallowInterceptTouchEvent(false); + } + if (viewPager2 != null) { + viewPager2.setUserInputEnabled(true); + } + if (sliderPanel != null) { + sliderPanel.requestDisallowInterceptTouchEvent(false); + } + break; + case MotionEvent.ACTION_MOVE: + float currentX = ev.getX(); + float currentY = ev.getY(); + float dx = Math.abs(currentX - lastX); + float dy = Math.abs(currentY - lastY); + + allowScroll = dy < dx; + + if (toroContainer != null) { + toroContainer.requestDisallowInterceptTouchEvent(allowScroll); + } + if (viewPager2 != null) { + viewPager2.setUserInputEnabled(false); + } + if (sliderPanel != null) { + sliderPanel.requestDisallowInterceptTouchEvent(true); + } + break; + } + + return allowScroll && super.onInterceptTouchEvent(ev); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java index c2e0a470..10d10558 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragmentBase.java @@ -256,8 +256,8 @@ public abstract class PostFragmentBase extends Fragment { if (!exceedThreshold && isCurrentlyActive) { exceedThreshold = true; if (vibrateWhenActionTriggered) { - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + itemView.setHapticFeedbackEnabled(true); + itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); } } backgroundSwipeRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); @@ -274,12 +274,12 @@ public abstract class PostFragmentBase extends Fragment { drawableSwipeRight.draw(c); } else if (dX < 0) { if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) { - dX = -(viewHolder.itemView.getRight() - viewHolder.itemView.getLeft()) * swipeActionThreshold; + dX = -(itemView.getRight() - itemView.getLeft()) * swipeActionThreshold; if (!exceedThreshold && isCurrentlyActive) { exceedThreshold = true; if (vibrateWhenActionTriggered) { - viewHolder.itemView.setHapticFeedbackEnabled(true); - viewHolder.itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + itemView.setHapticFeedbackEnabled(true); + itemView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); } } backgroundSwipeLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java index dbe4b23f..a64b00ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java @@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.markdown; import android.util.SparseArray; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.HorizontalScrollView; @@ -142,39 +141,6 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { return false; }); } else if (holder.itemView instanceof HorizontalScrollView) { - holder.itemView.setOnTouchListener(new View.OnTouchListener() { - boolean isSliderPanelLockedAlready; - boolean isViewPager2UserInputEnabledAlready; - @Override - public boolean onTouch(View v, MotionEvent motionEvent) { - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { - if (activity.mSliderPanel != null) { - activity.mSliderPanel.requestDisallowInterceptTouchEvent(false); - } - - if (activity.mViewPager2 != null && isViewPager2UserInputEnabledAlready) { - activity.mViewPager2.setUserInputEnabled(true); - } - - if (!isSliderPanelLockedAlready) { - activity.unlockSwipeRightToGoBack(); - } - } else { - if (activity.mSliderPanel != null) { - isSliderPanelLockedAlready = activity.mSliderPanel.isLocked(); - activity.mSliderPanel.requestDisallowInterceptTouchEvent(true); - } - if (activity.mViewPager2 != null) { - isViewPager2UserInputEnabledAlready = activity.mViewPager2.isUserInputEnabled(); - activity.mViewPager2.setUserInputEnabled(false); - } - activity.lockSwipeRightToGoBack(); - } - - return false; - } - }); - TableLayout tableLayout = holder.itemView.findViewById(R.id.table_layout); if (tableLayout != null) { for (int i = 0; i < tableLayout.getChildCount(); i++) { diff --git a/app/src/main/res/layout/adapter_table_block.xml b/app/src/main/res/layout/adapter_table_block.xml index e924f89e..29ce9279 100644 --- a/app/src/main/res/layout/adapter_table_block.xml +++ b/app/src/main/res/layout/adapter_table_block.xml @@ -1,5 +1,5 @@ - - + -- cgit v1.2.3