From 3e577039113073f84cdce7533d57617133e83705 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Wed, 25 Aug 2010 13:21:22 -0700 Subject: [PATCH] Fixed up bugs in reminders that would cause them to go off continually. Version bumped to 3.2.7 --- astrid/AndroidManifest.xml | 4 ++-- .../astrid/reminders/Notifications.java | 7 ++++--- .../astrid/reminders/ReminderService.java | 20 +++++++++++++------ .../src/com/todoroo/astrid/dao/TaskDao.java | 12 +++++++---- .../astrid/service/UpgradeService.java | 7 ++++++- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 5fdab1ed1..b6dc9c8cc 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionName="3.2.7 (bug fixes and ui improvements)" + android:versionCode="154"> diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java index 7a08c14e2..53c20484d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java @@ -136,10 +136,11 @@ public class Notifications extends BroadcastReceiver { // update last reminder time task.setValue(Task.REMINDER_LAST, DateUtilities.now()); - taskDao.saveExisting(task); + boolean saved = taskDao.saveExisting(task); - // schedule next notification - ReminderService.getInstance().scheduleAlarm(task); + // schedule next notification (unless couldn't save last time) + if(saved) + ReminderService.getInstance().scheduleAlarm(task); Context context = ContextManager.getContext(); String title = context.getString(R.string.app_name); diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java index edc5d7cd8..dc199f3af 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java @@ -199,7 +199,7 @@ public final class ReminderService { private long calculateNextOverdueReminder(Task task) { if(task.hasDueDate() && task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE)) { long dueDate = task.getValue(Task.DUE_DATE); - long lastReminder = task.getValue(Task.REMINDER_LAST);; + long lastReminder = task.getValue(Task.REMINDER_LAST); if(dueDate > DateUtilities.now()) return dueDate + (long)((0.5f + 2f * random.nextFloat()) * DateUtilities.ONE_HOUR); @@ -233,18 +233,26 @@ public final class ReminderService { long dueDate = task.getValue(Task.DUE_DATE); long lastReminder = task.getValue(Task.REMINDER_LAST);; - if(lastReminder > dueDate) - return NO_ALARM; - else if(task.hasDueTime()) + long dueDateAlarm; + + if(task.hasDueTime()) // return due date straight up - return dueDate; + dueDateAlarm = dueDate; else { // return notification time on this day Date date = new Date(dueDate); date.setHours(Preferences.getIntegerFromString(R.string.p_rmd_time, 12)); date.setMinutes(0); - return date.getTime(); + dueDateAlarm = date.getTime(); } + + if(lastReminder > dueDateAlarm) + return NO_ALARM; + + if(dueDate > DateUtilities.now() && dueDateAlarm < DateUtilities.now()) + dueDateAlarm = dueDate; + + return dueDateAlarm; } return NO_ALARM; } diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index 490525359..c5f7d2841 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -225,10 +225,14 @@ public class TaskDao extends GenericDao { * @param skipHooks whether this save occurs as part of a sync */ private void afterSave(Task task, ContentValues values) { - if(values != null && values.containsKey(Task.COMPLETION_DATE.name) && task.isCompleted()) - afterComplete(task, values); - else - ReminderService.getInstance().scheduleAlarm(task); + if(values != null) { + if(values.containsKey(Task.COMPLETION_DATE.name) && task.isCompleted()) + afterComplete(task, values); + else if(values.containsKey(Task.DUE_DATE.name) || + values.containsKey(Task.REMINDER_FLAGS.name) || + values.containsKey(Task.REMINDER_PERIOD.name)) + ReminderService.getInstance().scheduleAlarm(task); + } Astrid2TaskProvider.notifyDatabaseModification(); TasksWidget.updateWidgets(ContextManager.getContext()); diff --git a/astrid/src/com/todoroo/astrid/service/UpgradeService.java b/astrid/src/com/todoroo/astrid/service/UpgradeService.java index 87895c0c7..3f5512bed 100644 --- a/astrid/src/com/todoroo/astrid/service/UpgradeService.java +++ b/astrid/src/com/todoroo/astrid/service/UpgradeService.java @@ -16,6 +16,7 @@ import com.todoroo.astrid.dao.Database; public final class UpgradeService { + private static final int V3_2_6 = 153; private static final int V3_2_5 = 152; private static final int V3_2_4 = 151; private static final int V3_2_3 = 150; @@ -110,8 +111,12 @@ public final class UpgradeService { "If you liked the old version, you can also go back by " + "clicking here", }); + if(from > V3_1_0 && from <= V3_2_6) + newVersionString(changeLog, "3.2.7 (8/25/10)", new String[] { + "Fixed: crazy notifications for overdue tasks! :(", + }); if(from > V3_1_0 && from <= V3_2_5) - newVersionString(changeLog, "3.2.6 (8/24/10)", new String[] { + newVersionString(changeLog, "3.2.7 (8/24/10)", new String[] { "RTM: fix for login popping up randomly, not syncing priority", "Sync: added a 'Sync Now!' button to the menu, moved options to Settings", "Improvements to notification code to remind you of missed notifications",