From f1020770ac07eba1f81b2fe9d6d2f9311a9833f2 Mon Sep 17 00:00:00 2001 From: Bogdan Kornev Date: Tue, 6 Feb 2018 21:53:35 +0600 Subject: [PATCH] fix NO_POSITION for viewholder --- README.md | 2 +- hoveringcallback/build.gradle | 2 +- .../com/shuhart/hoveringcallback/HoveringCallback.java | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 88b36b2..9cdf3d5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Usage ----- 1. Add jcenter() to repositories block in your gradle file. -2. Add `implementation 'com.shuhart.hoveringcallback:hoveringcallback:1.2.2'` to your dependencies. +2. Add `implementation 'com.shuhart.hoveringcallback:hoveringcallback:1.2.3'` to your dependencies. 3. Look into the sample for additional details on how to use and configure the library. Example: diff --git a/hoveringcallback/build.gradle b/hoveringcallback/build.gradle index a1a4d27..fe222be 100644 --- a/hoveringcallback/build.gradle +++ b/hoveringcallback/build.gradle @@ -15,7 +15,7 @@ ext { siteUrl = 'https://github.com/shuhart/HoveringCallback' gitUrl = 'https://github.com/shuhart/HoveringCallback.git' - libraryVersion = '1.2.2' + libraryVersion = '1.2.3' developerId = 'shuhart' developerName = 'Redrick Shuhart' diff --git a/hoveringcallback/src/main/java/com/shuhart/hoveringcallback/HoveringCallback.java b/hoveringcallback/src/main/java/com/shuhart/hoveringcallback/HoveringCallback.java index 6563580..e2d3397 100644 --- a/hoveringcallback/src/main/java/com/shuhart/hoveringcallback/HoveringCallback.java +++ b/hoveringcallback/src/main/java/com/shuhart/hoveringcallback/HoveringCallback.java @@ -60,9 +60,7 @@ public void removeOnDropListener(OnDroppedListener listener) { public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { super.onSelectedChanged(viewHolder, actionState); if (viewHolder == null) { - if (current != null) { - findDroppedOn(); - } + findDroppedOn(); } this.current = viewHolder; if (actionState != ItemTouchHelper.ACTION_STATE_IDLE && viewHolder != null) { @@ -71,12 +69,12 @@ public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionStat } private void findDroppedOn() { - if (recyclerView == null) return; + if (recyclerView == null || current == null || current.getAdapterPosition() == RecyclerView.NO_POSITION) return; int childCount = recyclerView.getChildCount(); for (int i = 0; i < childCount; i++) { View view = recyclerView.getChildAt(i); RecyclerView.ViewHolder holder = recyclerView.findContainingViewHolder(view); - if (holder == null) continue; + if (holder == null || holder.getAdapterPosition() == RecyclerView.NO_POSITION) continue; if (view.getBackground() == backgroundCallback.getHoverBackground(holder)) { notifyDroppedOnListeners(holder); } @@ -137,7 +135,7 @@ public void onChildDraw(Canvas canvas, RecyclerView parent, RecyclerView.ViewHol RecyclerView.ViewHolder childViewHolder = parent.findContainingViewHolder(child); - if (childViewHolder == null) { + if (childViewHolder == null || childViewHolder.getAdapterPosition() == RecyclerView.NO_POSITION) { continue; }