From 064268b81994508bb41d57f984ef6ea9b05a8e2d Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 12 Apr 2013 17:47:28 -0700 Subject: [PATCH] Fixed bugs with user image display in comments --- .../actfm/sync/messages/FetchHistory.java | 5 +++ .../astrid/notes/EditNoteActivity.java | 7 +++- .../todoroo/astrid/adapter/UpdateAdapter.java | 40 ++++++++++++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) 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 0d1508f13..ae8c58833 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 @@ -22,6 +22,7 @@ import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.dao.UserDao; import com.todoroo.astrid.data.History; import com.todoroo.astrid.data.RemoteModel; +import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.User; public class FetchHistory { @@ -108,6 +109,10 @@ public class FetchHistory { history.setValue(History.TABLE_ID, table); history.setValue(History.TARGET_ID, uuid); history.setValue(History.UUID, historyJson.optString("id") + ":" + uuid); + + String userId = historyJson.optString("user_id"); + if (userId.equals(ActFmPreferenceService.userId())) + userId = Task.USER_ID_SELF; history.setValue(History.USER_UUID, historyJson.optString("user_id")); history.setValue(History.COLUMN, historyJson.optString("column")); history.setValue(History.OLD_VALUE, historyJson.optString("prev")); diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index fd565d30b..392938ab3 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -331,6 +331,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene notes.close(); } + User self = UpdateAdapter.getSelfUser(); TodorooCursor updates = taskService.getActivityAndHistoryForTask(task); try { @@ -343,12 +344,16 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene String type = updates.getString(UpdateAdapter.TYPE_PROPERTY_INDEX); NoteOrUpdate noa; - UpdateAdapter.readUserProperties(updates, user); + boolean isSelf; if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) { UpdateAdapter.readUserActivityProperties(updates, update); + isSelf = Task.USER_ID_SELF.equals(update.getValue(UserActivity.USER_UUID)); + UpdateAdapter.readUserProperties(updates, user, self, isSelf); noa = NoteOrUpdate.fromUpdateOrHistory(activity, update, null, user, linkColor); } else { UpdateAdapter.readHistoryProperties(updates, history); + isSelf = Task.USER_ID_SELF.equals(history.getValue(History.USER_UUID)); + UpdateAdapter.readUserProperties(updates, user, self, isSelf); noa = NoteOrUpdate.fromUpdateOrHistory(activity, null, history, user, linkColor); historyCount++; } diff --git a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java index 0c40cca3c..b88a700c9 100644 --- a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java @@ -49,6 +49,7 @@ import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; +import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.messages.NameMaps; import com.todoroo.astrid.activity.AstridActivity; @@ -133,6 +134,8 @@ public class UpdateAdapter extends CursorAdapter { public static final String FROM_TASK_VIEW = "from_task"; //$NON-NLS-1$ public static final String FROM_RECENT_ACTIVITY_VIEW = "from_recent_activity"; //$NON-NLS-1$ + private final User self; + /** * Constructor * @@ -161,6 +164,23 @@ public class UpdateAdapter extends CursorAdapter { this.resource = resource; this.fragment = fragment; + this.self = getSelfUser(); + } + + public static User getSelfUser() { + User self = new User(); + readPreferenceToUser(self, USER_FIRST_NAME, ActFmPreferenceService.PREF_FIRST_NAME); + readPreferenceToUser(self, USER_LAST_NAME, ActFmPreferenceService.PREF_LAST_NAME); + readPreferenceToUser(self, USER_NAME, ActFmPreferenceService.PREF_NAME); + readPreferenceToUser(self, USER_PICTURE, ActFmPreferenceService.PREF_PICTURE); + return self; + } + + private static void readPreferenceToUser(User u, StringProperty prop, String prefKey) { + String val = Preferences.getStringValue(prefKey); + if (val == null) + val = ""; //$NON-NLS-1$ + u.setValue(prop, val); } public static String getLinkColor(Fragment f) { @@ -207,12 +227,15 @@ public class UpdateAdapter extends CursorAdapter { user.clear(); History history = mh.history; + boolean isSelf; if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) { readUserActivityProperties(cursor, update); + isSelf = Task.USER_ID_SELF.equals(update.getValue(UserActivity.USER_UUID)); } else { readHistoryProperties(cursor, history); + isSelf = Task.USER_ID_SELF.equals(history.getValue(History.USER_UUID)); } - readUserProperties(cursor, user); + readUserProperties(cursor, user, self, isSelf); setFieldContentsAndVisibility(view, update, user, history, type); } @@ -239,11 +262,16 @@ public class UpdateAdapter extends CursorAdapter { history.setValue(History.USER_UUID, unionCursor.getString(7)); } - public static void readUserProperties(TodorooCursor joinCursor, User user) { - user.setValue(USER_FIRST_NAME, joinCursor.get(USER_FIRST_NAME)); - user.setValue(USER_LAST_NAME, joinCursor.get(USER_LAST_NAME)); - user.setValue(USER_NAME, joinCursor.get(USER_NAME)); - user.setValue(USER_PICTURE, joinCursor.get(USER_PICTURE)); + public static void readUserProperties(TodorooCursor joinCursor, User user, User self, boolean isSelf) { + if (isSelf) { + user.mergeWith(self.getSetValues()); + } else { + user.setValue(USER_FIRST_NAME, joinCursor.get(USER_FIRST_NAME)); + user.setValue(USER_LAST_NAME, joinCursor.get(USER_LAST_NAME)); + user.setValue(USER_NAME, joinCursor.get(USER_NAME)); + user.setValue(USER_PICTURE, joinCursor.get(USER_PICTURE)); + } + } /** Helper method to set the contents and visibility of each field */