diff --git a/core/src/main/java/org/lucasr/twowayview/ClickItemTouchListener.java b/core/src/main/java/org/lucasr/twowayview/ClickItemTouchListener.java index 5e57e50..72b9a65 100644 --- a/core/src/main/java/org/lucasr/twowayview/ClickItemTouchListener.java +++ b/core/src/main/java/org/lucasr/twowayview/ClickItemTouchListener.java @@ -6,14 +6,16 @@ import android.support.v4.view.MotionEventCompat; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.OnItemTouchListener; +import android.util.Log; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.view.View; abstract class ClickItemTouchListener implements OnItemTouchListener { - private static final String LOGTAG = "ClickItemTouchListener"; + private static final String TAG = "ClickItemTouchListener"; private final GestureDetectorCompat mGestureDetector; + private boolean disallowIntercept = false; ClickItemTouchListener(RecyclerView hostView) { mGestureDetector = new ItemClickGestureDetector(hostView.getContext(), @@ -38,7 +40,10 @@ public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent even return false; } - mGestureDetector.onTouchEvent(event); + if(!disallowIntercept){ + mGestureDetector.onTouchEvent(event); + return false; + } return false; } @@ -48,6 +53,11 @@ public void onTouchEvent(RecyclerView recyclerView, MotionEvent event) { // intercepting touch events in the host RecyclerView. } + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + this.disallowIntercept = disallowIntercept; + } + abstract boolean performItemClick(RecyclerView parent, View view, int position, long id); abstract boolean performItemLongClick(RecyclerView parent, View view, int position, long id); @@ -113,7 +123,8 @@ public boolean onSingleTapUp(MotionEvent event) { if (mTargetChild != null) { mTargetChild.setPressed(false); - final int position = mHostView.getChildPosition(mTargetChild); + final int position = mHostView.getChildAdapterPosition(mTargetChild); + //If custom RecycleView.Adapter doesn't override method getItemId , id will be NO_ID which means -1. final long id = mHostView.getAdapter().getItemId(position); handled = performItemClick(mHostView, mTargetChild, position, id); @@ -141,7 +152,8 @@ public void onLongPress(MotionEvent event) { return; } - final int position = mHostView.getChildPosition(mTargetChild); + final int position = mHostView.getChildAdapterPosition(mTargetChild); + //If custom RecycleView.Adapter doesn't override method getItemId , id will be NO_ID which means -1. final long id = mHostView.getAdapter().getItemId(position); final boolean handled = performItemLongClick(mHostView, mTargetChild, position, id); diff --git a/core/src/main/java/org/lucasr/twowayview/ItemClickSupport.java b/core/src/main/java/org/lucasr/twowayview/ItemClickSupport.java index 186f7e6..957cda8 100644 --- a/core/src/main/java/org/lucasr/twowayview/ItemClickSupport.java +++ b/core/src/main/java/org/lucasr/twowayview/ItemClickSupport.java @@ -1,11 +1,13 @@ package org.lucasr.twowayview; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.HapticFeedbackConstants; import android.view.SoundEffectConstants; import android.view.View; public class ItemClickSupport { + private static final String TAG = "ItemClickSupport"; /** * Interface definition for a callback to be invoked when an item in the * RecyclerView has been clicked. @@ -79,13 +81,17 @@ public void setOnItemLongClickListener(OnItemLongClickListener listener) { mItemLongClickListener = listener; } + public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { + mTouchListener.onRequestDisallowInterceptTouchEvent(disallowIntercept); + } + public static ItemClickSupport addTo(RecyclerView recyclerView) { ItemClickSupport itemClickSupport = from(recyclerView); if (itemClickSupport == null) { itemClickSupport = new ItemClickSupport(recyclerView); recyclerView.setTag(R.id.twowayview_item_click_support, itemClickSupport); } else { - // TODO: Log warning + Log.w(TAG,"RecyclerView already binds another ItemClickSupport instance!!!"); } return itemClickSupport; @@ -94,7 +100,7 @@ public static ItemClickSupport addTo(RecyclerView recyclerView) { public static void removeFrom(RecyclerView recyclerView) { final ItemClickSupport itemClickSupport = from(recyclerView); if (itemClickSupport == null) { - // TODO: Log warning + Log.w(TAG,"Not found any ItemClickSupport instance which is bound by recyclerView!!!"); return; } diff --git a/layouts/src/main/java/org/lucasr/twowayview/widget/DividerItemDecoration.java b/layouts/src/main/java/org/lucasr/twowayview/widget/DividerItemDecoration.java index 65079ad..58c3ce5 100644 --- a/layouts/src/main/java/org/lucasr/twowayview/widget/DividerItemDecoration.java +++ b/layouts/src/main/java/org/lucasr/twowayview/widget/DividerItemDecoration.java @@ -75,6 +75,12 @@ private static ItemSpacingOffsets createSpacing(Drawable verticalDivider, return spacing; } + + @Override + public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { + onDraw(c,parent); + } + @Override public void onDrawOver(Canvas c, RecyclerView parent) { final BaseLayoutManager lm = (BaseLayoutManager) parent.getLayoutManager(); @@ -117,6 +123,11 @@ public void onDrawOver(Canvas c, RecyclerView parent) { } } + @Override + public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + getItemOffsets(outRect, parent.getChildPosition(view), parent); + } + @Override public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { mItemSpacing.getItemOffsets(outRect, itemPosition, parent);