diff options
author | Paul Sliwowski <psliwowski@google.com> | 2013-06-20 21:51:40 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-06-20 21:51:40 +0000 |
commit | 97efecdb39c7149fe819f229f9a38401062e7000 (patch) | |
tree | 79dee57d746e993bbc2d67faa1aa5fcb31bd90cd /src | |
parent | 0322d0a6958d271eb2adbd0cb04685c8f08a71c3 (diff) | |
parent | 11d52ec01f9aa6cfae0b193a8362809d77d39835 (diff) | |
download | android_packages_apps_Calendar-97efecdb39c7149fe819f229f9a38401062e7000.tar.gz android_packages_apps_Calendar-97efecdb39c7149fe819f229f9a38401062e7000.tar.bz2 android_packages_apps_Calendar-97efecdb39c7149fe819f229f9a38401062e7000.zip |
Merge "Fix bug in recurrent event dialog picker when setting monthly day of the week." into ics-ub-calendar-eggplant
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java b/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java index acf48431..73591dd9 100644 --- a/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java +++ b/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java @@ -80,6 +80,10 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele private static final int COUNT_MAX = 730; private static final int COUNT_DEFAULT = 5; + // Special cases in monthlyByNthDayOfWeek + private static final int FIFTH_WEEK_IN_A_MONTH = 5; + private static final int LAST_NTH_DAY_OF_WEEK = -1; + private DatePickerDialog mDatePickerDialog; private class RecurrenceModel implements Parcelable { @@ -166,7 +170,10 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele /** * Nth day of the week to repeat. Used when monthlyRepeat == - * MONTHLY_BY_NTH_DAY_OF_WEEK 0=undefined, 1=1st, 2=2nd, etc + * MONTHLY_BY_NTH_DAY_OF_WEEK 0=undefined, -1=Last, 1=1st, 2=2nd, ..., 5=5th + * + * We support 5th, just to handle backwards capabilities with old bug, but it + * gets converted to -1 once edited. */ int monthlyByNthDayOfWeek; @@ -344,6 +351,12 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele public RecurrencePickerDialog() { } + static public boolean isSupportedMonthlyByNthDayOfWeek(int num) { + // We only support monthlyByNthDayOfWeek when it is greater then 0 but less then 5. + // Or if -1 when it is the last monthly day of the week. + return (num > 0 && num <= FIFTH_WEEK_IN_A_MONTH) || num == LAST_NTH_DAY_OF_WEEK; + } + static public boolean canHandleRecurrenceRule(EventRecurrence er) { switch (er.freq) { case EventRecurrence.DAILY: @@ -369,7 +382,7 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele */ int numOfByDayNum = 0; for (int i = 0; i < er.bydayCount; i++) { - if (er.bydayNum[i] > 0) { + if (isSupportedMonthlyByNthDayOfWeek(er.bydayNum[i])) { ++numOfByDayNum; } } @@ -462,8 +475,9 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele int dayOfWeek = EventRecurrence.day2TimeDay(er.byday[i]); model.weeklyByDayOfWeek[dayOfWeek] = true; - if (model.freq == RecurrenceModel.FREQ_MONTHLY && er.bydayNum[i] > 0) { - // LIMITATION: Can handle only (one) weekDayNum and only + if (model.freq == RecurrenceModel.FREQ_MONTHLY && + isSupportedMonthlyByNthDayOfWeek(er.bydayNum[i])) { + // LIMITATION: Can handle only (one) weekDayNum in nth or last and only // when // monthly model.monthlyByDayOfWeek = dayOfWeek; @@ -557,7 +571,7 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele er.bymonthdayCount = 1; } } else if (model.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) { - if (model.monthlyByNthDayOfWeek <= 0) { + if (!isSupportedMonthlyByNthDayOfWeek(model.monthlyByNthDayOfWeek)) { throw new IllegalStateException("month repeat by nth week but n is " + model.monthlyByNthDayOfWeek); } @@ -934,13 +948,22 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele if (mMonthRepeatByDayOfWeekStr == null) { if (mModel.monthlyByNthDayOfWeek == 0) { mModel.monthlyByNthDayOfWeek = (mTime.monthDay + 6) / 7; + // Since not all months have 5 weeks, we convert 5th NthDayOfWeek to + // -1 for last monthly day of the week + if (mModel.monthlyByNthDayOfWeek >= FIFTH_WEEK_IN_A_MONTH) { + mModel.monthlyByNthDayOfWeek = LAST_NTH_DAY_OF_WEEK; + } mModel.monthlyByDayOfWeek = mTime.weekDay; } String[] monthlyByNthDayOfWeekStrs = mMonthRepeatByDayOfWeekStrs[mModel.monthlyByDayOfWeek]; + + // TODO(psliwowski): Find a better way handle -1 indexes + int msgIndex = mModel.monthlyByNthDayOfWeek < 0 ? FIFTH_WEEK_IN_A_MONTH : + mModel.monthlyByNthDayOfWeek; mMonthRepeatByDayOfWeekStr = - monthlyByNthDayOfWeekStrs[mModel.monthlyByNthDayOfWeek - 1]; + monthlyByNthDayOfWeekStrs[msgIndex - 1]; mRepeatMonthlyByNthDayOfWeek.setText(mMonthRepeatByDayOfWeekStr); } break; |