Material-calendarview: setCalendarDisplayMode(CalendarMode.WEEKS) wrong week when Date selected

Created on 28 Jan 2016  路  18Comments  路  Source: prolificinteractive/material-calendarview

When you "collapse" the Calendar with .setCalendarDisplayMode(CalendarMode.WEEKS), the week displayed is one week to early, when using Monday as first day of the week. (Only working when i select the Sunday)
[BUG]

bug

Most helpful comment

I still have this issue on 1.4.0 when using monday as firstDayOfWeek

All 18 comments

its not working even if i set to Sunday .. on lollipop and above.
Works on pre-lolliop devices. if first day is Sunday.

problem with setCurrentDate
date set to Saturday or Sunday of the week in Week View.

eg:
In weekview (Today:30/6/16)
CurrentDate: CalendarDay{2016-2-26} selected Date: CalendarDay{2016-2-30}

Same bug on marshmallow, but week switches to the desired week if setCurrentTime set for Sunday
There is fast fix - just add one week to the current date.
Calendar now = Calendar.getInstance();
now.add(Calendar.DATE, 7);
calendarView.setCurrentDate(CalendarDay.from(now), true);

Adding dayDiff += (Calendar.DAY_OF_WEEK_IN_MONTH - firstDayOfTheWeek) % 7; between line 69-70 in WeekPagerAdapter#weekNumberDifference(...) seems to fix this.
Expose 'firstDayOfTheWeek' in CalendarPagerAdapter with 'public static' modifier.

@joecizac Thanks for your answer we are going to check that out

This issue has been fixed and is available in the 1.3 snapshot. Stay tuned for the next release.You can try the 1.3 snapshot with the instructions in README. Enjoy and report issues!

The issue still persists in nexus 5 running on 6.0.1...dunno why...
Working on other phones though.

yes issue still persists in marshmallow ... i have use a hack to scroll the pager in Week view. its working fine in lollipop and below i think

And the problem aggravates with setMaximumDate

@joecizac @victorileaf Can you provide full details on the MCV configuration you are using to repro this issue?

Also, we encourage you to try out the 1.4.0-SNAPSHOT and see if the issue is present. It is known that for 1.3.0 and below the _order in which certain setters are called will affect the final state of the MCV_, especially setMin/MaxDate, CalendarMode, and FirstDayOfWeek. It is hopefully resolved with 1.4.0 with the introduction of the state builder.

mCalendarView = (MaterialCalendarView) parent.findViewById(R.id.cal_week); mCalendarView.setShowOtherDates(MaterialCalendarView.SHOW_ALL); mCalendarView.setSelectedDate(now.getTime()); mCalendarView.setCurrentDate(CalendarDay.from(now), false); mCalendarView.setMaximumDate(now.getTime());

For 1.3.0 and below, you should call setMaxDate before Current/Selected; min/max does things which rebuild the adapters and is especially sensitive for Week mode.

Setting Min/Max Date, CalendarMode, and FirstDayOfWeek should always be the first things to configure for MCV because of its stateful nature.

EDIT: Was able to repro issue using today (05/25/16) with the above params. Bug is still present in 1.4.0 This is sadly a known issue regarding setting Max date in Week mode, and it is unclear what exactly is causing it. Will dive deeper into setting max date implementation when I have time. (This is one of the primary reasons Week mode is marked @Experimental)

The issue is with Marshmallow and N preview.

No, it's not platform specific. I can repro this even on a 5.1 device. This snippet will break on 1.4.0 for example:

CalendarDay today = CalendarDay.from(2016, 4, 25);

widget.state().edit()
  .setMaximumDate(today)
  .setCalendarDisplayMode(CalendarMode.WEEKS)
  .commit();

widget.setCurrentDate(today);
widget.setSelectedDate(today);

So this bug should be re-opened right?

It has already been reopened.

Fixed in 1.4.0

I still have this issue on 1.4.0 when using monday as firstDayOfWeek

issue in marshmallow and above selecting wrong week..and i don't want set max date..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chuks picture chuks  路  5Comments

gibsonndemanga picture gibsonndemanga  路  6Comments

vincent-etienne picture vincent-etienne  路  7Comments

broakenmedia picture broakenmedia  路  5Comments

don59 picture don59  路  3Comments