From c103617aec42ed339d67b91043a622bf70f8c084 Mon Sep 17 00:00:00 2001 From: Allan Crooks Date: Mon, 26 May 2014 19:27:08 +0100 Subject: [PATCH] Sync tasks with GTask list but no GTask ID. When synchronising up a Google Tasks list, find any tasks which were not successfully pushed on create, and force them to exist remotely. Otherwise, we will wipe them locally as we assume the user has moved or deleted the task remotely. --- .../gtasks/sync/GtasksSyncV2Provider.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java index f744e5acf..debe9f18a 100644 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java +++ b/astrid/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java @@ -168,8 +168,12 @@ public class GtasksSyncV2Provider extends SyncV2Provider { TodorooCursor queued = taskService.query(Query.select(Task.PROPERTIES). join(Join.left(Metadata.TABLE, Criterion.and(MetadataCriteria.withKey(GtasksMetadata.METADATA_KEY), Task.ID.eq(Metadata.TASK)))).where( Criterion.or(Task.MODIFICATION_DATE.gt(GtasksMetadata.LAST_SYNC), - Criterion.and(Task.USER_ID.neq(Task.USER_ID_SELF), GtasksMetadata.ID.isNotNull()), + Criterion.and(Task.USER_ID.neq(Task.USER_ID_SELF), GtasksMetadata.ID.isNotNull()), // XXX: Shouldn't this neq("")? Metadata.KEY.isNull()))); + pushTasks(queued, invoker, callback); + } + + private synchronized void pushTasks(TodorooCursor queued, GtasksInvoker invoker, SyncResultCallback callback) { callback.incrementMax(queued.getCount() * 10); try { Task task = new Task(); @@ -248,6 +252,21 @@ public class GtasksSyncV2Provider extends SyncV2Provider { } else { lastSyncDate = 0; } + + /** + * Find tasks which have been associated with the list internally, but have not yet been + * pushed to Google Tasks (and so haven't yet got a valid ID). + */ + Criterion not_pushed_tasks = Criterion.and( + Metadata.KEY.eq(GtasksMetadata.METADATA_KEY), + GtasksMetadata.LIST_ID.eq(listId), + GtasksMetadata.ID.eq("") + ); + TodorooCursor qs = taskService.query(Query.select(Task.PROPERTIES). + join(Join.left(Metadata.TABLE, Criterion.and(MetadataCriteria.withKey(GtasksMetadata.METADATA_KEY), Task.ID.eq(Metadata.TASK)))).where(not_pushed_tasks) + ); + pushTasks(qs, invoker, callback); + boolean includeDeletedAndHidden = lastSyncDate != 0; try { Tasks taskList = invoker.getAllGtasksFromListId(listId, includeDeletedAndHidden,