Closed KaHa6uc closed 6 years ago
Probably related, but the same issue occurs with the title view for the month. From what I can tell, currentMonth is initialized to today at MaterialCalendarView.java#L388 and then it's only updated in response to when the user scrolls via the pager. This is particularly problematic when the min/max date are such that scrolling is not possible.
It seems like the DayViews do represent the days from the current week, which makes it even more confusing. Rather than fork the repo, I've been working around this by using reflection to update MaterialCalendarView.currentMonth prior to calling setCurrentDate().
When set first day of week is set to a Monday, weekView shows previous week by default I am also facing with the same issue. but its only with the oreo i test with jeally bean to naought versions its working fine.
calendarView.state().edit()
.setFirstDayOfWeek(Calendar.MONDAY)
.setCalendarDisplayMode(CalendarMode.WEEKS).commit();
Any fix or workaround for this issue? I am facing this in week mode without setting setFirstDayOfWeek() to MONDAY, today is 27th Feb 2018 and it is showing the last week.
I did set minimum and maximum date and it worked for me, here is my snippet
MaterialCalendarView calendarView = view.findViewById(R.id.calendarView);
calendarView.setOnDateChangedListener(this);
calendarView.setPagingEnabled(false);
calendarView.setTopbarVisible(false);
Calendar currentCal = Calendar.getInstance();
currentCal.clear(Calendar.HOUR_OF_DAY);
currentCal.clear(Calendar.MINUTE);
currentCal.clear(Calendar.SECOND);
currentCal.clear(Calendar.MILLISECOND);
calendarView.setSelectedDate(currentCal.getTime());
Calendar startCal = (Calendar) currentCal.clone();
startCal.set(Calendar.DAY_OF_WEEK, startCal.getFirstDayOfWeek());
Calendar endCal = (Calendar) startCal.clone();
endCal.add(Calendar.WEEK_OF_YEAR, 1);
calendarView.state().edit()
.setMinimumDate(
CalendarDay.from(
startCal.get(Calendar.YEAR),
startCal.get(Calendar.MONTH),
startCal.get(Calendar.DAY_OF_MONTH)
)
)
.setMaximumDate(
CalendarDay.from(
endCal.get(Calendar.YEAR),
endCal.get(Calendar.MONTH),
endCal.get(Calendar.DAY_OF_MONTH)
)
)
.setCalendarDisplayMode(CalendarMode.WEEKS)
.commit();
calendarView.addDecorators(
new TodayDecorator()
);
thank you @dhruvmi and I can work fine by reseting the minDate and MaxDate after as you mentioned. note: remember to set .setFirstDayOfWeek(Calendar.SUNDAY) because the first day of a week is Sunday.
MaterialCalendarView calendarView = view.findViewById(R.id.calendarView);
calendarView.setOnDateChangedListener(this);
Calendar currentCal = Calendar.getInstance();
currentCal.clear(Calendar.HOUR_OF_DAY);
currentCal.clear(Calendar.MINUTE);
currentCal.clear(Calendar.SECOND);
currentCal.clear(Calendar.MILLISECOND);
calendarView.setSelectedDate(currentCal.getTime());
Calendar startCal = (Calendar) currentCal.clone();
startCal.set(Calendar.DAY_OF_WEEK, startCal.getFirstDayOfWeek());
Calendar endCal = (Calendar) startCal.clone();
endCal.add(Calendar.WEEK_OF_YEAR, 1);
calendarView.state().edit()
.setMinimumDate(
CalendarDay.from(
startCal.get(Calendar.YEAR),
startCal.get(Calendar.MONTH),
startCal.get(Calendar.DAY_OF_MONTH)
)
)
.setMaximumDate(
CalendarDay.from(
endCal.get(Calendar.YEAR),
endCal.get(Calendar.MONTH),
endCal.get(Calendar.DAY_OF_MONTH)
)
)
.setCalendarDisplayMode(CalendarMode.WEEKS)
.commit();
calendarView.addDecorators(
new TodayDecorator()
);
calendarView.state().edit()
.setMinimumDate(
CalendarDay.from(
startCal.get(2000),
startCal.get(1),
startCal.get(1)
)
)
.setMaximumDate(
CalendarDay.from(
endCal.get(2050),
endCal.get(12),
endCal.get(30)
)
)
.setCalendarDisplayMode(CalendarMode.WEEKS)
.commit();
I believe that should be fixed in with #809
i disabled topbar visible using setTopbarVisible(false). but need a month and year when scrolling the calendar in past or previous. how to get the date or i need to remove the mcv_arrows.
I'm layout-ing your class like this:
And then stylise like this:
When I .setCurrentDate() to a Monday, the initial display shows the previous week - the week that contains the Sunday with which the week that contains currentDate starts, even though I've told it that the week should start on Monday.
Uncomment the commented line to subtract the number of days needed to set it to a Monday to reproduce the issue.
Please advise.
Thanks in advance.