calendar header fix (TUTU-1286)
This commit is contained in:
parent
27aadbb40e
commit
c0bd08cc88
|
|
@ -219,16 +219,37 @@ public final class CalendarUtils {
|
|||
// add range with days before today
|
||||
calendarItems.add(new CalendarDayItem(calendar.getTimeInMillis() / CalendarAdapter.ONE_DAY_LENGTH + 1,
|
||||
1, shift, shift + firstDate - 1, CalendarDateState.BEFORE_TODAY));
|
||||
shift += firstDate - 1;
|
||||
shift += firstDate;
|
||||
|
||||
// add today item
|
||||
calendar.setTime(cleanStartDate.getTime());
|
||||
calendarItems.add(new CalendarDayItem(calendar.getTimeInMillis() / CalendarAdapter.ONE_DAY_LENGTH + 1,
|
||||
firstDate + 1, shift + 1, shift + 1, CalendarDateState.TODAY));
|
||||
firstDate + 1, shift, shift, CalendarDateState.TODAY));
|
||||
shift += 1;
|
||||
|
||||
//add empty items and header if current day the last day in the month
|
||||
if (calendar.get(Calendar.DAY_OF_MONTH) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) {
|
||||
addItemsIfCurrentDayTheLastDayInTheMonth(calendar, calendarItems, shift);
|
||||
}
|
||||
|
||||
return calendarItems;
|
||||
}
|
||||
|
||||
private static void addItemsIfCurrentDayTheLastDayInTheMonth(@NonNull final Calendar calendar,
|
||||
@NonNull final List<CalendarItem> calendarItems,
|
||||
final int initialShift) {
|
||||
int shift = initialShift;
|
||||
final Calendar newMonthCalendar = Calendar.getInstance();
|
||||
newMonthCalendar.setTime(calendar.getTime());
|
||||
newMonthCalendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
final int firstFayInNextMonth = getFirstDateStart(newMonthCalendar);
|
||||
calendarItems.add(new CalendarEmptyItem(shift, shift + (7 - firstFayInNextMonth) - 1));
|
||||
shift += 7 - firstFayInNextMonth;
|
||||
calendarItems.add(new CalendarHeaderItem(calendar.get(Calendar.MONTH) + 1, shift, shift));
|
||||
shift += 1;
|
||||
calendarItems.add(new CalendarEmptyItem(shift, shift + firstFayInNextMonth - 1));
|
||||
}
|
||||
|
||||
private static int getFirstDateStart(@NonNull final Calendar calendar) {
|
||||
int firstDateStart = calendar.get(Calendar.DAY_OF_WEEK) - 2;
|
||||
if (firstDateStart == -1) {
|
||||
|
|
@ -249,4 +270,4 @@ public final class CalendarUtils {
|
|||
private CalendarUtils() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue