Fixed several bugs/missing pieces that were preventing task attachments from syncing

pull/14/head
Sam Bosley 12 years ago
parent 4f0fa98253
commit 49507146c5

@ -16,6 +16,7 @@ import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table; import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
/** /**
@ -32,6 +33,9 @@ public final class TaskAttachment extends RemoteModel {
/** table for this model */ /** table for this model */
public static final Table TABLE = new Table("task_attachments", TaskAttachment.class); public static final Table TABLE = new Table("task_attachments", TaskAttachment.class);
/** model class for entries in the outstanding table */
public static final Class<? extends OutstandingEntry<TaskAttachment>> OUTSTANDING_MODEL = TaskAttachmentOutstanding.class;
/** content uri for this model */ /** content uri for this model */
public static final Uri CONTENT_URI = Uri.parse("content://" + AstridApiConstants.API_PACKAGE + "/" + public static final Uri CONTENT_URI = Uri.parse("content://" + AstridApiConstants.API_PACKAGE + "/" +
TABLE.name); TABLE.name);
@ -147,6 +151,7 @@ public final class TaskAttachment extends RemoteModel {
attachment.setValue(USER_UUID, Task.USER_ID_SELF); attachment.setValue(USER_UUID, Task.USER_ID_SELF);
attachment.setValue(FILE_PATH, filePath); attachment.setValue(FILE_PATH, filePath);
attachment.setValue(CONTENT_TYPE, fileType); attachment.setValue(CONTENT_TYPE, fileType);
attachment.setValue(CREATED_AT, DateUtilities.now());
attachment.setValue(DELETED_AT, 0L); attachment.setValue(DELETED_AT, 0L);
return attachment; return attachment;
} }

