Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new call back to handle when the dragged view is dropped #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -58,6 +58,18 @@ public interface OnViewSwapListener {
* No guarantee is made as to which of the two has a lesser/greater position.
*/
void onSwap(View firstView, int firstPosition, View secondView, int secondPosition);

/**
* Invoked after the dragged item is released and dropped into its final position (i.e. the
* finger is lifted off the screen). This is different than {@link this.onSwap()} which gets
* notified everytime the dragged item passes another item in the layout durring drag.
*
* this is useful if you want to only take action when the drag is finished, and not during.
*
* @param originalPosition the original position where the dragged item was picked up
* @param finalPosition the final position where the dragged item is dropped
*/
void onDrop(int originalPosition, int finalPosition);
}

private OnViewSwapListener swapListener;
Expand Down Expand Up @@ -100,6 +112,8 @@ private class DragItem {
private int startVisibility;
private BitmapDrawable viewDrawable;
private int position;
private int originalPosition;
private int finalPosition;
private int startTop;
private int height;
private int totalDragOffset;
Expand All @@ -117,7 +131,8 @@ public void startDetectingOnPossibleDrag(final View view, final int position) {
this.view = view;
this.startVisibility = view.getVisibility();
this.viewDrawable = getDragDrawable(view);
this.position = position;
this.originalPosition = this.position = position;
this.finalPosition = -1;
this.startTop = view.getTop();
this.height = view.getHeight();
this.totalDragOffset = 0;
Expand Down Expand Up @@ -155,7 +170,7 @@ public void stopDetecting() {
view = null;
startVisibility = -1;
viewDrawable = null;
position = -1;
originalPosition = position = -1;
startTop = -1;
height = -1;
totalDragOffset = 0;
Expand Down Expand Up @@ -424,6 +439,7 @@ public void onAnimationEnd(Animator animation) {
}
});
draggedItem.settleAnimation.start();
swapListener.onDrop(draggedItem.originalPosition, draggedItem.position);
}

/**
Expand Down