diff --git a/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectTouchListener.java b/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectTouchListener.java index cb3d3358e..46465c0e0 100644 --- a/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectTouchListener.java +++ b/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectTouchListener.java @@ -307,6 +307,8 @@ private void notifySelectRangeChange() { return; } + boolean isReverse = mStart > mEnd; + int newStart, newEnd; newStart = Math.min(mStart, mEnd); newEnd = Math.max(mStart, mEnd); @@ -315,21 +317,21 @@ private void notifySelectRangeChange() { } if (mLastStart == RecyclerView.NO_POSITION || mLastEnd == RecyclerView.NO_POSITION) { if (newEnd - newStart == 1) { - mSelectListener.onSelectChange(newStart, newStart, true); + mSelectListener.onSelectChange(newStart, newStart, true, isReverse); } else { - mSelectListener.onSelectChange(newStart, newEnd, true); + mSelectListener.onSelectChange(newStart, newEnd, true, isReverse); } } else { if (newStart > mLastStart) { - mSelectListener.onSelectChange(mLastStart, newStart - 1, false); + mSelectListener.onSelectChange(mLastStart, newStart - 1, false, isReverse); } else if (newStart < mLastStart) { - mSelectListener.onSelectChange(newStart, mLastStart - 1, true); + mSelectListener.onSelectChange(newStart, mLastStart - 1, true, isReverse); } if (newEnd > mLastEnd) { - mSelectListener.onSelectChange(mLastEnd + 1, newEnd, true); + mSelectListener.onSelectChange(mLastEnd + 1, newEnd, true, isReverse); } else if (newEnd < mLastEnd) { - mSelectListener.onSelectChange(newEnd + 1, mLastEnd, false); + mSelectListener.onSelectChange(newEnd + 1, mLastEnd, false, isReverse); } } @@ -389,7 +391,8 @@ public interface OnSlideSelectListener { * @param start the newly (un)selected range start * @param end the newly (un)selected range end * @param isSelected true, it range got selected, false if not + * @param isReverse true, it select from bottom to top, false if not */ - void onSelectChange(int start, int end, boolean isSelected); + void onSelectChange(int start, int end, boolean isSelected, boolean isReverse); } } diff --git a/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectionHandler.java b/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectionHandler.java index d0c29299b..dc6988a1b 100644 --- a/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectionHandler.java +++ b/selector/src/main/java/com/luck/picture/lib/widget/SlideSelectionHandler.java @@ -54,9 +54,16 @@ public void onSelectionFinished(int end) { } @Override - public void onSelectChange(int start, int end, boolean isSelected) { - for (int i = start; i <= end; i++) { - checkedChangeSelection(i, i, isSelected != mOriginalSelection.contains(i)); + public void onSelectChange(int start, int end, boolean isSelected, boolean isReverse) { + if (isReverse) { + for (int i = end; i >= start; i--) { + checkedChangeSelection(i, i, isSelected != mOriginalSelection.contains(i)); + } + } + else { + for (int i = start; i <= end; i++) { + checkedChangeSelection(i, i, isSelected != mOriginalSelection.contains(i)); + } } }