Fixed bugs with user image display in comments

pull/14/head
Sam Bosley 13 years ago
parent c7dc3f276d
commit 064268b819

@ -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<TYPE extends RemoteModel> {
@ -108,6 +109,10 @@ public class FetchHistory<TYPE extends RemoteModel> {
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"));

@ -331,6 +331,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
notes.close();
}
User self = UpdateAdapter.getSelfUser();
TodorooCursor<UserActivity> 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++;
}

@ -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<UserActivity> 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<UserActivity> 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 */

Loading…
Cancel
Save