From 1c9d4c16967f879717107b06c98f9a9871c7c3ce Mon Sep 17 00:00:00 2001 From: Tim Su Date: Fri, 2 Jul 2010 19:17:39 -0700 Subject: [PATCH] More progress in the effort of getting notifications working. --- astrid/AndroidManifest.xml | 2 + .../reminders/NotificationActivity.java} | 9 +- .../astrid/reminders/Notifications.java | 292 +++++------------- .../astrid/reminders/ReminderService.java | 2 +- astrid/res/values/arrays.xml | 57 ---- astrid/res/values/strings-legacy.xml | 9 - astrid/res/values/strings-reminders.xml | 92 ++++++ .../astrid/data/task/TaskController.java | 17 +- .../astrid/activity/TaskEditActivity.java | 4 +- .../src/com/todoroo/astrid/dao/TaskDao.java | 84 ++++- astrid/translation-notes | 8 + 11 files changed, 274 insertions(+), 302 deletions(-) rename astrid/{src-legacy/com/timsu/astrid/activities/TaskListNotify.java => plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java} (82%) create mode 100644 astrid/res/values/strings-reminders.xml diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 3eecdd7af..a0235fd51 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -195,6 +195,8 @@ + diff --git a/astrid/src-legacy/com/timsu/astrid/activities/TaskListNotify.java b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java similarity index 82% rename from astrid/src-legacy/com/timsu/astrid/activities/TaskListNotify.java rename to astrid/plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java index 75fbb2b6b..9317c69c5 100644 --- a/astrid/src-legacy/com/timsu/astrid/activities/TaskListNotify.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationActivity.java @@ -17,12 +17,15 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package com.timsu.astrid.activities; +package com.todoroo.astrid.reminders; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import com.timsu.astrid.activities.TaskList; +import com.todoroo.astrid.activity.TaskListActivity; + /** * This activity is launched when a user opens up a notification from the * tray. It launches the appropriate activity based on the passed in parameters. @@ -30,7 +33,7 @@ import android.os.Bundle; * @author timsu * */ -public class TaskListNotify extends Activity { +public class NotificationActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { @@ -47,7 +50,7 @@ public class TaskListNotify extends Activity { } private void launchTaskList(Intent intent) { - Intent taskListIntent = new Intent(this, TaskList.class); + Intent taskListIntent = new Intent(this, TaskListActivity.class); taskListIntent.putExtra(TaskList.VARIABLES_TAG, intent.getExtras()); startActivity(taskListIntent); diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java index 6c8fa8c4a..207c7e3cc 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java @@ -1,7 +1,6 @@ package com.todoroo.astrid.reminders; import java.util.Date; -import java.util.Random; import android.app.Activity; import android.app.Notification; @@ -17,85 +16,66 @@ import android.net.Uri; import android.util.Log; import com.timsu.astrid.R; -import com.timsu.astrid.activities.TaskListNotify; -import com.timsu.astrid.activities.TaskListSubActivity; -import com.timsu.astrid.data.task.TaskController; import com.timsu.astrid.data.task.TaskIdentifier; -import com.timsu.astrid.data.task.TaskModelForReminder; import com.timsu.astrid.utilities.Constants; import com.timsu.astrid.utilities.Preferences; +import com.todoroo.andlib.service.Autowired; +import com.todoroo.andlib.service.DependencyInjectionService; +import com.todoroo.andlib.service.ExceptionService; +import com.todoroo.andlib.utility.DateUtilities; +import com.todoroo.astrid.dao.TaskDao; +import com.todoroo.astrid.model.Task; +import com.todoroo.astrid.service.AstridDependencyInjector; public class Notifications extends BroadcastReceiver { - static final String ID_KEY = "id"; - static final String TYPE_KEY = "flags"; - private static final String REPEAT_KEY = "repeat"; - private static final int TAG_ID_OFFSET = 100000; - - // stuff for scheduling - /** minimum # of seconds before a deadline to notify */ - private static final int DEADLINE_NOTIFY_SECS = 60 * 60; - /** # of seconds after deadline to repeat reminder*/ - private static final int DEADLINE_REPEAT = 10 * 60; - - // flags - public static final int FLAG_DEFINITE_DEADLINE = 1 << 0; - public static final int FLAG_PREFERRED_DEADLINE = 1 << 1; - public static final int FLAG_OVERDUE = 1 << 2; - public static final int FLAG_PERIODIC = 1 << 3; - public static final int FLAG_FIXED = 1 << 4; - public static final int FLAG_SNOOZE = 1 << 5; - /** # of bits to shift the fixed alert ID */ - public static final int FIXED_ID_SHIFT = 6; - - private static Random random = new Random(); - - /** Something we can create a notification for */ - public interface Notifiable { - public TaskIdentifier getTaskIdentifier(); - public Integer getNotificationIntervalSeconds(); - public boolean isTaskCompleted(); - public Date getHiddenUntil(); - public Date getDefiniteDueDate(); - public Date getPreferredDueDate(); - public Date getLastNotificationDate(); - public int getNotificationFlags(); - public Integer getEstimatedSeconds(); + // --- constants + + /** task id extra */ + static final String ID_KEY = "id"; //$NON-NLS-1$ + + /** notification type extra */ + static final String TYPE_KEY = "flags"; //$NON-NLS-1$ + + // --- instance variables + + @Autowired + private TaskDao taskDao; + + @Autowired + private ExceptionService exceptionService; + + // --- alarm handling + + static { + AstridDependencyInjector.initialize(); } @Override /** Alarm intent */ public void onReceive(Context context, Intent intent) { + DependencyInjectionService.getInstance().inject(this); + long id = intent.getLongExtra(ID_KEY, 0); - int flags = intent.getIntExtra(FLAGS_KEY, 0); + int type = intent.getIntExtra(TYPE_KEY, 0); Resources r = context.getResources(); String reminder; - if((flags & FLAG_DEFINITE_DEADLINE) > 0) - reminder = r.getString(R.string.notif_definiteDueDate); - else if((flags & FLAG_PREFERRED_DEADLINE) > 0) - reminder = r.getString(R.string.notif_preferredDueDate); + if(type == ReminderService.TYPE_DUE || type == ReminderService.TYPE_OVERDUE) + reminder = getRandomReminder(r.getStringArray(R.array.reminders_due)); + else if(type == ReminderService.TYPE_SNOOZE) + reminder = getRandomReminder(r.getStringArray(R.array.reminders_snooze)); else - reminder = getRandomReminder(r); - - long repeatInterval = intent.getLongExtra(REPEAT_KEY, 0); - if(Constants.DEBUG) - Log.e("ALARM", "Alarm triggered id " + id +", flags " + flags + - ", repeat " + repeatInterval); + reminder = getRandomReminder(r.getStringArray(R.array.reminders)); - if(!showNotification(context, id, flags, repeatInterval, reminder)) { - deleteAlarm(context, intent, id); + if(!showNotification(context, id, type, reminder)) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel((int)id); } } - // --- alarm manager stuff - - - - // --- notification manager stuff + // --- notification creation /** Clear notifications associated with this application */ public static void clearAllNotifications(Context context, TaskIdentifier taskId) { @@ -104,57 +84,46 @@ public class Notifications extends BroadcastReceiver { nm.cancel((int)taskId.getId()); } - private static String getRandomReminder(Resources r) { - String[] reminders = r.getStringArray(R.array.reminders); - int next = random.nextInt(reminders.length); + /** @return a random reminder string */ + private static String getRandomReminder(String[] reminders) { + int next = ReminderService.random.nextInt(reminders.length); String reminder = reminders[next]; return reminder; } - /** Schedule a new notification about the given task. Returns false if there was - * some sort of error or the alarm should be disabled. */ - public static boolean showNotification(Context context, long id, - int flags, long repeatInterval, String reminder) { + /** + * Schedule a new notification about the given task. Returns false if there was + * some sort of error or the alarm should be disabled. + */ + public boolean showNotification(Context context, long id, + int type, String reminder) { - String taskName; - TaskController controller = new TaskController(context); - boolean nonstopMode = false; + Task task; try { - controller.open(); - TaskModelForReminder task = controller.fetchTaskForReminder(new TaskIdentifier(id)); - - // you're working on it - don't sound, don't delete - if(task.getTimerStart() != null) - return true; - - // you're done - don't sound, do delete - if(task.isTaskCompleted()) - return false; + task = taskDao.fetch(id, Task.TITLE, Task.HIDE_UNTIL, Task.COMPLETION_DATE, + Task.DELETION_DATE, Task.REMINDER_FLAGS); + } catch (Exception e) { + exceptionService.reportError("show-notif", e); //$NON-NLS-1$ + return false; + } - // it's hidden - don't sound, don't delete - if(task.getHiddenUntil() != null && - task.getHiddenUntil().after(new Date()) && - (flags & FLAG_PERIODIC) > 0) - return true; + // you're done - don't sound, do delete + if(task.isCompleted() || task.isDeleted()) + return false; - taskName = task.getName(); - if((flags & FLAG_PERIODIC) > 0) - controller.setLastNotificationTime(task.getTaskIdentifier(), - new Date()); + // it's hidden - don't sound, don't delete + if(task.isHidden() && type == ReminderService.TYPE_RANDOM) + return true; - if((task.getNotificationFlags() & TaskModelForReminder.NOTIFY_NONSTOP) > 0) - nonstopMode = true; + // read properties + String taskTitle = task.getValue(Task.TITLE); + boolean nonstopMode = task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_NONSTOP); - } catch (Exception e) { - // task might have been deleted - Log.e(Notifications.class.getSimpleName(), - "Error loading task for notification", e); - return false; - } finally { - controller.close(); - } + // update last reminder time + task.setValue(Task.REMINDER_LAST, DateUtilities.now()); + taskDao.save(task, false); - // quiet hours? disabled if alarm clock + // quiet hours? unless alarm clock boolean quietHours = false; Integer quietHoursStart = Preferences.getQuietHourStart(context); Integer quietHoursEnd = Preferences.getQuietHourEnd(context); @@ -173,11 +142,11 @@ public class Notifications extends BroadcastReceiver { .getSystemService(Context.NOTIFICATION_SERVICE); Resources r = context.getResources(); - Intent notifyIntent = new Intent(context, TaskListNotify.class); - notifyIntent.putExtra(TaskListSubActivity.LOAD_INSTANCE_TOKEN, id); + Intent notifyIntent = new Intent(context, NotificationActivity.class); + /*notifyIntent.putExtra(TaskListSubActivity.LOAD_INSTANCE_TOKEN, id); notifyIntent.putExtra(TaskListSubActivity.FROM_NOTIFICATION_TOKEN, true); notifyIntent.putExtra(TaskListSubActivity.NOTIF_FLAGS_TOKEN, flags); - notifyIntent.putExtra(TaskListSubActivity.NOTIF_REPEAT_TOKEN, repeatInterval); + notifyIntent.putExtra(TaskListSubActivity.NOTIF_REPEAT_TOKEN, repeatInterval); TODO */ PendingIntent pendingIntent = PendingIntent.getActivity(context, (int)id, notifyIntent, PendingIntent.FLAG_ONE_SHOT); @@ -200,7 +169,7 @@ public class Notifications extends BroadcastReceiver { icon, reminder, System.currentTimeMillis()); notification.setLatestEventInfo(context, appName, - reminder + " " + taskName, + reminder + " " + taskTitle, //$NON-NLS-1$ pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; if(Preferences.isPersistenceMode(context)) { @@ -216,10 +185,10 @@ public class Notifications extends BroadcastReceiver { AudioManager audioManager = (AudioManager)context.getSystemService( Context.AUDIO_SERVICE); - // if nonstop mode is activated, set up the flags for insistent + // if non-stop mode is activated, set up the flags for insistent // notification, and increase the volume to full volume, so the user // will actually pay attention to the alarm - if(nonstopMode && (flags & FLAG_PERIODIC) == 0) { + if(nonstopMode && (type != ReminderService.TYPE_RANDOM)) { notification.flags |= Notification.FLAG_INSISTENT; notification.audioStreamType = AudioManager.STREAM_ALARM; audioManager.setStreamVolume(AudioManager.STREAM_ALARM, @@ -236,7 +205,7 @@ public class Notifications extends BroadcastReceiver { if(audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) { notification.sound = null; } else if(notificationSound != null && - !notificationSound.toString().equals("")) { + !notificationSound.toString().equals("")) { //$NON-NLS-1$ notification.sound = notificationSound; } else { notification.defaults |= Notification.DEFAULT_SOUND; @@ -244,7 +213,7 @@ public class Notifications extends BroadcastReceiver { } // quiet hours + periodic = no vibrate - if(quietHours && (flags & FLAG_PERIODIC) > 0) { + if(quietHours && (type == ReminderService.TYPE_RANDOM)) { notification.vibrate = null; } else { if (Preferences.shouldVibrate(context) @@ -256,121 +225,10 @@ public class Notifications extends BroadcastReceiver { } if(Constants.DEBUG) - Log.w("Astrid", "Logging notification: " + reminder); + Log.w("Astrid", "Logging notification: " + reminder); //$NON-NLS-1$ //$NON-NLS-2$ nm.notify((int)id, notification); return true; } - /** Show a notification when a user is "on-the-clock" for a given task */ - public static boolean showTimingNotification(Context context, - TaskIdentifier taskId, String taskName) { - - String text = context.getResources().getString(R.string.notif_timerStarted) + - " " + taskName; - NotificationManager nm = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); - Resources r = context.getResources(); - - Intent notifyIntent = new Intent(context, TaskListNotify.class); - notifyIntent.putExtra(TaskListSubActivity.LOAD_INSTANCE_TOKEN, taskId.getId()); - notifyIntent.putExtra(TaskListSubActivity.FROM_NOTIFICATION_TOKEN, true); - PendingIntent pendingIntent = PendingIntent.getActivity(context, - (int)taskId.getId(), notifyIntent, 0); - - // create notification object - int icon; - switch(Preferences.getNotificationIconTheme(context)) { - case Preferences.ICON_SET_PINK: - icon = R.drawable.notif_pink_working; - break; - case Preferences.ICON_SET_BORING: - icon = R.drawable.notif_boring_working; - break; - default: - icon = R.drawable.notif_astrid; - } - - String appName = r.getString(R.string.app_name); - Notification notification = new Notification( - icon, text, System.currentTimeMillis()); - notification.setLatestEventInfo(context, - appName, - text, - pendingIntent); - notification.flags |= Notification.FLAG_ONGOING_EVENT | - Notification.FLAG_NO_CLEAR; - notification.flags &= ~Notification.FLAG_AUTO_CANCEL; - - if(Constants.DEBUG) - Log.w("Astrid", "Logging timing notification: " + text); - nm.notify((int)taskId.getId(), notification); - - return true; - } - - /** Schedule a new notification about the given tag. */ - public static boolean showTagNotification(Context context, long tagId, - String reminder) { - - // quiet hours? only for periodic reminders - boolean quietHours = false; - Integer quietHoursStart = Preferences.getQuietHourStart(context); - Integer quietHoursEnd = Preferences.getQuietHourEnd(context); - if(quietHoursStart != null && quietHoursEnd != null) { - int hour = new Date().getHours(); - if(quietHoursStart < quietHoursEnd) { - if(hour >= quietHoursStart && hour < quietHoursEnd) - quietHours = true; - } else { // wrap across 24/hour boundary - if(hour >= quietHoursStart || hour < quietHoursEnd) - quietHours = true; - } - } - - NotificationManager nm = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); - Resources r = context.getResources(); - - Intent notifyIntent = new Intent(context, TaskListNotify.class); - notifyIntent.putExtra(TaskListSubActivity.TAG_TOKEN, tagId); - notifyIntent.putExtra(TaskListSubActivity.FROM_NOTIFICATION_TOKEN, true); - PendingIntent pendingIntent = PendingIntent.getActivity(context, - TAG_ID_OFFSET + (int)tagId, notifyIntent, PendingIntent.FLAG_ONE_SHOT); - - // set up properties (name and icon) for the notification - String appName = r.getString(R.string.app_name); - int icon = R.drawable.notif_tag; - - // create notification object - Notification notification = new Notification( - icon, reminder, System.currentTimeMillis()); - notification.setLatestEventInfo(context, - appName, - reminder, - pendingIntent); - notification.flags |= Notification.FLAG_AUTO_CANCEL; - notification.ledARGB = Color.BLUE; - notification.defaults = Notification.DEFAULT_LIGHTS; - - if(quietHours) { - notification.vibrate = null; - notification.sound = null; - } else { - notification.defaults |= Notification.DEFAULT_VIBRATE; - Uri notificationSound = Preferences.getNotificationRingtone(context); - if(notificationSound != null && - !notificationSound.toString().equals("")) { - notification.sound = notificationSound; - } else { - notification.defaults |= Notification.DEFAULT_SOUND; - } - } - - if(Constants.DEBUG) - Log.w("Astrid", "Logging tag notification: " + reminder); - nm.notify(TAG_ID_OFFSET + (int)tagId, notification); - - return true; - } } \ No newline at end of file diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java index 42d898382..3b4570d5a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java @@ -56,7 +56,7 @@ public final class ReminderService { @Autowired private TaskDao taskDao; - private static final Random random = new Random(); + static final Random random = new Random(); public ReminderService() { DependencyInjectionService.getInstance().inject(this); diff --git a/astrid/res/values/arrays.xml b/astrid/res/values/arrays.xml index 5512ae3a4..47f113a18 100644 --- a/astrid/res/values/arrays.xml +++ b/astrid/res/values/arrays.xml @@ -25,63 +25,6 @@ --> - - - - - - Hi there! Have a sec? - Can I see you for a sec? - Have a few minutes? - Did you forget? - Excuse me! - When you have a minute: - On your agenda: - Free for a moment? - Astrid here! - Hi! Can I bug you? - A minute of your time? - It\'s a great day to - - - - - I\'ve got something for you! - Ready to put this in the past? - Why don\'t you get this done? - How about it? Ready tiger? - Ready to do this? - Can you handle this? - You can be happy! Just finish this! - I promise you\'ll feel better if you finish this! - Won\'t you do this today? - Please finish this, I\'m sick of it! - Can you finish this? Yes you can! - Are you ever going to do this? - Feel good about yourself! Let\'s go! - I\'m so proud of you! Lets get it done! - A little snack after you finish this? - Just this one task? Please? - Time to shorten your todo list! - - - - - Please tell me it isn\'t true that you\'re a procrastinator! - Doesn\'t being lazy get old sometimes? - Somewhere, someone is depending on you to finish this! - When you said postpone, you really meant \'I\'m doing this\', right? - This is the last time you postpone this, right? - Just finish this today, I won\'t tell anyone! - Why postpone when you can um... not postpone! - You\'ll finish this eventually, I presume? - I think you\'re really great! How about not putting this off? - Will you be able to achieve your goals if you do that? - Postpone, postpone, postpone. When will you change! - I\'ve had enough with your excuses! Just do it already! - Didn\'t you make that excuse last time? - I can\'t help you organize your life if you do that... - diff --git a/astrid/res/values/strings-legacy.xml b/astrid/res/values/strings-legacy.xml index f5a2563fe..56fb5f53a 100644 --- a/astrid/res/values/strings-legacy.xml +++ b/astrid/res/values/strings-legacy.xml @@ -399,15 +399,6 @@ Skipped %d tasks.\n when you have uncompleted tasks with the following criteria: Tagged with: - - - - Absolute Deadline! - Goal Deadline! - Working on: - - You have $NUM tagged $TAG! - diff --git a/astrid/res/values/strings-reminders.xml b/astrid/res/values/strings-reminders.xml new file mode 100644 index 000000000..c8e411e85 --- /dev/null +++ b/astrid/res/values/strings-reminders.xml @@ -0,0 +1,92 @@ + + + + + + + Absolute Deadline! + Goal Deadline! + Working on: + + You have $NUM tagged $TAG! + + + + + + Hi there! Have a sec? + Can I see you for a sec? + Have a few minutes? + Did you forget? + Excuse me! + When you have a minute: + On your agenda: + Free for a moment? + Astrid here! + Hi! Can I bug you? + A minute of your time? + It\'s a great day to + + + + + Time to work! + Due date is here! + Ready to start? + You said you would do: + You\'re supposed to start: + Time to start: + It\'s time! + Excuse me! Time for + You free? Time to + + + + + Don\'t be lazy now! + Snooze time is up! + No more snoozing! + Now are you ready? + No more postponing! + + + + + I\'ve got something for you! + Ready to put this in the past? + Why don\'t you get this done? + How about it? Ready tiger? + Ready to do this? + Can you handle this? + You can be happy! Just finish this! + I promise you\'ll feel better if you finish this! + Won\'t you do this today? + Please finish this, I\'m sick of it! + Can you finish this? Yes you can! + Are you ever going to do this? + Feel good about yourself! Let\'s go! + I\'m so proud of you! Lets get it done! + A little snack after you finish this? + Just this one task? Please? + Time to shorten your todo list! + + + + + Please tell me it isn\'t true that you\'re a procrastinator! + Doesn\'t being lazy get old sometimes? + Somewhere, someone is depending on you to finish this! + When you said postpone, you really meant \'I\'m doing this\', right? + This is the last time you postpone this, right? + Just finish this today, I won\'t tell anyone! + Why postpone when you can um... not postpone! + You\'ll finish this eventually, I presume? + I think you\'re really great! How about not putting this off? + Will you be able to achieve your goals if you do that? + Postpone, postpone, postpone. When will you change! + I\'ve had enough with your excuses! Just do it already! + Didn\'t you make that excuse last time? + I can\'t help you organize your life if you do that... + + + diff --git a/astrid/src-legacy/com/timsu/astrid/data/task/TaskController.java b/astrid/src-legacy/com/timsu/astrid/data/task/TaskController.java index ab37fcaa4..1004277a3 100644 --- a/astrid/src-legacy/com/timsu/astrid/data/task/TaskController.java +++ b/astrid/src-legacy/com/timsu/astrid/data/task/TaskController.java @@ -46,7 +46,6 @@ import com.timsu.astrid.data.task.AbstractTaskModel.TaskModelDatabaseHelper; import com.timsu.astrid.provider.TasksProvider; import com.timsu.astrid.sync.Synchronizer; import com.timsu.astrid.sync.Synchronizer.SynchronizerListener; -import com.todoroo.astrid.reminders.ReminderService; /** * Controller for task-related operations @@ -307,12 +306,12 @@ public class TaskController extends AbstractController { // task timer was updated, update notification bar if(values.containsKey(AbstractTaskModel.TIMER_START)) { // show notification bar if timer was started - if(values.getAsLong(AbstractTaskModel.TIMER_START) != 0) { - ReminderService.showTimingNotification(context, - task.getTaskIdentifier(), task.getName()); - } else { - ReminderService.clearAllNotifications(context, task.getTaskIdentifier()); - } +// if(values.getAsLong(AbstractTaskModel.TIMER_START) != 0) { +// ReminderService.showTimingNotification(context, +// task.getTaskIdentifier(), task.getName()); +// } else { +// ReminderService.clearAllNotifications(context, task.getTaskIdentifier()); +// } } // due date was updated, update calendar event @@ -390,7 +389,7 @@ public class TaskController extends AbstractController { /** Clean up state from a task. Called when deleting or completing it */ private void cleanupTask(TaskIdentifier taskId, boolean isRepeating) { // delete notifications & alarms - ReminderService.deleteAlarm(context, null, taskId.getId()); +// ReminderService.deleteAlarm(context, null, taskId.getId()); // delete calendar event if not repeating if(!isRepeating) { @@ -578,7 +577,7 @@ public class TaskController extends AbstractController { TaskModelForNotify task = fetchTaskForNotify(taskId); AlertController alertController = new AlertController(context); alertController.open(); - ReminderService.updateAlarm(context, this, alertController, task); +// ReminderService.updateAlarm(context, this, alertController, task); alertController.close(); } diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java index ef2c0581c..b766daf4d 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java @@ -795,7 +795,7 @@ public final class TaskEditActivity extends TabActivity { this.urgency.setAdapter(urgencyAdapter); if(isNewTask()) { - urgency.setSelection(Preferences.getIntegerFromString(R.string.EPr_default_urgency_key)); + urgency.setSelection(Preferences.getIntegerFromString(R.string.p_default_urgency_key)); } else { urgency.setSelection(0); } @@ -979,7 +979,7 @@ public final class TaskEditActivity extends TabActivity { random = (CheckBox)findViewById(randomId); mode = (Spinner)findViewById(modeId); - periodic = Preferences.getIntegerFromString(R.string.p_notif_defaultRemind) + periodic = Preferences.getIntegerFromString(R.string.p_default_reminder_random) * DateUtilities.ONE_DAY; updatePeriodicString(); diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index ae2e70ad9..d9cee3a4c 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -19,6 +19,7 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.model.Task; +import com.todoroo.astrid.reminders.ReminderService; /** * Data Access layer for {@link Task}-related operations. @@ -34,6 +35,8 @@ public class TaskDao extends GenericDao { @Autowired Database database; + ReminderService reminderService = new ReminderService(); + public TaskDao() { super(Task.class); DependencyInjectionService.getInstance().inject(this); @@ -192,18 +195,91 @@ public class TaskDao extends GenericDao { * @param duringSync whether this save occurs as part of a sync */ private void afterSave(Task task, ContentValues values, boolean duringSync) { + if(values.containsKey(Task.COMPLETION_DATE.name) && task.isCompleted()) + afterComplete(task, values, duringSync); + else + reminderService.scheduleAlarm(task); + if(duringSync) return; - // if task was completed, fire task completed notification - if(values.containsKey(Task.COMPLETION_DATE.name) && - values.getAsInteger(Task.COMPLETION_DATE.name) > 0 && !duringSync) { + // due date was updated, update calendar event + /*if((values.containsKey(AbstractTaskModel.DEFINITE_DUE_DATE) || + values.containsKey(AbstractTaskModel.PREFERRED_DUE_DATE)) && + !values.containsKey(AbstractTaskModel.CALENDAR_URI)) { + try { + Cursor cursor = fetchTaskCursor(task.getTaskIdentifier(), + new String[] { AbstractTaskModel.CALENDAR_URI }); + cursor.moveToFirst(); + String uriAsString = cursor.getString(0); + cursor.close(); + if(uriAsString != null && uriAsString.length() > 0) { + ContentResolver cr = context.getContentResolver(); + Uri uri = Uri.parse(uriAsString); + + Integer estimated = null; + if(values.containsKey(AbstractTaskModel.ESTIMATED_SECONDS)) + estimated = values.getAsInteger(AbstractTaskModel.ESTIMATED_SECONDS); + else { // read from event + Cursor event = cr.query(uri, new String[] {"dtstart", "dtend"}, + null, null, null); + event.moveToFirst(); + estimated = (event.getInt(1) - event.getInt(0))/1000; + } + + // create new start and end date for this event + ContentValues newValues = new ContentValues(); + TaskEditActivity.createCalendarStartEndTimes(task.getPreferredDueDate(), + task.getDefiniteDueDate(), estimated, newValues); TODO + cr.update(uri, newValues, null, null); + } + } catch (Exception e) { + // ignore calendar event - event could be deleted or whatever + Log.e("astrid", "Error moving calendar event", e); + } + }*/ + } + /** + * Called after the task was just completed + * + * @param task + * @param values + * @param duringSync + */ + private void afterComplete(Task task, ContentValues values, boolean duringSync) { + /*Cursor cursor = fetchTaskCursor(task.getTaskIdentifier(), + TaskModelForHandlers.FIELD_LIST); + TaskModelForHandlers model = new TaskModelForHandlers(cursor, values); + + // handle repeat + RepeatInfo repeatInfo = model.getRepeat(); + if(repeatInfo != null) { + model.repeatTaskBy(context, this, repeatInfo); + database.update(tasksTable, values, KEY_ROWID + "=" + + task.getTaskIdentifier().getId(), null); + } + + // handle sync-on-complete + if((model.getFlags() & TaskModelForHandlers.FLAG_SYNC_ON_COMPLETE) > 0 && + !duringSync) { + Synchronizer synchronizer = new Synchronizer(model.getTaskIdentifier()); + synchronizer.synchronize(context, new SynchronizerListener() { + public void onSynchronizerFinished(int numServicesSynced) { + TaskListSubActivity.shouldRefreshTaskList = true; + } + }); + } + + cursor.close(); + cleanupTask(task.getTaskIdentifier(), repeatInfo != null);*/ + + // send broadcast + if(!duringSync) { Context context = ContextManager.getContext(); Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_COMPLETED); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId()); context.sendOrderedBroadcast(broadcastIntent, null); - } } diff --git a/astrid/translation-notes b/astrid/translation-notes index 24ec537c8..4b81f330d 100644 --- a/astrid/translation-notes +++ b/astrid/translation-notes @@ -1,3 +1,11 @@ +reminders + + Absolute Deadline! + Goal Deadline! + Working on: + + You have $NUM tagged $TAG! + task edit