From db415b19c7239716e8b06d5b9543460476ab8057 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Wed, 22 Jun 2011 00:33:42 -0700 Subject: [PATCH] Apply default reminder settings for producteev and gtasks sync --- .../astrid/actfm/sync/ActFmSyncProvider.java | 2 ++ .../gtasks/sync/GtasksSyncProvider.java | 6 +++++- .../sync/ProducteevSyncProvider.java | 2 ++ .../src/com/todoroo/astrid/dao/TaskDao.java | 21 +++++++++++++------ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java index 2536144a5..61caf849c 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java @@ -30,6 +30,7 @@ import com.todoroo.astrid.actfm.ActFmPreferences; import com.todoroo.astrid.actfm.sync.ActFmSyncService.JsonHelper; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.core.PluginServices; +import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.notes.NoteMetadata; @@ -223,6 +224,7 @@ public class ActFmSyncProvider extends SyncProvider { * @throws JSONException */ private ActFmTaskContainer parseRemoteTask(JSONObject remoteTask) throws JSONException { Task task = new Task(); + TaskDao.setDefaultReminders(task); ArrayList metadata = new ArrayList(); JsonHelper.taskFromJson(remoteTask, task, metadata); diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java index 8e39f8a1f..f4f2362bb 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncProvider.java @@ -32,6 +32,7 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.core.PluginServices; +import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.Task; @@ -371,6 +372,7 @@ public class GtasksSyncProvider extends SyncProvider { // update reminder flags for incoming remote tasks to prevent annoying if(container.task.hasDueDate() && container.task.getValue(Task.DUE_DATE) < DateUtilities.now()) container.task.setFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE, false); + gtasksMetadataService.findLocalMatch(container); remoteTasks.add(container); } @@ -477,10 +479,12 @@ public class GtasksSyncProvider extends SyncProvider { } } - /** Create a task container for the given RtmTaskSeries + /** Create a task container for the given remote task * @throws JSONException */ private GtasksTaskContainer parseRemoteTask(GoogleTaskTask remoteTask) { Task task = new Task(); + TaskDao.setDefaultReminders(task); + ArrayList metadata = new ArrayList(); task.setValue(Task.TITLE, remoteTask.getName()); diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java index 5a4a1aa54..75f9553dd 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java @@ -35,6 +35,7 @@ import com.todoroo.astrid.activity.ShortcutActivity; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.core.PluginServices; +import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.Task; @@ -348,6 +349,7 @@ public class ProducteevSyncProvider extends SyncProvider metadata = new ArrayList(); if(remoteTask.has("task")) diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index 0bfbee69c..fa3d43083 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -196,6 +196,21 @@ public class TaskDao extends DatabaseDao { Task.HIDE_UNTIL_NONE); item.setValue(Task.HIDE_UNTIL, item.createHideUntil(setting, 0)); } + + setDefaultReminders(item); + + ContentValues values = item.getSetValues(); + boolean result = super.createNew(item); + if(result) + afterSave(item, values); + return result; + } + + /** + * Sets default reminders for the given task if reminders are not set + * @param item + */ + public static void setDefaultReminders(Task item) { if(!item.containsValue(Task.REMINDER_PERIOD)) { item.setValue(Task.REMINDER_PERIOD, DateUtilities.ONE_HOUR * Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours, @@ -206,12 +221,6 @@ public class TaskDao extends DatabaseDao { Preferences.getIntegerFromString(R.string.p_default_reminders_key, Task.NOTIFY_AT_DEADLINE | Task.NOTIFY_AFTER_DEADLINE)); } - - ContentValues values = item.getSetValues(); - boolean result = super.createNew(item); - if(result) - afterSave(item, values); - return result; } @Override