Skip to content

Commit

Permalink
Fix - Range Mode Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin41500 committed Jul 6, 2018
1 parent 95461fe commit 903f855
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.support.v4.view.ViewPager;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.Gravity;
Expand Down Expand Up @@ -1475,19 +1476,29 @@ protected void onDateClicked(@NonNull CalendarDay date, boolean nowSelected) {
}
break;
case SELECTION_MODE_RANGE: {
adapter.setDateSelected(date, nowSelected);
if (adapter.getSelectedDates().size() > 2) {
adapter.clearSelections();
adapter.setDateSelected(date, nowSelected); // re-set because adapter has been cleared
final List<CalendarDay> currentSelection = adapter.getSelectedDates();

if (currentSelection.size() == 0) {
// Selecting the first date of a range
adapter.setDateSelected(date, nowSelected);
dispatchOnDateSelected(date, nowSelected);
} else if (adapter.getSelectedDates().size() == 2) {
final List<CalendarDay> dates = adapter.getSelectedDates();
if (dates.get(0).isAfter(dates.get(1))) {
dispatchOnRangeSelected(dates.get(1), dates.get(0));
} else if (currentSelection.size() == 1) {
// Selecting the second date of a range
final CalendarDay firstDaySelected = currentSelection.get(0);
adapter.setDateSelected(date, nowSelected);
if (firstDaySelected.equals(date)) {
// Right now, we are not supporting a range of one day, so we are removing the day instead.
dispatchOnDateSelected(date, nowSelected);
} else if (firstDaySelected.isAfter(date)) {
// Selecting a range, dispatching...
dispatchOnRangeSelected(date, firstDaySelected);
} else {
dispatchOnRangeSelected(dates.get(0), dates.get(1));
// Selecting a range, dispatching in reverse order...
dispatchOnRangeSelected(firstDaySelected, date);
}
} else {
// Clearing selection and making a selection of the new date.
adapter.clearSelections();
adapter.setDateSelected(date, nowSelected);
dispatchOnDateSelected(date, nowSelected);
}
Expand Down

0 comments on commit 903f855

Please sign in to comment.