diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-10-28 16:28:26 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-10-28 16:28:26 +0000 |
commit | 27152bf1d5f2f329d7afd578073fc718215957c2 (patch) | |
tree | 117cf841915d19f248f4cdd61213d33e5b5e24c3 /app | |
parent | ec3a0930e9919ce8ccdb382a983d8430c1533c7b (diff) | |
download | infinity-for-reddit-27152bf1d5f2f329d7afd578073fc718215957c2.tar infinity-for-reddit-27152bf1d5f2f329d7afd578073fc718215957c2.tar.gz infinity-for-reddit-27152bf1d5f2f329d7afd578073fc718215957c2.tar.bz2 infinity-for-reddit-27152bf1d5f2f329d7afd578073fc718215957c2.tar.lz infinity-for-reddit-27152bf1d5f2f329d7afd578073fc718215957c2.tar.xz infinity-for-reddit-27152bf1d5f2f329d7afd578073fc718215957c2.tar.zst infinity-for-reddit-27152bf1d5f2f329d7afd578073fc718215957c2.zip |
Refine TableHorizontalScrollView MotionEvent processing.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/customviews/TableHorizontalScrollView.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/customviews/TableHorinzontalScrollView.java) | 46 | ||||
-rw-r--r-- | app/src/main/res/layout/adapter_table_block.xml | 4 |
2 files changed, 34 insertions, 16 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/TableHorinzontalScrollView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/TableHorizontalScrollView.java index 6d8615cf..e5687a4c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/TableHorinzontalScrollView.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/TableHorizontalScrollView.java @@ -8,34 +8,40 @@ import android.view.MotionEvent; import android.view.ViewParent; import android.widget.HorizontalScrollView; +import androidx.annotation.Nullable; import androidx.viewpager2.widget.ViewPager2; import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel; -public class TableHorinzontalScrollView extends HorizontalScrollView { +public class TableHorizontalScrollView extends HorizontalScrollView { + @Nullable private CustomToroContainer toroContainer; + @Nullable private ViewPager2 viewPager2; + @Nullable private SliderPanel sliderPanel; private float lastX = 0.0f; private float lastY = 0.0f; + private boolean allowScroll; + private boolean isViewPager2Enabled; - public TableHorinzontalScrollView(Context context) { + public TableHorizontalScrollView(Context context) { super(context); init(); } - public TableHorinzontalScrollView(Context context, AttributeSet attrs) { + public TableHorizontalScrollView(Context context, AttributeSet attrs) { super(context, attrs); init(); } - public TableHorinzontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) { + public TableHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } - public TableHorinzontalScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + public TableHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(); } @@ -48,6 +54,7 @@ public class TableHorinzontalScrollView extends HorizontalScrollView { toroContainer = (CustomToroContainer) parent; } else if (parent instanceof ViewPager2) { viewPager2 = (ViewPager2) parent; + isViewPager2Enabled = viewPager2.isUserInputEnabled(); } else if (parent instanceof SliderPanel) { sliderPanel = (SliderPanel) parent; } @@ -59,32 +66,45 @@ public class TableHorinzontalScrollView extends HorizontalScrollView { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - boolean allowScroll = true; + processMotionEvent(ev); + return allowScroll; + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + processMotionEvent(ev); + return super.onTouchEvent(ev); + } + private void processMotionEvent(MotionEvent ev) { switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: lastX = ev.getX(); lastY = ev.getY(); + allowScroll = true; if (toroContainer != null) { toroContainer.requestDisallowInterceptTouchEvent(true); } - if (viewPager2 != null) { + if (viewPager2 != null && isViewPager2Enabled) { viewPager2.setUserInputEnabled(false); } if (sliderPanel != null) { - sliderPanel.requestDisallowInterceptTouchEvent(true); + sliderPanel.lock(); } break; case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + allowScroll = false; + if (toroContainer != null) { toroContainer.requestDisallowInterceptTouchEvent(false); } - if (viewPager2 != null) { + if (viewPager2 != null && isViewPager2Enabled) { viewPager2.setUserInputEnabled(true); } if (sliderPanel != null) { - sliderPanel.requestDisallowInterceptTouchEvent(false); + sliderPanel.unlock(); } break; case MotionEvent.ACTION_MOVE: @@ -98,15 +118,13 @@ public class TableHorinzontalScrollView extends HorizontalScrollView { if (toroContainer != null) { toroContainer.requestDisallowInterceptTouchEvent(allowScroll); } - if (viewPager2 != null) { + if (viewPager2 != null && isViewPager2Enabled) { viewPager2.setUserInputEnabled(false); } if (sliderPanel != null) { - sliderPanel.requestDisallowInterceptTouchEvent(true); + sliderPanel.lock(); } break; } - - return allowScroll && super.onInterceptTouchEvent(ev); } } diff --git a/app/src/main/res/layout/adapter_table_block.xml b/app/src/main/res/layout/adapter_table_block.xml index 29ce9279..35f6178b 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 @@ <?xml version="1.0" encoding="utf-8"?> -<ml.docilealligator.infinityforreddit.customviews.TableHorinzontalScrollView +<ml.docilealligator.infinityforreddit.customviews.TableHorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" @@ -13,4 +13,4 @@ android:layout_height="wrap_content" android:stretchColumns="*" /> -</ml.docilealligator.infinityforreddit.customviews.TableHorinzontalScrollView> +</ml.docilealligator.infinityforreddit.customviews.TableHorizontalScrollView> |