You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem: Things like setCalendarMode, setMinDate, setMaxDate, and setFirstDayOfWeek are side effecting, namely they rebuild adapters and recreate views on every call. This is very wasteful especially if you need to set all of them at once, and usually you only need to set them once. A lot of things are GC'd with each call. Worst of all, the order that each of them are called matters and it may not be clear to the user why the order should matter.
We need to separate setters that simply decorate/resize the view (like tileHeight/Width, decorators, select current date) to ones that actually modify adapter state and current page (min/max date, first day of the week).
Propose an immutable MaterialCalendarView.State object which is accessed through mcv.state(). Call edit() which creates a new builder from existing state to modify side effecting parameters all at once, then call commit() to trigger rebuild of all adapters and child views.
Something like this would be the ideal API:
// MCV inflated with default state or state defined in XMLMaterialCalendarViewmcv = (MaterialCalendarView) findViewById(R.id.calendar);
mcv.setSelectedDate(CalendarDay.today()); // non side effecting, this is fine. selected days are stored as a list// Modify existing statemcv.state().edit()
.setCalendarMode(CalendarMode.WEEK)
.setMinDate(CalendarDay.from(2016, 4, 4))
.setMaxDate(CalendarDay.from(2016, 6, 24))
.setFirstDayOfWeek(Calendar.TUESDAY)
.commit(); // triggers rebuild of all adapters and childviews// Make a new state (with defaults)mcv.newState().setCalendarMode(CalendarMode.WEEK).commit();
commit() should be the ONLY method that requires creating an adapter and telling all children to rebuild state based on the new state.
The text was updated successfully, but these errors were encountered:
Problem: Things like
setCalendarMode
,setMinDate
,setMaxDate
, andsetFirstDayOfWeek
are side effecting, namely they rebuild adapters and recreate views on every call. This is very wasteful especially if you need to set all of them at once, and usually you only need to set them once. A lot of things are GC'd with each call. Worst of all, the order that each of them are called matters and it may not be clear to the user why the order should matter.We need to separate setters that simply decorate/resize the view (like tileHeight/Width, decorators, select current date) to ones that actually modify adapter state and current page (min/max date, first day of the week).
Propose an immutable
MaterialCalendarView.State
object which is accessed throughmcv.state()
. Calledit()
which creates a new builder from existing state to modify side effecting parameters all at once, then callcommit()
to trigger rebuild of all adapters and child views.Something like this would be the ideal API:
commit()
should be the ONLY method that requires creating an adapter and telling all children to rebuild state based on the new state.The text was updated successfully, but these errors were encountered: