diff --git a/api/src/com/todoroo/astrid/data/TagData.java b/api/src/com/todoroo/astrid/data/TagData.java index 5ccd0764d..e03d806e6 100644 --- a/api/src/com/todoroo/astrid/data/TagData.java +++ b/api/src/com/todoroo/astrid/data/TagData.java @@ -121,6 +121,18 @@ public final class TagData extends RemoteModel { public static final LongProperty PUSHED_AT = new LongProperty( TABLE, PUSHED_AT_PROPERTY_NAME, Property.PROP_FLAG_DATE); + /** Tasks pushed at date */ + public static final LongProperty TASKS_PUSHED_AT = new LongProperty( + TABLE, "tasks_pushed_at", Property.PROP_FLAG_DATE); + + /** Metadata pushed at date */ + public static final LongProperty METADATA_PUSHED_AT = new LongProperty( + TABLE, "metadata_pushed_at", Property.PROP_FLAG_DATE); + + /** User activities pushed at date */ + public static final LongProperty USER_ACTIVITIES_PUSHED_AT = new LongProperty( + TABLE, "activities_pushed_at", Property.PROP_FLAG_DATE); + /** Tag ordering */ public static final StringProperty TAG_ORDERING = new StringProperty( TABLE, "tagOrdering"); @@ -169,6 +181,9 @@ public final class TagData extends RemoteModel { defaultValues.put(TASK_COUNT.name, 0); defaultValues.put(TAG_DESCRIPTION.name, ""); defaultValues.put(PUSHED_AT.name, 0L); + defaultValues.put(TASKS_PUSHED_AT.name, 0L); + defaultValues.put(METADATA_PUSHED_AT.name, 0L); + defaultValues.put(USER_ACTIVITIES_PUSHED_AT.name, 0L); defaultValues.put(TAG_ORDERING.name, "[]"); } diff --git a/api/src/com/todoroo/astrid/data/Task.java b/api/src/com/todoroo/astrid/data/Task.java index e1c4e79c7..ab4217603 100644 --- a/api/src/com/todoroo/astrid/data/Task.java +++ b/api/src/com/todoroo/astrid/data/Task.java @@ -178,6 +178,14 @@ public final class Task extends RemoteModel { public static final LongProperty PUSHED_AT = new LongProperty( TABLE, PUSHED_AT_PROPERTY_NAME, Property.PROP_FLAG_DATE); + /** Attachments pushed at date */ + public static final LongProperty ATTACHMENTS_PUSHED_AT = new LongProperty( + TABLE, "attachments_pushed_at", Property.PROP_FLAG_DATE); + + /** User activities pushed at date */ + public static final LongProperty USER_ACTIVITIES_PUSHED_AT = new LongProperty( + TABLE, "activities_pushed_at", Property.PROP_FLAG_DATE); + /** History fetch time */ public static final LongProperty HISTORY_FETCH_DATE = new LongProperty( TABLE, "historyFetch"); @@ -311,6 +319,8 @@ public final class Task extends RemoteModel { defaultValues.put(USER.name, ""); // defaultValues.put(USER_EMAIL.name, ""); defaultValues.put(PUSHED_AT.name, 0L); + defaultValues.put(ATTACHMENTS_PUSHED_AT.name, 0L); + defaultValues.put(USER_ACTIVITIES_PUSHED_AT.name, 0L); } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java index dcee4fbb9..15ccbc468 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java @@ -128,7 +128,7 @@ public class TagCommentsFragment extends CommentsFragment { @Override protected void performFetch(boolean manual, Runnable done) { if (tagData != null) { - ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), done); + ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), done); new FetchHistory(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, done).execute(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index 78601e591..98c23bf5a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -66,6 +66,7 @@ import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagMetadata; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskListMetadata; import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.helper.AsyncImageView; @@ -355,7 +356,10 @@ public class TagViewFragment extends TaskListFragment { }; ActFmSyncThread.getInstance().repopulateQueueFromOutstandingTables(); + ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(Task.class, null, tagData.getValue(TagData.TASKS_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback); + ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback); + ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(TaskListMetadata.class, null, tagData.getValue(TagData.METADATA_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback); new FetchHistory(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, null).execute(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java index 87f5f667e..0c4a49f81 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TaskCommentsFragment.java @@ -81,7 +81,7 @@ public class TaskCommentsFragment extends CommentsFragment { @Override protected void performFetch(boolean manual, Runnable done) { if (task != null) { - ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), done); + ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), done); new FetchHistory(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), false, done).execute(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java index de2f6203f..4cfb89933 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java @@ -3,12 +3,19 @@ package com.todoroo.astrid.actfm.sync.messages; import org.json.JSONException; import org.json.JSONObject; +import android.util.Log; + import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.data.RemoteModel; public class BriefMe extends ClientToServerMessage { + private static final String ERROR_TAG = "actfm-brief-me"; //$NON-NLS-1$ + + public static final String TASK_ID_KEY = "task_id"; //$NON-NLS-1$ + public static final String TAG_ID_KEY = "tag_id"; //$NON-NLS-1$ + public static BriefMe instantiateBriefMeForClass(Class cls, String pushedAtKey) { long pushedAt = Preferences.getLong(pushedAtKey, 0); return new BriefMe(cls, null, pushedAt); @@ -16,15 +23,31 @@ public class BriefMe extends ClientToServerMessage modelClass, RemoteModelDao modelDao) { super(id, modelClass, modelDao); + this.extraParameters = null; } - public BriefMe(Class modelClass, String uuid, long pushedAt) { + private final Object[] extraParameters; + + public BriefMe(Class modelClass, String uuid, long pushedAt, Object...extraParameters) { super(modelClass, uuid, pushedAt); + this.extraParameters = extraParameters; } @Override protected boolean serializeExtrasToJSON(JSONObject serializeTo) throws JSONException { - // No extras + if (extraParameters != null && extraParameters.length > 0) { + for (int i = 0; i < extraParameters.length - 1; i++) { + try { + String key = (String) extraParameters[i]; + Object value = extraParameters[i + 1]; + serializeTo.put(key, value); + } catch (ClassCastException e) { + Log.e(ERROR_TAG, "ClassCastException serializing BriefMe", e); //$NON-NLS-1$ + } catch (JSONException e) { + Log.e(ERROR_TAG, "JSONException serializing BriefMe", e); //$NON-NLS-1$ + } + } + } return true; } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java index be57f123b..81a827694 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java @@ -9,8 +9,11 @@ import android.util.Log; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; +import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.data.RemoteModel; +import com.todoroo.astrid.data.TagData; +import com.todoroo.astrid.data.Task; @SuppressWarnings("nls") public class NowBriefed extends ServerToClientMessage { @@ -20,12 +23,16 @@ public class NowBriefed extends ServerToClientMessage private final RemoteModelDao dao; private final String table; private final String uuid; + private final String taskId; + private final String tagId; private long pushedAt; public NowBriefed(JSONObject json, RemoteModelDao dao) { super(json); this.table = json.optString("table"); this.uuid = json.optString("uuid"); + this.taskId = json.optString(BriefMe.TASK_ID_KEY); + this.tagId = json.optString(BriefMe.TAG_ID_KEY); this.dao = dao; try { this.pushedAt = DateUtilities.parseIso8601(json.optString("pushed_at")); @@ -38,20 +45,44 @@ public class NowBriefed extends ServerToClientMessage public void processMessage() { if (pushedAt > 0) { if (TextUtils.isEmpty(uuid)) { - String pushedAtKey = null; - if (NameMaps.TABLE_ID_TASKS.equals(table)) - pushedAtKey = NameMaps.PUSHED_AT_TASKS; - else if (NameMaps.TABLE_ID_TAGS.equals(table)) - pushedAtKey = NameMaps.PUSHED_AT_TAGS; - else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table)) - pushedAtKey = NameMaps.PUSHED_AT_ACTIVITY; - else if (NameMaps.TABLE_ID_USERS.equals(table)) - pushedAtKey = NameMaps.PUSHED_AT_USERS; - else if (NameMaps.TABLE_ID_TASK_LIST_METADATA.equals(table)) - pushedAtKey = NameMaps.PUSHED_AT_TASK_LIST_METADATA; - - if (pushedAtKey != null) - Preferences.setLong(pushedAtKey, pushedAt); + if (!TextUtils.isEmpty(taskId)) { + Task template = new Task(); + if (NameMaps.TABLE_ID_ATTACHMENTS.equals(table)) + template.setValue(Task.ATTACHMENTS_PUSHED_AT, pushedAt); + else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table)) + template.setValue(Task.USER_ACTIVITIES_PUSHED_AT, pushedAt); + + if (template.getSetValues() != null) + PluginServices.getTaskDao().update(Task.UUID.eq(taskId), template); + + } else if (!TextUtils.isEmpty(tagId)) { + TagData template = new TagData(); + if (NameMaps.TABLE_ID_TASKS.equals(table)) + template.setValue(TagData.TASKS_PUSHED_AT, pushedAt); + if (NameMaps.TABLE_ID_TASK_LIST_METADATA.equals(table)) + template.setValue(TagData.METADATA_PUSHED_AT, pushedAt); + else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table)) + template.setValue(TagData.USER_ACTIVITIES_PUSHED_AT, pushedAt); + + if (template.getSetValues() != null) + PluginServices.getTagDataDao().update(TagData.UUID.eq(tagId), template); + + } else { + String pushedAtKey = null; + if (NameMaps.TABLE_ID_TASKS.equals(table)) + pushedAtKey = NameMaps.PUSHED_AT_TASKS; + else if (NameMaps.TABLE_ID_TAGS.equals(table)) + pushedAtKey = NameMaps.PUSHED_AT_TAGS; + else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table)) + pushedAtKey = NameMaps.PUSHED_AT_ACTIVITY; + else if (NameMaps.TABLE_ID_USERS.equals(table)) + pushedAtKey = NameMaps.PUSHED_AT_USERS; + else if (NameMaps.TABLE_ID_TASK_LIST_METADATA.equals(table)) + pushedAtKey = NameMaps.PUSHED_AT_TASK_LIST_METADATA; + + if (pushedAtKey != null) + Preferences.setLong(pushedAtKey, pushedAt); + } } else { try { diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index ca2c9fb2c..426a325f7 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -66,6 +66,7 @@ import com.todoroo.astrid.data.History; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskAttachment; import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.helper.AsyncImageView; @@ -423,7 +424,8 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene } }; - ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), callback); + ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback); + ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(TaskAttachment.class, null, task.getValue(Task.ATTACHMENTS_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback); new FetchHistory(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), false, callback).execute(); } diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index 92589b9bf..0fe133804 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -360,8 +360,13 @@ public class Database extends AbstractDatabase { database.execSQL(addColumnSql(Task.TABLE, Task.IS_READONLY, visitor, "0")); database.execSQL(addColumnSql(Task.TABLE, Task.CLASSIFICATION, visitor, null)); database.execSQL(addColumnSql(Task.TABLE, Task.HISTORY_FETCH_DATE, visitor, null)); + database.execSQL(addColumnSql(Task.TABLE, Task.ATTACHMENTS_PUSHED_AT, visitor, null)); + database.execSQL(addColumnSql(Task.TABLE, Task.USER_ACTIVITIES_PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(TagData.TABLE, TagData.PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(TagData.TABLE, TagData.HISTORY_FETCH_DATE, visitor, null)); + database.execSQL(addColumnSql(TagData.TABLE, TagData.TASKS_PUSHED_AT, visitor, null)); + database.execSQL(addColumnSql(TagData.TABLE, TagData.METADATA_PUSHED_AT, visitor, null)); + database.execSQL(addColumnSql(TagData.TABLE, TagData.USER_ACTIVITIES_PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(Metadata.TABLE, Metadata.DELETION_DATE, visitor, "0")); database.execSQL(addColumnSql(User.TABLE, User.PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(User.TABLE, User.FIRST_NAME, visitor, null));