Description: I can call builder.setSelection(lMyDAteInMillis) and it works great to highlight that date on the calendar. But say I set that for 2 months from today, the calendar still shows the current day and month, not what I have set to be the default date
Expected behavior: I would have expected that the calendar opens up to the month that I have selected the default date in. Not the current month. The user will see the text of the default date, but no selection and in the wrong month.
Source code:
Date myFutureDate = new Date(2 months from now);
MaterialDatePicker.Builder<Long> builder = MaterialDatePicker.Builder.datePicker();
long lDateInMillis = myFutureDate.getTime()
builder.setSelection(lDateInMillis);
Android API version: API Minimum 23 for me.
Material Library version: 1.1.0
Device: Bluebird EF500 & Pixel 2 & Pixel 4
Have you tried setOpenAt when setting the date picker constraints? It should set the month which the dialog will show when opened.
val constraints = CalendarConstraints.Builder()
.setOpenAt(myFutureDate)
.build()
...
builder.setCalendarConstraints(constraints)
Thanks for the tip, that does work.
I guess my question would be what is a scenario where I have set a default date and do not want to display that date by default. I'm only really thinking about my scenario, but I would have expected these to go together.
I have min/max dates as well and it's kind of weird that I have 2 objects that I'm working with to achieve a default date selected and displayed.
@GRRedWings Can you add more details:
I guess my question would be what is a scenario where I have set a default date and do not want to display that date by default
How can the user know that there is a selection if it is not displayed?
I think this is the question I was trying to ask. It seems weird to me that I have set a default date, a date that is not displayed in the current month, and I have to go through the extra step of setCalendarConstraints if I want the calendar to open to that date. I would have expected the calendar to always open up to whatever month I have a default day selected in.
Ok it sounds like to set the setOpenAt(monthSelection) by default if the setOpenAtis not initialized.
Yeah, I think that would be acceptable and match more of what I was expecting.
I can submit a PR but it would be nice to know the opinion of someone in the google team.
There are 2 kinds of problem.
Currently there is a default:
if (openAt == null) {
long today = MaterialDatePicker.thisMonthInUtcMilliseconds();
openAt = start <= today && today <= end ? today : start;
}
Maybe using the selection is a better solution than today|start.
the CalendarConstraints is not aware of the selection. It means that after the initialization the MaterialDatePicker should update the CalendarConstraints.openAt value in respect of the type of DateSelector it is using.
This makes sense to me. If there is a selection, we can use that as the default openAt (should still support setting a totally different/custom openAt override). If there is no selection, then we can use the current default openAt logic.