From 9a1757f684d136175c093cb213349fb1ccc50412 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Sat, 6 May 2017 17:02:20 -0700 Subject: [PATCH] Do not offset month adapter count by min date. --- .../date/PagingMonthAdapter.java | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/bottomsheetpickers/src/main/java/com/philliphsu/bottomsheetpickers/date/PagingMonthAdapter.java b/bottomsheetpickers/src/main/java/com/philliphsu/bottomsheetpickers/date/PagingMonthAdapter.java index 371c994..5f63aa9 100644 --- a/bottomsheetpickers/src/main/java/com/philliphsu/bottomsheetpickers/date/PagingMonthAdapter.java +++ b/bottomsheetpickers/src/main/java/com/philliphsu/bottomsheetpickers/date/PagingMonthAdapter.java @@ -29,7 +29,6 @@ import com.philliphsu.bottomsheetpickers.date.MonthView.OnDayClickListener; import java.util.ArrayList; -import java.util.Calendar; import java.util.HashMap; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; @@ -110,24 +109,9 @@ protected void init() { @Override public int getCount() { - final Calendar minDate = mController.getMinDate(); - final Calendar maxDate = mController.getMaxDate(); - final int minMonth = minDate == null ? 0 : minDate.get(Calendar.MONTH); - - // The number of months remaining in minDate's year, from minMonth forward. - int monthsInMinYear = MONTHS_IN_YEAR - minMonth; - // The number of months in maxDate's year, up to maxDate's month. - // From Calendar.JANUARY (0) forward. - int monthsInMaxYear = maxDate == null ? MONTHS_IN_YEAR : maxDate.get(Calendar.MONTH) + 1; - - int count = monthsInMinYear + monthsInMaxYear; - // Add the number of months in between the min and max dates. - // Subtract 2 from the year range because we already counted the min and max years. // Add 1 to get the total number of years in the year range. // e.g. There are 11 years in the range [2016, 2026]. - // => net difference = -1 - count += (mController.getMaxYear() - mController.getMinYear() - 1) * MONTHS_IN_YEAR; - return count; + return (mController.getMaxYear() - mController.getMinYear() + 1) * MONTHS_IN_YEAR; } @Override @@ -267,26 +251,21 @@ protected void onDayTapped(CalendarDay day) { * Returns the month (0 - 11) displayed at this position. */ final int getMonth(int position) { - return (position + getMonthOffset()) % MONTHS_IN_YEAR; + return position % MONTHS_IN_YEAR; } /** * Returns the year displayed at this position. */ final int getYear(int position) { - return (position + getMonthOffset()) / MONTHS_IN_YEAR + mController.getMinYear(); + return position / MONTHS_IN_YEAR + mController.getMinYear(); } /** * @return The page position at which the given day is located. */ final int getPosition(CalendarDay day) { - int positionOfYear = MONTHS_IN_YEAR * (day.year - mController.getMinYear()) - getMonthOffset(); + int positionOfYear = MONTHS_IN_YEAR * (day.year - mController.getMinYear()); return positionOfYear + day.month; } - - private int getMonthOffset() { - Calendar minDate = mController.getMinDate(); - return minDate == null ? 0 : minDate.get(Calendar.MONTH); - } }