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; + } +}