Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
fix NO_POSITION for viewholder
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhart committed Feb 6, 2018
1 parent b547b14 commit f102077
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion hoveringcallback/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f102077

Please sign in to comment.