Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ public class DragAndDropHandler implements TouchEventHandler {
@Nullable
private OnItemMovedListener mOnItemMovedListener;



/**
* The {@link OnItemMovingCanceledListener} that is notified of moved items.
*/
@Nullable
private OnItemMovingCanceledListener mOnItemMovingCanceledListener;

/**
* The raw x coordinate of the down event.
*/
Expand Down Expand Up @@ -250,6 +258,13 @@ public void setOnItemMovedListener(@Nullable final OnItemMovedListener onItemMov
mOnItemMovedListener = onItemMovedListener;
}


/**
* Sets the {@link com.nhaarman.listviewanimations.itemmanipulation.dragdrop.OnItemMovingCanceledListener} that is notified when user has dropped a dragging item in its original position.
*/
public void setOnItemMovingCanceledListener(@Nullable final OnItemMovingCanceledListener onItemMovingCanceledListener) {
mOnItemMovingCanceledListener = onItemMovingCanceledListener;
}
@Override
public boolean isInteracting() {
return mMobileItemId != INVALID_ID;
Expand Down Expand Up @@ -441,8 +456,13 @@ private void switchViews(final View switchView, final long switchId, final float
* Handles the up event.
* <p/>
* Animates the hover drawable to its final position, and finalizes our drag properties when the animation has finished.
*
* Will also notify the {@link com.nhaarman.listviewanimations.itemmanipulation.dragdrop.OnItemMovedListener} set if applicable.
*
* Will also notify the
* {@link com.nhaarman.listviewanimations.itemmanipulation.dragdrop.OnItemMovingCanceledListener}
* if user drop item in its original position.
*
* @return {@code true} if the event was handled, {@code false} otherwise.
*/
private boolean handleUpEvent() {
Expand All @@ -458,9 +478,17 @@ private boolean handleUpEvent() {
valueAnimator.start();

int newPosition = getPositionForId(mMobileItemId) - mWrapper.getHeaderViewsCount();
if (mOriginalMobileItemPosition != newPosition && mOnItemMovedListener != null) {
mOnItemMovedListener.onItemMoved(mOriginalMobileItemPosition, newPosition);
}
if (mOriginalMobileItemPosition != newPosition) {

if(mOnItemMovedListener != null) {
mOnItemMovedListener.onItemMoved(mOriginalMobileItemPosition, newPosition);
}
}else{
if(mOnItemMovingCanceledListener != null){
mOnItemMovingCanceledListener.onItemMovingCanceled(mOriginalMobileItemPosition);
}

}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public interface OnItemMovedListener {
* @param newPosition the new position of the item that was dragged.
*/
void onItemMoved(int originalPosition, int newPosition);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nhaarman.listviewanimations.itemmanipulation.dragdrop;

/**
* An interface which provides a callback that is called when an item's moving has been canceled
* using the {@link com.nhaarman.listviewanimations.itemmanipulation.DynamicListView}.
* It usually happens when user drags item but then drop it back to its original position
*/
public interface OnItemMovingCanceledListener {

/**
* Called when an item that was dragged has been dropped without moving to new position.
*
* @param originalPosition the original position of the item that was dragged.
*
*/
void onItemMovingCanceled(int originalPosition);
}