From ce427d2a0b2adf7f91b316621f82db184a4e0da7 Mon Sep 17 00:00:00 2001 From: Grishka Date: Mon, 26 Feb 2024 19:09:29 +0300 Subject: [PATCH] AND-149 --- .../discover/DiscoverNewsFragment.java | 4 +++ .../HorizontalScrollingTouchListener.java | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/ui/utils/HorizontalScrollingTouchListener.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java index 7c0917f5..46462ebd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.discover; +import android.annotation.SuppressLint; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -18,6 +19,7 @@ import org.joinmastodon.android.ui.DividerItemDecoration; import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.drawables.BlurhashCrossfadeDrawable; import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper; +import org.joinmastodon.android.ui.utils.HorizontalScrollingTouchListener; import org.joinmastodon.android.ui.utils.UiUtils; import java.util.ArrayList; @@ -81,6 +83,7 @@ public class DiscoverNewsFragment extends BaseRecyclerFragment im .exec(accountID); } + @SuppressLint("ClickableViewAccessibility") @Override protected RecyclerView.Adapter getAdapter(){ cardsList=new UsableRecyclerView(getActivity()); @@ -98,6 +101,7 @@ public class DiscoverNewsFragment extends BaseRecyclerFragment im }); cardsList.setSelector(R.drawable.bg_rect_12dp_ripple); cardsList.setDrawSelectorOnTop(true); + cardsList.setOnTouchListener(new HorizontalScrollingTouchListener(getActivity())); mergeAdapter=new MergeRecyclerAdapter(); bannerHelper.maybeAddBanner(list, mergeAdapter); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/HorizontalScrollingTouchListener.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/HorizontalScrollingTouchListener.java new file mode 100644 index 00000000..57b9f930 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/HorizontalScrollingTouchListener.java @@ -0,0 +1,36 @@ +package org.joinmastodon.android.ui.utils; + +import android.content.Context; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewConfiguration; + +public class HorizontalScrollingTouchListener implements View.OnTouchListener{ + private float downX, touchslop; + private boolean didDisallow; + + public HorizontalScrollingTouchListener(Context context){ + touchslop=ViewConfiguration.get(context).getScaledTouchSlop(); + } + + @Override + public boolean onTouch(View v, MotionEvent ev){ + if(ev.getAction()==MotionEvent.ACTION_DOWN){ + if(v.canScrollHorizontally(-1) || v.canScrollHorizontally(1)){ + v.getParent().requestDisallowInterceptTouchEvent(true); + didDisallow=true; + }else{ + didDisallow=false; + } + downX=ev.getX(); + }else if(didDisallow && ev.getAction()==MotionEvent.ACTION_MOVE){ + if(Math.abs(downX-ev.getX())>=touchslop){ + if(!v.canScrollHorizontally((int) (downX-ev.getX()))){ + didDisallow=false; + v.getParent().requestDisallowInterceptTouchEvent(false); + } + } + } + return false; + } +}