Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd51b4d0 authored by Alan Viverette's avatar Alan Viverette
Browse files

Return correct year in DayPickerPagerAdapter.getYearForPosition()

Previously it wasn't offsetting the position by the min date's month,
so it would be off by a year if the min date wasn't in January. Also
now updates button visibility whenever the ViewPager's range changes.

Bug: 21203303
Change-Id: Id7a41a4fa48843943c744fb0fecd4bebb798cee5
parent afabc217
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -186,11 +186,12 @@ class DayPickerPagerAdapter extends PagerAdapter {
    }
    }


    private int getMonthForPosition(int position) {
    private int getMonthForPosition(int position) {
        return position % MONTHS_IN_YEAR + mMinDate.get(Calendar.MONTH);
        return (position + mMinDate.get(Calendar.MONTH)) % MONTHS_IN_YEAR;
    }
    }


    private int getYearForPosition(int position) {
    private int getYearForPosition(int position) {
        return position / MONTHS_IN_YEAR + mMinDate.get(Calendar.YEAR);
        final int yearOffset = (position + mMinDate.get(Calendar.MONTH)) / MONTHS_IN_YEAR;
        return yearOffset + mMinDate.get(Calendar.YEAR);
    }
    }


    private int getPositionForDay(@Nullable Calendar day) {
    private int getPositionForDay(@Nullable Calendar day) {
@@ -198,8 +199,8 @@ class DayPickerPagerAdapter extends PagerAdapter {
            return -1;
            return -1;
        }
        }


        final int yearOffset = (day.get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR));
        final int yearOffset = day.get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR);
        final int monthOffset = (day.get(Calendar.MONTH) - mMinDate.get(Calendar.MONTH));
        final int monthOffset = day.get(Calendar.MONTH) - mMinDate.get(Calendar.MONTH);
        final int position = yearOffset * MONTHS_IN_YEAR + monthOffset;
        final int position = yearOffset * MONTHS_IN_YEAR + monthOffset;
        return position;
        return position;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -176,8 +176,6 @@ class DayPickerView extends ViewGroup {
                }
                }
            }
            }
        });
        });

        updateButtonVisibility(mViewPager.getCurrentItem());
    }
    }


    private void updateButtonVisibility(int position) {
    private void updateButtonVisibility(int position) {
@@ -346,6 +344,8 @@ class DayPickerView extends ViewGroup {
        // Changing the min/max date changes the selection position since we
        // Changing the min/max date changes the selection position since we
        // don't really have stable IDs. Jumps immediately to the new position.
        // don't really have stable IDs. Jumps immediately to the new position.
        setDate(mSelectedDay.getTimeInMillis(), false, false);
        setDate(mSelectedDay.getTimeInMillis(), false, false);

        updateButtonVisibility(mViewPager.getCurrentItem());
    }
    }


    /**
    /**