recruit-mp / LightCalendarView

A lightweight monthly calendar view for Android, fully written in Kotlin. Designed to meet the minimum demands for typical calendars.
Apache License 2.0
445 stars 67 forks source link

Unselect date after swiping to another month #21

Open csbenz opened 7 years ago

csbenz commented 7 years ago

When I swipe to another month, select a day and come back to the initial month, the day is still selected. Is this a normal behaviour? Because it isn't intuitive and there's no way of unselecting the day. What I propose: when a day is clicked, all other days (there should be only one) are unselected.

dgadelha commented 7 years ago

Experiencing this too. :(

Managed to workaround it with that:

private int lastMonth;

@Override
public void onDateSelected(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    if (calendar.get(Calendar.MONTH) != lastMonth) {
        Date epochStart = new Date(0L);

        for (int i = 0; i < 12; i++) {
            MonthView monthView = lightCalendarView.getMonthViewForPosition(i);
            if (monthView != null) monthView.setSelectedDate(epochStart);
        }

        lastMonth = calendar.get(Calendar.MONTH);
    }
}
filippe-cl commented 7 years ago

Same here.

Another workaround:

private Date mLastSelectedDate = Calendar.getInstance().getTime();

private void setCalendarView() {
        mCalendarView.setOnStateUpdatedListener(new LightCalendarView.OnStateUpdatedListener() {
            @Override
            public void onMonthSelected(@NotNull Date date, @NotNull MonthView monthView) {
                monthView.setSelectedDate(mLastSelectedDate);
            }

            @Override
            public void onDateSelected(@NotNull Date date) {
                mLastSelectedDate = date;
            }
        });
    }