aminography / PrimeDatePicker

PrimeDatePicker is a tool that provides picking a single day, multiple days, and a range of days.
Apache License 2.0
470 stars 51 forks source link

Switch do endDay after chosen startDay in PrimeMonthView or PrimeCalendarView #55

Open dpelluzi opened 3 years ago

dpelluzi commented 3 years ago

When I use PrimeMonthView or PrimeCalendarView as standalone component I only can get the startDay on touching it. I set pickType attribute to PickType.RANGE_START and the callback onDayPickedListener returns only the startDay, i.e, selecting other days only changes the startDay. If I set pickType to PickType.RANGE_ENDnothing happens.

Is it possible to switch to endDay after chosen the startDay?

aminography commented 2 years ago

If you change the pickType to PickType.RANGE_END it should change the picking type as everything in this library works based on that. In order to switch to PickType.RANGE_END automatically, you just need to have something like this:

override fun onDayPicked(
        pickType: PickType,
        singleDay: PrimeCalendar?,
        startDay: PrimeCalendar?,
        endDay: PrimeCalendar?,
        multipleDays: List<PrimeCalendar>
    ) {
        when (pickType) {
            PickType.RANGE_START -> {
                if (endDay == null) {
                    calendarView.pickType = PickType.RANGE_END
                }
            }
            // ...
        }
    }

It has been implemented in PrimeDatePickerImpl to handle auto-switching for the dialog/bottomsheet date pickers.