Apply default reminder settings for producteev and gtasks sync

pull/14/head
Tim Su 14 years ago
parent a0e41f42dc
commit db415b19c7

@ -30,6 +30,7 @@ import com.todoroo.astrid.actfm.ActFmPreferences;
import com.todoroo.astrid.actfm.sync.ActFmSyncService.JsonHelper; import com.todoroo.astrid.actfm.sync.ActFmSyncService.JsonHelper;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.notes.NoteMetadata; import com.todoroo.astrid.notes.NoteMetadata;
@ -223,6 +224,7 @@ public class ActFmSyncProvider extends SyncProvider<ActFmTaskContainer> {
* @throws JSONException */ * @throws JSONException */
private ActFmTaskContainer parseRemoteTask(JSONObject remoteTask) throws JSONException { private ActFmTaskContainer parseRemoteTask(JSONObject remoteTask) throws JSONException {
Task task = new Task(); Task task = new Task();
TaskDao.setDefaultReminders(task);
ArrayList<Metadata> metadata = new ArrayList<Metadata>(); ArrayList<Metadata> metadata = new ArrayList<Metadata>();
JsonHelper.taskFromJson(remoteTask, task, metadata); JsonHelper.taskFromJson(remoteTask, task, metadata);

@ -32,6 +32,7 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -371,6 +372,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
// update reminder flags for incoming remote tasks to prevent annoying // update reminder flags for incoming remote tasks to prevent annoying
if(container.task.hasDueDate() && container.task.getValue(Task.DUE_DATE) < DateUtilities.now()) if(container.task.hasDueDate() && container.task.getValue(Task.DUE_DATE) < DateUtilities.now())
container.task.setFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE, false); container.task.setFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE, false);
gtasksMetadataService.findLocalMatch(container); gtasksMetadataService.findLocalMatch(container);
remoteTasks.add(container); remoteTasks.add(container);
} }
@ -477,10 +479,12 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
} }
} }
/** Create a task container for the given RtmTaskSeries /** Create a task container for the given remote task
* @throws JSONException */ * @throws JSONException */
private GtasksTaskContainer parseRemoteTask(GoogleTaskTask remoteTask) { private GtasksTaskContainer parseRemoteTask(GoogleTaskTask remoteTask) {
Task task = new Task(); Task task = new Task();
TaskDao.setDefaultReminders(task);
ArrayList<Metadata> metadata = new ArrayList<Metadata>(); ArrayList<Metadata> metadata = new ArrayList<Metadata>();
task.setValue(Task.TITLE, remoteTask.getName()); task.setValue(Task.TITLE, remoteTask.getName());

@ -35,6 +35,7 @@ import com.todoroo.astrid.activity.ShortcutActivity;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -348,6 +349,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
* @throws JSONException */ * @throws JSONException */
private ProducteevTaskContainer parseRemoteTask(JSONObject remoteTask) throws JSONException { private ProducteevTaskContainer parseRemoteTask(JSONObject remoteTask) throws JSONException {
Task task = new Task(); Task task = new Task();
TaskDao.setDefaultReminders(task);
ArrayList<Metadata> metadata = new ArrayList<Metadata>(); ArrayList<Metadata> metadata = new ArrayList<Metadata>();
if(remoteTask.has("task")) if(remoteTask.has("task"))

@ -196,6 +196,21 @@ public class TaskDao extends DatabaseDao<Task> {
Task.HIDE_UNTIL_NONE); Task.HIDE_UNTIL_NONE);
item.setValue(Task.HIDE_UNTIL, item.createHideUntil(setting, 0)); 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)) { if(!item.containsValue(Task.REMINDER_PERIOD)) {
item.setValue(Task.REMINDER_PERIOD, DateUtilities.ONE_HOUR * item.setValue(Task.REMINDER_PERIOD, DateUtilities.ONE_HOUR *
Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours, Preferences.getIntegerFromString(R.string.p_rmd_default_random_hours,
@ -206,12 +221,6 @@ public class TaskDao extends DatabaseDao<Task> {
Preferences.getIntegerFromString(R.string.p_default_reminders_key, Preferences.getIntegerFromString(R.string.p_default_reminders_key,
Task.NOTIFY_AT_DEADLINE | Task.NOTIFY_AFTER_DEADLINE)); 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 @Override

Loading…
Cancel
Save