Fixed issues with producteev and synchronizing created/deleted tasks

pull/14/head
Tim Su 14 years ago
parent bfbd493fe9
commit f765dd17e0

@ -15,8 +15,8 @@ import android.content.Context;
import android.widget.Toast; import android.widget.Toast;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.service.ExceptionService;
@ -72,9 +72,11 @@ public abstract class SyncProvider<TYPE extends TaskContainer> {
/** /**
* Create a task on the remote server. * Create a task on the remote server.
* *
* @return task to create * @param task
* task to create
* @return task created on remote server
*/ */
abstract protected void create(TYPE task) throws IOException; abstract protected TYPE create(TYPE task) throws IOException;
/** /**
* Push variables from given task to the remote server. * Push variables from given task to the remote server.
@ -231,10 +233,6 @@ public abstract class SyncProvider<TYPE extends TaskContainer> {
remote.task.setId(local.task.getId()); remote.task.setId(local.task.getId());
data.remoteUpdated.set(remoteIndex, remote); data.remoteUpdated.set(remoteIndex, remote);
// if remote is deleted, undelete it, since we just created
if(remote.task.isDeleted())
remote.task.setValue(Task.DELETION_DATE, 0L);
} else { } else {
create(local); create(local);
} }

@ -51,6 +51,7 @@ import com.todoroo.astrid.utility.Preferences;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer> { public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer> {
private static final long TASK_ID_UNSYNCED = 1L;
private ProducteevDataService dataService = null; private ProducteevDataService dataService = null;
private ProducteevInvoker invoker = null; private ProducteevInvoker invoker = null;
private final ProducteevUtilities preferences = ProducteevUtilities.INSTANCE; private final ProducteevUtilities preferences = ProducteevUtilities.INSTANCE;
@ -299,7 +300,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@Override @Override
protected void create(ProducteevTaskContainer local) throws IOException { protected ProducteevTaskContainer create(ProducteevTaskContainer local) throws IOException {
Task localTask = local.task; Task localTask = local.task;
long dashboard = ProducteevUtilities.INSTANCE.getDefaultDashboard(); long dashboard = ProducteevUtilities.INSTANCE.getDefaultDashboard();
if(local.pdvTask.containsNonNullValue(ProducteevTask.DASHBOARD_ID)) if(local.pdvTask.containsNonNullValue(ProducteevTask.DASHBOARD_ID))
@ -307,8 +308,8 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
if(dashboard == ProducteevUtilities.DASHBOARD_NO_SYNC) { if(dashboard == ProducteevUtilities.DASHBOARD_NO_SYNC) {
// set a bogus task id, then return without creating // set a bogus task id, then return without creating
local.pdvTask.setValue(ProducteevTask.ID, 1L); local.pdvTask.setValue(ProducteevTask.ID, TASK_ID_UNSYNCED);
return; return local;
} }
JSONObject response = invoker.tasksCreate(localTask.getValue(Task.TITLE), JSONObject response = invoker.tasksCreate(localTask.getValue(Task.TITLE),
@ -322,6 +323,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
} }
transferIdentifiers(newRemoteTask, local); transferIdentifiers(newRemoteTask, local);
push(local, newRemoteTask); push(local, newRemoteTask);
return newRemoteTask;
} }
/** Create a task container for the given RtmTaskSeries /** Create a task container for the given RtmTaskSeries
@ -403,14 +405,22 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
if(shouldTransmit(local, Task.DELETION_DATE, remote)) { if(shouldTransmit(local, Task.DELETION_DATE, remote)) {
if(local.task.getValue(Task.DELETION_DATE) > 0) if(local.task.getValue(Task.DELETION_DATE) > 0)
invoker.tasksDelete(idTask); invoker.tasksDelete(idTask);
else else {
create(local); // if we create, we transfer identifiers to old remote
// in case it is used by caller for other purposes
ProducteevTaskContainer newRemote = create(local);
transferIdentifiers(newRemote, remote);
remote = newRemote;
}
} }
// dashboard // dashboard
if(remote != null && idDashboard != remote.pdvTask.getValue(ProducteevTask.DASHBOARD_ID)) { if(remote != null && idDashboard != remote.pdvTask.getValue(ProducteevTask.DASHBOARD_ID)) {
invoker.tasksSetWorkspace(idTask, idDashboard); invoker.tasksSetWorkspace(idTask, idDashboard);
remote = pull(local); remote = pull(local);
} else if(remote == null && idTask == TASK_ID_UNSYNCED) {
// was un-synced, create remote
remote = create(local);
} }
// core properties // core properties

@ -349,7 +349,7 @@ public class RTMSyncProvider extends SyncProvider<RTMTaskContainer> {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@Override @Override
protected void create(RTMTaskContainer task) throws IOException { protected RTMTaskContainer create(RTMTaskContainer task) throws IOException {
String listId = null; String listId = null;
if(task.listId > 0) if(task.listId > 0)
listId = Long.toString(task.listId); listId = Long.toString(task.listId);
@ -358,6 +358,7 @@ public class RTMSyncProvider extends SyncProvider<RTMTaskContainer> {
RTMTaskContainer newRemoteTask = parseRemoteTask(rtmTask); RTMTaskContainer newRemoteTask = parseRemoteTask(rtmTask);
transferIdentifiers(newRemoteTask, task); transferIdentifiers(newRemoteTask, task);
push(task, newRemoteTask); push(task, newRemoteTask);
return newRemoteTask;
} }
/** /**

Loading…
Cancel
Save