@ -32,6 +32,7 @@ import com.todoroo.astrid.dao.OutstandingEntryDao;
import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.dao.RemoteModelDao;
import com.todoroo.astrid.dao.TagDataDao; import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TagOutstandingDao; import com.todoroo.astrid.dao.TagOutstandingDao;
import com.todoroo.astrid.dao.TaskAttachmentDao;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskOutstandingDao; import com.todoroo.astrid.dao.TaskOutstandingDao;
import com.todoroo.astrid.dao.UserActivityDao; import com.todoroo.astrid.dao.UserActivityDao;
@ -41,6 +42,7 @@ import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagOutstanding; import com.todoroo.astrid.data.TagOutstanding;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskAttachment;
import com.todoroo.astrid.data.TaskOutstanding; import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivity;
@ -87,7 +89,8 @@ public class ActFmSyncThread {
public static enum ModelType { public static enum ModelType {
TYPE_TASK, TYPE_TASK,
TYPE_TAG, TYPE_TAG,
TYPE_ACTIVITY TYPE_ACTIVITY,
TYPE_ATTACHMENT
} }
private static volatile ActFmSyncThread instance; private static volatile ActFmSyncThread instance;
@ -96,14 +99,14 @@ public class ActFmSyncThread {
if (instance == null) { if (instance == null) {
synchronized(ActFmSyncThread.class) { synchronized(ActFmSyncThread.class) {
if (instance == null) { if (instance == null) {
initializeSyncComponents(PluginServices.getTaskDao(), PluginServices.getTagDataDao(), PluginServices.getUserActivityDao()); initializeSyncComponents(PluginServices.getTaskDao(), PluginServices.getTagDataDao(), PluginServices.getUserActivityDao(), PluginServices.getTaskAttachmentDao());
} }
} }
} }
return instance; return instance;
} }
public static ActFmSyncThread initializeSyncComponents(TaskDao taskDao, TagDataDao tagDataDao, UserActivityDao userActivityDao) { public static ActFmSyncThread initializeSyncComponents(TaskDao taskDao, TagDataDao tagDataDao, UserActivityDao userActivityDao, TaskAttachmentDao taskAttachmentDao) {
if (instance == null) { if (instance == null) {
synchronized(ActFmSyncThread.class) { synchronized(ActFmSyncThread.class) {
if (instance == null) { if (instance == null) {
@ -115,6 +118,7 @@ public class ActFmSyncThread {
taskDao.addListener(new SyncDatabaseListener<Task>(instance, ModelType.TYPE_TASK)); taskDao.addListener(new SyncDatabaseListener<Task>(instance, ModelType.TYPE_TASK));
tagDataDao.addListener(new SyncDatabaseListener<TagData>(instance, ModelType.TYPE_TAG)); tagDataDao.addListener(new SyncDatabaseListener<TagData>(instance, ModelType.TYPE_TAG));
userActivityDao.addListener(new SyncDatabaseListener<UserActivity>(instance, ModelType.TYPE_ACTIVITY)); userActivityDao.addListener(new SyncDatabaseListener<UserActivity>(instance, ModelType.TYPE_ACTIVITY));
taskAttachmentDao.addListener(new SyncDatabaseListener<TaskAttachment>(instance, ModelType.TYPE_ATTACHMENT));
instance.startSyncThread(); instance.startSyncThread();
} }

@ -29,6 +29,8 @@ import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagOutstanding; import com.todoroo.astrid.data.TagOutstanding;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskAttachment;
import com.todoroo.astrid.data.TaskAttachmentOutstanding;
import com.todoroo.astrid.data.TaskOutstanding; import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.data.UserActivityOutstanding; import com.todoroo.astrid.data.UserActivityOutstanding;
@ -55,6 +57,9 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
case TYPE_ACTIVITY: case TYPE_ACTIVITY:
return new ChangesHappened<UserActivity, UserActivityOutstanding>(id, UserActivity.class, return new ChangesHappened<UserActivity, UserActivityOutstanding>(id, UserActivity.class,
PluginServices.getUserActivityDao(), PluginServices.getUserActivityOutstandingDao()); PluginServices.getUserActivityDao(), PluginServices.getUserActivityOutstandingDao());
case TYPE_ATTACHMENT:
return new ChangesHappened<TaskAttachment, TaskAttachmentOutstanding>(id, TaskAttachment.class,
PluginServices.getTaskAttachmentDao(), PluginServices.getTaskAttachmentOutstandingDao());
default: default:
return null; return null;
} }

@ -269,7 +269,7 @@ public class NameMaps {
TASK_ATTACHMENT_PROPERTIES_EXCLUDED = new HashSet<String>(); TASK_ATTACHMENT_PROPERTIES_EXCLUDED = new HashSet<String>();
putTaskAttachmentPropertyToServerName(TaskAttachment.UUID, "uuid", false); putTaskAttachmentPropertyToServerName(TaskAttachment.UUID, "uuid", false);
putTaskAttachmentPropertyToServerName(TaskAttachment.USER_UUID, "user_id", true); putTaskAttachmentPropertyToServerName(TaskAttachment.USER_UUID, "user_id", false);
putTaskAttachmentPropertyToServerName(TaskAttachment.TASK_UUID, "task_id", true); putTaskAttachmentPropertyToServerName(TaskAttachment.TASK_UUID, "task_id", true);
putTaskAttachmentPropertyToServerName(TaskAttachment.NAME, "name", false); putTaskAttachmentPropertyToServerName(TaskAttachment.NAME, "name", false);
putTaskAttachmentPropertyToServerName(TaskAttachment.URL, "url", false); putTaskAttachmentPropertyToServerName(TaskAttachment.URL, "url", false);

@ -57,12 +57,13 @@ public class TaskAttachmentDao extends RemoteModelDao<TaskAttachment> {
JSONObject newFileHash = new JSONObject(); JSONObject newFileHash = new JSONObject();
newFileHash.put("name", modelSetValues.getAsString(TaskAttachment.NAME.name)); //$NON-NLS-1$ newFileHash.put("name", modelSetValues.getAsString(TaskAttachment.NAME.name)); //$NON-NLS-1$
newFileHash.put("type", modelSetValues.getAsString(TaskAttachment.CONTENT_TYPE.name)); //$NON-NLS-1$ newFileHash.put("type", modelSetValues.getAsString(TaskAttachment.CONTENT_TYPE.name)); //$NON-NLS-1$
newFileHash.put("path", modelSetValues.getAsString(path)); //$NON-NLS-1$ newFileHash.put("path", path); //$NON-NLS-1$
m.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, modelId); m.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, modelId);
m.setValue(OutstandingEntry.COLUMN_STRING_PROPERTY, NameMaps.ATTACHMENT_ADDED_COLUMN); m.setValue(OutstandingEntry.COLUMN_STRING_PROPERTY, NameMaps.ATTACHMENT_ADDED_COLUMN);
m.setValue(OutstandingEntry.VALUE_STRING_PROPERTY, newFileHash.toString()); m.setValue(OutstandingEntry.VALUE_STRING_PROPERTY, newFileHash.toString());
m.setValue(OutstandingEntry.CREATED_AT_PROPERTY, DateUtilities.now()); m.setValue(OutstandingEntry.CREATED_AT_PROPERTY, DateUtilities.now());
database.insert(outstandingTable.name, null, m.getSetValues());
} catch (JSONException e) { } catch (JSONException e) {
return -1; return -1;
} }

@ -21,6 +21,8 @@ import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.TagDataDao; import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TagMetadataDao; import com.todoroo.astrid.dao.TagMetadataDao;
import com.todoroo.astrid.dao.TagOutstandingDao; import com.todoroo.astrid.dao.TagOutstandingDao;
import com.todoroo.astrid.dao.TaskAttachmentDao;
import com.todoroo.astrid.dao.TaskAttachmentOutstandingDao;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskOutstandingDao; import com.todoroo.astrid.dao.TaskOutstandingDao;
import com.todoroo.astrid.dao.UpdateDao; import com.todoroo.astrid.dao.UpdateDao;
@ -83,6 +85,8 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
injectables.put("tagOutstandingDao", TagOutstandingDao.class); injectables.put("tagOutstandingDao", TagOutstandingDao.class);
injectables.put("userActivityOutstandingDao", UserActivityOutstandingDao.class); injectables.put("userActivityOutstandingDao", UserActivityOutstandingDao.class);
injectables.put("historyDao", HistoryDao.class); injectables.put("historyDao", HistoryDao.class);
injectables.put("taskAttachmentDao", TaskAttachmentDao.class);
injectables.put("taskAttachmentOutstandingDao", TaskAttachmentOutstandingDao.class);
// com.todoroo.astrid.service // com.todoroo.astrid.service
injectables.put("taskService", TaskService.class); injectables.put("taskService", TaskService.class);

@ -52,6 +52,7 @@ import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TagDataDao; import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TaskAttachmentDao;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.UserActivityDao; import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
@ -106,6 +107,8 @@ public class StartupService {
@Autowired UserActivityDao userActivityDao; @Autowired UserActivityDao userActivityDao;
@Autowired TaskAttachmentDao taskAttachmentDao;
@Autowired MetadataService metadataService; @Autowired MetadataService metadataService;
@Autowired Database database; @Autowired Database database;
@ -221,7 +224,7 @@ public class StartupService {
abTestInvoker.reportAcquisition(); abTestInvoker.reportAcquisition();
initializeDatabaseListeners(); initializeDatabaseListeners();
ActFmSyncThread.initializeSyncComponents(taskDao, tagDataDao, userActivityDao); ActFmSyncThread.initializeSyncComponents(taskDao, tagDataDao, userActivityDao, taskAttachmentDao);
// perform startup activities in a background thread // perform startup activities in a background thread
new Thread(new Runnable() { new Thread(new Runnable() {

Loading…
Cancel
Save