From 438bfdefa4e2e4b26c4f72405b5df8ad0a96e535 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Sat, 1 Oct 2011 00:00:39 -0700 Subject: [PATCH] fix for repeat-after-complete weekly setting due time on tasks --- .../todoroo/andlib/utility/DateUtilities.java | 29 +++---------------- astrid/AndroidManifest.xml | 4 +-- .../repeats/RepeatTaskCompleteListener.java | 19 ++++++++---- .../astrid/repeats/NewRepeatTests.java | 3 +- .../repeats/RepeatAfterCompleteTests.java | 8 ++++- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/api/src/com/todoroo/andlib/utility/DateUtilities.java b/api/src/com/todoroo/andlib/utility/DateUtilities.java index fd847e219..464981476 100644 --- a/api/src/com/todoroo/andlib/utility/DateUtilities.java +++ b/api/src/com/todoroo/andlib/utility/DateUtilities.java @@ -46,31 +46,10 @@ public class DateUtilities { * @return the calculated time in milliseconds */ public static final long addCalendarMonthsToUnixtime(long time, int interval) { - long result = 0; - Date date = new Date(time); - - int month = date.getMonth(); - int year = date.getYear(); - - int yearsToAdd = interval / 12; - int monthsToAdd = interval % 12; - - year += yearsToAdd; - month += monthsToAdd; - - // correct month overflow - if (month > Calendar.DECEMBER) { - month = month - Calendar.DECEMBER - 1; - year++; - } - - // the day stays the same, thats the point - // it's especially important for birthday-reminders - date.setMonth(month); - date.setYear(year); - - result = date.getTime(); - return result; + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(time); + c.add(Calendar.MONTH, interval); + return c.getTimeInMillis(); } /** Returns unixtime for current time */ diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 2bd71740e..b8dac66a2 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionName="3.8.4.1" + android:versionCode="196"> diff --git a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java index e0aeb0a9b..996f56a7a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java +++ b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java @@ -97,8 +97,9 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver { clone.setValue(Task.REMINDER_SNOOZE, 0L); clone.setValue(Task.REMINDER_LAST, 0L); - boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null && - !Preferences.getStringValue(R.string.gcal_p_default).equals("-1"); + boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null + && !Preferences.getStringValue(R.string.gcal_p_default). + equals("-1"); //$NON-NLS-1$ if (gcalCreateEventEnabled) { ContentResolver cr = ContextManager.getContext().getContentResolver(); Uri calendarUri = GCalHelper.createTaskEvent(clone, cr, new ContentValues()); @@ -139,13 +140,14 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver { if(rrule.getFreq() == Frequency.HOURLY || rrule.getFreq() == Frequency.MINUTELY) return handleSubdayRepeat(original, rrule); - else if(rrule.getByDay().size() > 0 && repeatAfterCompletion) - return handleWeeklyRepeatAfterComplete(rrule, original); + else if(rrule.getFreq() == Frequency.WEEKLY && rrule.getByDay().size() > 0 && repeatAfterCompletion) + return handleWeeklyRepeatAfterComplete(rrule, original, task.hasDueTime()); else return invokeRecurrence(rrule, original, startDateAsDV); } - private static long handleWeeklyRepeatAfterComplete(RRule rrule, Date original) { + private static long handleWeeklyRepeatAfterComplete(RRule rrule, Date original, + boolean hasDueTime) { List byDay = rrule.getByDay(); long newDate = original.getTime(); newDate += DateUtilities.ONE_WEEK * (rrule.getInterval() - 1); @@ -158,7 +160,12 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver { do { date.add(Calendar.DATE, 1); } while (date.get(Calendar.DAY_OF_WEEK) != next.wday.javaDayNum); - return date.getTimeInMillis(); + + long time = date.getTimeInMillis(); + if(hasDueTime) + return Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, time); + else + return Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, time); } private static Comparator weekdayCompare = new Comparator() { diff --git a/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java b/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java index 89480821d..6f9c57328 100644 --- a/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java +++ b/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java @@ -114,7 +114,8 @@ public class NewRepeatTests extends DatabaseTestCase { } } - protected void testRepeating(boolean completeBefore, boolean fromCompletion, RRule rrule, Frequency frequency, String title) { + protected void testRepeating(boolean completeBefore, boolean fromCompletion, + RRule rrule, Frequency frequency, String title) { for (int i = 0; i < StartupService.INTRO_TASK_SIZE; i++) { // Create startup tasks so sync services don't miss the test tasks Task temp = new Task(); temp.setValue(Task.TITLE, "" + i); diff --git a/tests/src/com/todoroo/astrid/repeats/RepeatAfterCompleteTests.java b/tests/src/com/todoroo/astrid/repeats/RepeatAfterCompleteTests.java index 302fa4a39..6407bf011 100644 --- a/tests/src/com/todoroo/astrid/repeats/RepeatAfterCompleteTests.java +++ b/tests/src/com/todoroo/astrid/repeats/RepeatAfterCompleteTests.java @@ -50,11 +50,15 @@ public class RepeatAfterCompleteTests extends TodorooTestCase { buildRRule(6, freq); nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal()); assertDateTimeEquals(freq.toString() + "x6", DateUtilities.now() + 6 * interval, nextDueDate); + task.setValue(Task.DUE_DATE, nextDueDate); + assertTrue(task.hasDueTime()); } } public void testDailyAndGreaterFreqs() throws ParseException { - task.setValue(Task.DUE_DATE, DateUtilities.now() - DateUtilities.ONE_WEEK); + task.setValue(Task.DUE_DATE, + Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, + DateUtilities.now() - DateUtilities.ONE_WEEK)); task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true); for(int interval = 1; interval < 7; interval++) { @@ -76,6 +80,8 @@ public class RepeatAfterCompleteTests extends TodorooTestCase { buildRRule(interval, freq); nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal()); assertDateEquals(freq.toString() + "x" + interval, next, nextDueDate); + task.setValue(Task.DUE_DATE, nextDueDate); + assertFalse(task.hasDueTime()); } } }