File tree 2 files changed +18
-20
lines changed
lib/java/com/google/android/material/datepicker 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) {
88
88
return start .getDay (1 ) <= date && date <= end .getDay (end .daysInMonth );
89
89
}
90
90
91
+ boolean isWithinBounds (Month month ) {
92
+ return start .compareTo (month ) <= 0 && end .compareTo (month ) >= 0 ;
93
+ }
94
+
91
95
/**
92
96
* Returns the {@link DateValidator} that determines whether a date can be clicked and selected.
93
97
*/
Original file line number Diff line number Diff line change @@ -463,26 +463,20 @@ public void onClick(View view) {
463
463
}
464
464
});
465
465
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
+ });
486
480
}
487
481
488
482
private void postSmoothRecyclerViewScroll (final int position ) {
You can’t perform that action at this time.
0 commit comments