File tree Expand file tree Collapse file tree 2 files changed +18
-20
lines changed
lib/java/com/google/android/material/datepicker Expand file tree Collapse file tree 2 files changed +18
-20
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,10 @@ boolean isWithinBounds(long date) {
8888 return start .getDay (1 ) <= date && date <= end .getDay (end .daysInMonth );
8989 }
9090
91+ boolean isWithinBounds (Month month ) {
92+ return start .compareTo (month ) <= 0 && end .compareTo (month ) >= 0 ;
93+ }
94+
9195 /**
9296 * Returns the {@link DateValidator} that determines whether a date can be clicked and selected.
9397 */
Original file line number Diff line number Diff line change @@ -463,26 +463,20 @@ public void onClick(View view) {
463463 }
464464 });
465465
466- monthNext .setOnClickListener (
467- new OnClickListener () {
468- @ Override
469- public void onClick (View view ) {
470- int currentItem = getLayoutManager ().findFirstVisibleItemPosition ();
471- if (currentItem + 1 < recyclerView .getAdapter ().getItemCount ()) {
472- setCurrentMonth (monthsPagerAdapter .getPageMonth (currentItem + 1 ));
473- }
474- }
475- });
476- monthPrev .setOnClickListener (
477- new OnClickListener () {
478- @ Override
479- public void onClick (View view ) {
480- int currentItem = getLayoutManager ().findLastVisibleItemPosition ();
481- if (currentItem - 1 >= 0 ) {
482- setCurrentMonth (monthsPagerAdapter .getPageMonth (currentItem - 1 ));
483- }
484- }
485- });
466+ monthNext .setOnClickListener (view -> {
467+ Month currentMonth = getCurrentMonth ();
468+ Month nextMonth = currentMonth .monthsLater (1 );
469+ if (calendarConstraints .isWithinBounds (nextMonth )) {
470+ setCurrentMonth (nextMonth );
471+ }
472+ });
473+ monthPrev .setOnClickListener (view -> {
474+ Month currentMonth = getCurrentMonth ();
475+ Month prevMonth = currentMonth .monthsLater (-1 );
476+ if (calendarConstraints .isWithinBounds (prevMonth )) {
477+ setCurrentMonth (prevMonth );
478+ }
479+ });
486480 }
487481
488482 private void postSmoothRecyclerViewScroll (final int position ) {
You can’t perform that action at this time.
0 commit comments