prolificinteractive / material-calendarview

A Material design back port of Android's CalendarView
https://prolificinteractive.github.io/material-calendarview/
MIT License
5.92k stars 1.32k forks source link

Last week is missing in some months #995

Open selarugirl opened 5 years ago

selarugirl commented 5 years ago

In calendar view, I noticed that in some months, the last week is missing. I'm using the following version of the library. implementation 'com.prolificinteractive:material-calendarview:1.4.3'

Screenshot_2019-10-08-13-22-55-00

I have checked this with different mobile devices and Android versions, but I get this issue only in some devices. Currently I'm facing this issue in OPPO F5. Below is the xml code of the calendar view.

`<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:orientation="horizontal" android:paddingBottom="100dp">

<ImageButton
    android:id="@+id/balance_arrow_left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true"
    android:layout_gravity="center_vertical"
    android:layout_marginStart="5dp"
    android:background="@drawable/circle_shadow"
    android:elevation="4dp"
    android:src="@drawable/ic_circular_arrow"/>

    <com.prolificinteractive.materialcalendarview.MaterialCalendarView 
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/balance_calendar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toStartOf="@+id/balance_arrow_right"
        android:layout_toEndOf="@+id/balance_arrow_left"
        app:layout_collapseMode="parallax"
        app:mcv_arrowColor="@android:color/white"
        app:mcv_firstDayOfWeek="monday"
        app:mcv_headerTextAppearance="@style/headerTextAppearance"
        app:mcv_selectionColor="#f4c842"
        app:mcv_weekDayTextAppearance="@style/weekDayTextAppearance"
        app:mcv_showOtherDates="defaults"/>

        <ImageButton
            android:id="@+id/balance_arrow_right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_gravity="center_vertical"
            android:layout_marginEnd="5dp"
            android:background="@drawable/circle_shadow"
            android:elevation="4dp"
            android:rotation="180"
            android:src="@drawable/ic_circular_arrow" />

`

firebirdberlin commented 4 years ago

The reason is this function:

    private int getWeekCountBasedOnMode() {
        int weekCount = calendarMode.visibleWeeksCount;
        boolean isInMonthsMode = calendarMode.equals(CalendarMode.MONTHS);
        if (isInMonthsMode && mDynamicHeightEnabled && adapter != null && pager != null) {
            Calendar cal = (Calendar) adapter.getItem(pager.getCurrentItem()).getCalendar().clone();
            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
            //noinspection ResourceType
            cal.setFirstDayOfWeek(getFirstDayOfWeek());
            weekCount = cal.get(Calendar.WEEK_OF_MONTH);
        }
        return weekCount + DAY_NAMES_ROW;
    }

This gives the correct number of lines:

Calendar cal = (Calendar) adapter.getItem(pager.getCurrentItem()).getCalendar().clone();
cal.setMinimalDaysInFirstWeek(1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));