|
|
|
@ -14,6 +14,7 @@ import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import com.timsu.astrid.C2DMReceiver;
|
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
|
import com.todoroo.andlib.data.AbstractModel;
|
|
|
|
|
import com.todoroo.andlib.data.TodorooCursor;
|
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
|
import com.todoroo.andlib.service.ContextManager;
|
|
|
|
@ -21,13 +22,15 @@ import com.todoroo.andlib.sql.Criterion;
|
|
|
|
|
import com.todoroo.andlib.sql.Join;
|
|
|
|
|
import com.todoroo.andlib.sql.Query;
|
|
|
|
|
import com.todoroo.andlib.utility.Preferences;
|
|
|
|
|
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
|
|
|
|
|
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
|
|
|
|
import com.todoroo.astrid.data.Metadata;
|
|
|
|
|
import com.todoroo.astrid.data.RemoteModel;
|
|
|
|
|
import com.todoroo.astrid.data.TagData;
|
|
|
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
|
import com.todoroo.astrid.data.User;
|
|
|
|
|
import com.todoroo.astrid.files.FileMetadata;
|
|
|
|
|
import com.todoroo.astrid.service.AstridDependencyInjector;
|
|
|
|
|
import com.todoroo.astrid.service.MetadataService;
|
|
|
|
|
import com.todoroo.astrid.service.TagDataService;
|
|
|
|
|
import com.todoroo.astrid.service.TaskService;
|
|
|
|
|
import com.todoroo.astrid.sync.SyncResultCallback;
|
|
|
|
@ -50,6 +53,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
|
|
|
|
|
|
|
|
|
|
@Autowired TagDataService tagDataService;
|
|
|
|
|
|
|
|
|
|
@Autowired MetadataService metadataService;
|
|
|
|
|
|
|
|
|
|
private final PushQueuedArgs<Task> taskPusher = new PushQueuedArgs<Task>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Task getRemoteModelInstance(TodorooCursor<Task> cursor) {
|
|
|
|
@ -80,6 +85,24 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private final PushQueuedArgs<Metadata> filesPusher = new PushQueuedArgs<Metadata>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void pushRemoteModel(Metadata model) {
|
|
|
|
|
long taskId = model.getValue(Metadata.TASK);
|
|
|
|
|
Task localTask = taskService.fetchById(taskId, Task.REMOTE_ID);
|
|
|
|
|
long remoteTaskId = localTask.getValue(Task.REMOTE_ID);
|
|
|
|
|
if (remoteTaskId <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
actFmSyncService.pushAttachment(remoteTaskId, model);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public Metadata getRemoteModelInstance(TodorooCursor<Metadata> cursor) {
|
|
|
|
|
return new Metadata(cursor);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
AstridDependencyInjector.initialize();
|
|
|
|
|
}
|
|
|
|
@ -228,12 +251,12 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static interface PushQueuedArgs<T extends RemoteModel> {
|
|
|
|
|
private static interface PushQueuedArgs<T extends AbstractModel> {
|
|
|
|
|
public T getRemoteModelInstance(TodorooCursor<T> cursor);
|
|
|
|
|
public void pushRemoteModel(T model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <T extends RemoteModel> void pushQueued(final SyncResultCallback callback, final AtomicInteger finisher,
|
|
|
|
|
private <T extends AbstractModel> void pushQueued(final SyncResultCallback callback, final AtomicInteger finisher,
|
|
|
|
|
TodorooCursor<T> cursor, boolean awaitTermination, final PushQueuedArgs<T> pusher) {
|
|
|
|
|
try {
|
|
|
|
|
callback.incrementMax(cursor.getCount() * 20);
|
|
|
|
@ -278,7 +301,13 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
|
|
|
|
|
Criterion.and(Task.REMOTE_ID.isNotNull(),
|
|
|
|
|
Task.MODIFICATION_DATE.gt(Task.LAST_SYNC)))));
|
|
|
|
|
|
|
|
|
|
pushQueued(callback, finisher, taskCursor, false, taskPusher);
|
|
|
|
|
TodorooCursor<Metadata> filesCursor = metadataService.query(Query.select(Metadata.PROPERTIES)
|
|
|
|
|
.where(Criterion.and(
|
|
|
|
|
MetadataCriteria.withKey(FileMetadata.METADATA_KEY),
|
|
|
|
|
FileMetadata.REMOTE_ID.eq(0))));
|
|
|
|
|
|
|
|
|
|
pushQueued(callback, finisher, taskCursor, true, taskPusher);
|
|
|
|
|
pushQueued(callback, finisher, filesCursor, false, filesPusher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void pushQueuedTags(final SyncResultCallback callback,
|
|
|
|
|