From 334cf7e2da0ee3ad32b7688120656d3452b57cf2 Mon Sep 17 00:00:00 2001 From: leonel Mendez Date: Tue, 13 Dec 2016 23:58:49 -0600 Subject: [PATCH] FIX: Fixed error touch listener --- .../util/RecyclerViewHeaderClickListener.kt | 15 +++++++++++---- .../util/RecyclerViewItemClickListener.kt | 11 ++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewHeaderClickListener.kt b/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewHeaderClickListener.kt index 3fc94cc..1da3bbc 100644 --- a/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewHeaderClickListener.kt +++ b/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewHeaderClickListener.kt @@ -11,10 +11,17 @@ open class RecyclerViewHeaderClickListener(context: Context, var headerClick:OnH val child:View? = rv?.findChildViewUnder(e!!.x,e.y) if(gestureDetector.onTouchEvent(e)) { - if(rv?.getChildAdapterPosition(child) == 0) - headerClick.onHeaderClick() - else - recyclerViewItem.onItemClick(child, (rv?.getChildAdapterPosition(child)?.minus(1))) + if(rv?.getChildAdapterPosition(child)!! >= 0) { + if (rv?.getChildAdapterPosition(child) == 0) { + headerClick.onHeaderClick() + return true + } else { + recyclerViewItem.onItemClick(child, (rv?.getChildAdapterPosition(child)?.minus(1))) + return true + } + }else { + return false + } } return false } diff --git a/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewItemClickListener.kt b/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewItemClickListener.kt index 6a0f829..2754dfd 100644 --- a/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewItemClickListener.kt +++ b/easyrecycler/src/main/kotlin/mx/leo/easyrecycler/util/RecyclerViewItemClickListener.kt @@ -22,9 +22,14 @@ open class RecyclerViewItemClickListener(context: Context, var recyclerViewItem: } override fun onInterceptTouchEvent(rv: RecyclerView?, e: MotionEvent?): Boolean { - val child:View? = rv?.findChildViewUnder(e!!.x,e.y) - if(gestureDetector.onTouchEvent(e)) { - recyclerViewItem.onItemClick(child, rv?.getChildAdapterPosition(child)) + val child: View? = rv?.findChildViewUnder(e!!.x, e.y) + if (gestureDetector.onTouchEvent(e)) { + if (rv?.getChildAdapterPosition(child)!! >= 0) { + recyclerViewItem.onItemClick(child, rv?.getChildAdapterPosition(child)) + return true + } else { + return false + } } return false }