Applandeo / Material-Calendar-View

Material Calendar View for Android
Apache License 2.0
970 stars 317 forks source link

Fix one day picker crash when selecting a day if no days were previously selected #427

Closed mikewellback closed 2 years ago

mikewellback commented 2 years ago

The widget led to app crash when selecting a day in the one day picker mode if no days were previously selected.

To mimic this behaviour you can add this code on the sample app, OneDayPickerActivity, row 37:

`

    Calendar today = Calendar.getInstance();

    try {
        calendarView.setDate(today);
    } catch (OutOfDateRangeException e) {
        e.printStackTrace();
    }

    calendarView.setDisabledDays(Collections.singletonList(today));

`

Basically if a day is selected and then disabled, the selection is cleared and, by tapping on another day, the crash happens.

My solution is to check the size of the selected days array before trying to get the first element and also allow to select the tapped day even if there is no day to deselect.