diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index e7074bc5f..08435caa9 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -353,7 +353,7 @@ public class TagViewFragment extends TaskListFragment { }; ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback); - new FetchHistory(NameMaps.TABLE_ID_TAGS, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT), true).execute(); + new FetchHistory(NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.PUSHED_AT), true).execute(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java index 67947f072..70ba036f9 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java @@ -2,6 +2,7 @@ package com.todoroo.astrid.actfm.sync.messages; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import org.json.JSONArray; import org.json.JSONObject; @@ -15,7 +16,10 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.actfm.sync.ActFmInvoker; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.dao.HistoryDao; +import com.todoroo.astrid.dao.UserDao; import com.todoroo.astrid.data.History; +import com.todoroo.astrid.data.RemoteModel; +import com.todoroo.astrid.data.User; public class FetchHistory { @@ -23,6 +27,7 @@ public class FetchHistory { private final String table; private final String uuid; + private final String taskTitle; private final long modifiedAfter; private final boolean includeTaskHistory; @@ -32,13 +37,17 @@ public class FetchHistory { @Autowired private HistoryDao historyDao; + @Autowired + private UserDao userDao; + @Autowired private ActFmPreferenceService actFmPreferenceService; - public FetchHistory(String table, String uuid, long modifiedAfter, boolean includeTaskHistory) { + public FetchHistory(String table, String uuid, String taskTitle, long modifiedAfter, boolean includeTaskHistory) { DependencyInjectionService.getInstance().inject(this); this.table = table; this.uuid = uuid; + this.taskTitle = taskTitle; this.modifiedAfter = modifiedAfter; this.includeTaskHistory = includeTaskHistory; } @@ -93,6 +102,11 @@ public class FetchHistory { history.setValue(History.TABLE_ID, NameMaps.TABLE_ID_TASKS); history.setValue(History.TARGET_ID, taskObj.optString(0)); history.setValue(History.TASK, taskObj.toString()); + } else if (NameMaps.TABLE_ID_TASKS.equals(table) && !TextUtils.isEmpty(taskTitle)) { + taskObj = new JSONArray(); + taskObj.put(uuid); + taskObj.put(taskTitle); + history.setValue(History.TASK, taskObj.toString()); } if (historyDao.update(History.UUID.eq(history.getValue(History.UUID)), history) <= 0) { @@ -101,6 +115,31 @@ public class FetchHistory { } } } + + JSONObject users = result.optJSONObject("users"); + if (users != null) { + Iterator keys = users.keys(); + while (keys.hasNext()) { + String key = keys.next(); + JSONObject userObj = users.optJSONObject(key); + if (userObj != null) { + String userUuid = userObj.optString("id"); + if (RemoteModel.isUuidEmpty(uuid)) + continue; + + User user = new User(); + user.setValue(User.FIRST_NAME, userObj.optString("first_name")); + user.setValue(User.LAST_NAME, userObj.optString("last_name")); + user.setValue(User.NAME, userObj.optString("name")); + user.setValue(User.PICTURE, userObj.optString("picture")); + user.setValue(User.UUID, userUuid); + + if (userDao.update(User.UUID.eq(userUuid), user) <= 0) { + userDao.createNew(user); + } + } + } + } } catch (IOException e) { Log.e(ERROR_TAG, "Error getting model history", e); } diff --git a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java index 6b040f183..0ffaa6e1e 100644 --- a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java @@ -103,7 +103,7 @@ public class UpdateAdapter extends CursorAdapter { History.TABLE_ID, History.OLD_VALUE, History.NEW_VALUE, - PADDING_PROPERTY, + History.TASK, History.ID, HISTORY_TYPE_PROPERTY, }; @@ -215,11 +215,12 @@ public class UpdateAdapter extends CursorAdapter { private static void readHistoryProperties(TodorooCursor unionCursor, History history) { history.setValue(History.CREATED_AT, unionCursor.getLong(0)); - history.setValue(History.UUID, unionCursor.getLong(1)); + history.setValue(History.UUID, unionCursor.getString(1)); history.setValue(History.COLUMN, unionCursor.getString(2)); history.setValue(History.TABLE_ID, unionCursor.getString(3)); history.setValue(History.OLD_VALUE, unionCursor.getString(4)); history.setValue(History.NEW_VALUE, unionCursor.getString(5)); + history.setValue(History.TASK, unionCursor.getString(6)); } public static void readUserProperties(TodorooCursor joinCursor, User user) { @@ -418,6 +419,10 @@ public class UpdateAdapter extends CursorAdapter { return builder; } + public static Spanned getHistoryComment(final AstridActivity context, History history, String linkColor, String fromView) { + return null; + } + private static CharSequence getLinkSpan(final AstridActivity activity, UserActivity update, String targetName, String linkColor, String linkType) { if (TASK_LINK_TYPE.equals(linkType)) { final String taskId = update.getValue(UserActivity.TARGET_ID);