Store task titles in history models, save users the history api tells us about

pull/14/head
Sam Bosley 13 years ago
parent e598320683
commit 7833916490

@ -353,7 +353,7 @@ public class TagViewFragment extends TaskListFragment {
}; };
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TagData>(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback); ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TagData>(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();
} }
} }

@ -2,6 +2,7 @@ package com.todoroo.astrid.actfm.sync.messages;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; 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.ActFmInvoker;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.dao.HistoryDao; import com.todoroo.astrid.dao.HistoryDao;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.History; import com.todoroo.astrid.data.History;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.User;
public class FetchHistory { public class FetchHistory {
@ -23,6 +27,7 @@ public class FetchHistory {
private final String table; private final String table;
private final String uuid; private final String uuid;
private final String taskTitle;
private final long modifiedAfter; private final long modifiedAfter;
private final boolean includeTaskHistory; private final boolean includeTaskHistory;
@ -32,13 +37,17 @@ public class FetchHistory {
@Autowired @Autowired
private HistoryDao historyDao; private HistoryDao historyDao;
@Autowired
private UserDao userDao;
@Autowired @Autowired
private ActFmPreferenceService actFmPreferenceService; 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); DependencyInjectionService.getInstance().inject(this);
this.table = table; this.table = table;
this.uuid = uuid; this.uuid = uuid;
this.taskTitle = taskTitle;
this.modifiedAfter = modifiedAfter; this.modifiedAfter = modifiedAfter;
this.includeTaskHistory = includeTaskHistory; this.includeTaskHistory = includeTaskHistory;
} }
@ -93,6 +102,11 @@ public class FetchHistory {
history.setValue(History.TABLE_ID, NameMaps.TABLE_ID_TASKS); history.setValue(History.TABLE_ID, NameMaps.TABLE_ID_TASKS);
history.setValue(History.TARGET_ID, taskObj.optString(0)); history.setValue(History.TARGET_ID, taskObj.optString(0));
history.setValue(History.TASK, taskObj.toString()); 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) { 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<String> 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) { } catch (IOException e) {
Log.e(ERROR_TAG, "Error getting model history", e); Log.e(ERROR_TAG, "Error getting model history", e);
} }

@ -103,7 +103,7 @@ public class UpdateAdapter extends CursorAdapter {
History.TABLE_ID, History.TABLE_ID,
History.OLD_VALUE, History.OLD_VALUE,
History.NEW_VALUE, History.NEW_VALUE,
PADDING_PROPERTY, History.TASK,
History.ID, History.ID,
HISTORY_TYPE_PROPERTY, HISTORY_TYPE_PROPERTY,
}; };
@ -215,11 +215,12 @@ public class UpdateAdapter extends CursorAdapter {
private static void readHistoryProperties(TodorooCursor<UserActivity> unionCursor, History history) { private static void readHistoryProperties(TodorooCursor<UserActivity> unionCursor, History history) {
history.setValue(History.CREATED_AT, unionCursor.getLong(0)); 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.COLUMN, unionCursor.getString(2));
history.setValue(History.TABLE_ID, unionCursor.getString(3)); history.setValue(History.TABLE_ID, unionCursor.getString(3));
history.setValue(History.OLD_VALUE, unionCursor.getString(4)); history.setValue(History.OLD_VALUE, unionCursor.getString(4));
history.setValue(History.NEW_VALUE, unionCursor.getString(5)); history.setValue(History.NEW_VALUE, unionCursor.getString(5));
history.setValue(History.TASK, unionCursor.getString(6));
} }
public static void readUserProperties(TodorooCursor<UserActivity> joinCursor, User user) { public static void readUserProperties(TodorooCursor<UserActivity> joinCursor, User user) {
@ -418,6 +419,10 @@ public class UpdateAdapter extends CursorAdapter {
return builder; 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) { private static CharSequence getLinkSpan(final AstridActivity activity, UserActivity update, String targetName, String linkColor, String linkType) {
if (TASK_LINK_TYPE.equals(linkType)) { if (TASK_LINK_TYPE.equals(linkType)) {
final String taskId = update.getValue(UserActivity.TARGET_ID); final String taskId = update.getValue(UserActivity.TARGET_ID);

Loading…
Cancel
Save