Several changes to history model, bug fixes to FetchHistory, and placeholder display of history in UpdateAdapter to prove it works. It's pretty legit.

pull/14/head
Sam Bosley 13 years ago
parent fa1b0d3fb2
commit 73a2b5ac4f

@ -12,7 +12,7 @@ import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.api.AstridApiConstants;
@SuppressWarnings("nls")
public class History extends RemoteModel {
public class History extends AbstractModel {
/** table for this model */
public static final Table TABLE = new Table("history", History.class);
@ -28,8 +28,8 @@ public class History extends RemoteModel {
TABLE, ID_PROPERTY_NAME);
/** Remote ID */
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
public static final LongProperty UUID = new LongProperty(
TABLE, RemoteModel.UUID_PROPERTY_NAME);
/** Created at */
public static final LongProperty CREATED_AT = new LongProperty(
@ -45,11 +45,11 @@ public class History extends RemoteModel {
/** Old value */
public static final StringProperty OLD_VALUE = new StringProperty(
TABLE, "old_value");
TABLE, "old_value", Property.PROP_FLAG_NULLABLE);
/** New value */
public static final StringProperty NEW_VALUE = new StringProperty(
TABLE, "new_value");
TABLE, "new_value", Property.PROP_FLAG_NULLABLE);
/** Table identifier */
public static final StringProperty TABLE_ID = new StringProperty(
@ -59,10 +59,9 @@ public class History extends RemoteModel {
public static final StringProperty TARGET_ID = new StringProperty(
TABLE, "target_id");
@Override
public String getUuid() {
return getUuidHelper(UUID);
}
/** Task name and id (JSONArray) */
public static final StringProperty TASK = new StringProperty(
TABLE, "task");
/** Default values container */
private static final ContentValues defaultValues = new ContentValues();
@ -73,7 +72,7 @@ public class History extends RemoteModel {
}
static {
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(UUID.name, 0L);
defaultValues.put(CREATED_AT.name, 0L);
}

@ -47,6 +47,8 @@ import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.actfm.sync.ActFmSyncThread;
import com.todoroo.astrid.actfm.sync.messages.BriefMe;
import com.todoroo.astrid.actfm.sync.messages.FetchHistory;
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.activity.FilterListFragment;
import com.todoroo.astrid.activity.TaskListActivity;
@ -350,7 +352,8 @@ public class TagViewFragment extends TaskListFragment {
}
};
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TagData>(TagData.class, tagData.getValue(TagData.UUID), 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();
}
}

@ -64,7 +64,6 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
this.outstandingClass = DaoReflectionHelpers.getOutstandingClass(modelClass);
this.outstandingDao = outstandingDao;
this.changes = new ArrayList<OE>();
Log.e("CH", "Allocating", new Throwable());
}

@ -10,6 +10,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.sync.ActFmInvoker;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
@ -35,6 +36,7 @@ public class FetchHistory {
private ActFmPreferenceService actFmPreferenceService;
public FetchHistory(String table, String uuid, long modifiedAfter, boolean includeTaskHistory) {
DependencyInjectionService.getInstance().inject(this);
this.table = table;
this.uuid = uuid;
this.modifiedAfter = modifiedAfter;
@ -76,24 +78,25 @@ public class FetchHistory {
for (int i = 0; i < list.length(); i++) {
JSONObject historyJson = list.optJSONObject(i);
if (historyJson != null) {
try {
History history = MakeChanges.changesToModel(historyDao, historyJson, table);
history.setValue(History.TABLE_ID, table);
history.setValue(History.TARGET_ID, uuid);
JSONArray taskObj = historyJson.optJSONArray("task");
if (taskObj != null) {
history.setValue(History.TABLE_ID, NameMaps.TABLE_ID_TASKS);
history.setValue(History.TARGET_ID, taskObj.optString(0));
}
if (historyDao.update(History.UUID.eq(history.getUuid()), history) <= 0) {
historyDao.createNew(history);
}
} catch (InstantiationException e) {
Log.e(ERROR_TAG, "Error instantiating history", e);
} catch (IllegalAccessException e) {
Log.e(ERROR_TAG, "Error instantiating history", e);
History history = new History();
history.setValue(History.TABLE_ID, table);
history.setValue(History.TARGET_ID, uuid);
history.setValue(History.UUID, historyJson.optLong("id"));
history.setValue(History.USER_UUID, historyJson.optString("user_id"));
history.setValue(History.COLUMN, historyJson.optString("column"));
history.setValue(History.OLD_VALUE, historyJson.optString("prev"));
history.setValue(History.NEW_VALUE, historyJson.optString("value"));
history.setValue(History.CREATED_AT, historyJson.optLong("created_at") * 1000);
JSONArray taskObj = historyJson.optJSONArray("task");
if (taskObj != null) {
history.setValue(History.TABLE_ID, NameMaps.TABLE_ID_TASKS);
history.setValue(History.TARGET_ID, taskObj.optString(0));
history.setValue(History.TASK, taskObj.toString());
}
if (historyDao.update(History.UUID.eq(history.getValue(History.UUID)), history) <= 0) {
historyDao.createNew(history);
}
}
}
@ -102,7 +105,7 @@ public class FetchHistory {
Log.e(ERROR_TAG, "Error getting model history", e);
}
}
});
}).start();
}
}

@ -8,7 +8,6 @@ import java.util.Set;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.data.History;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
@ -241,40 +240,40 @@ public class NameMaps {
// ----------
// History
// ----------
private static final Map<Property<?>, String> HISTORY_PROPERTIES_LOCAL_TO_SERVER;
private static final Map<String, Property<?>> HISTORY_COLUMN_NAMES_TO_PROPERTIES;
private static final Map<String, String> HISTORY_COLUMNS_LOCAL_TO_SERVER;
private static final Map<String, Property<?>> HISTORY_PROPERTIES_SERVER_TO_LOCAL;
private static final Set<String> HISTORY_PROPERTIES_EXCLUDED;
private static void putHistoryPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
putPropertyToServerName(property, serverName, HISTORY_PROPERTIES_LOCAL_TO_SERVER, HISTORY_COLUMN_NAMES_TO_PROPERTIES,
HISTORY_COLUMNS_LOCAL_TO_SERVER, HISTORY_PROPERTIES_EXCLUDED, writeable);
}
static {
HISTORY_PROPERTIES_LOCAL_TO_SERVER = new HashMap<Property<?>, String>();
HISTORY_COLUMN_NAMES_TO_PROPERTIES = new HashMap<String, Property<?>>();
HISTORY_COLUMNS_LOCAL_TO_SERVER = new HashMap<String, String>();
HISTORY_PROPERTIES_EXCLUDED = new HashSet<String>();
putHistoryPropertyToServerName(History.UUID, "id", false);
putHistoryPropertyToServerName(History.CREATED_AT, "created_at", false);
putHistoryPropertyToServerName(History.USER_UUID, "user_id", false);
putHistoryPropertyToServerName(History.COLUMN, "column", false);
putHistoryPropertyToServerName(History.OLD_VALUE, "prev", false);
putHistoryPropertyToServerName(History.NEW_VALUE, "value", false);
// Reverse the mapping to construct the server to local map
HISTORY_PROPERTIES_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(USER_ACTIVITY_PROPERTIES_LOCAL_TO_SERVER);
}
// private static final Map<Property<?>, String> HISTORY_PROPERTIES_LOCAL_TO_SERVER;
// private static final Map<String, Property<?>> HISTORY_COLUMN_NAMES_TO_PROPERTIES;
// private static final Map<String, String> HISTORY_COLUMNS_LOCAL_TO_SERVER;
// private static final Map<String, Property<?>> HISTORY_PROPERTIES_SERVER_TO_LOCAL;
// private static final Set<String> HISTORY_PROPERTIES_EXCLUDED;
//
// private static void putHistoryPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
// putPropertyToServerName(property, serverName, HISTORY_PROPERTIES_LOCAL_TO_SERVER, HISTORY_COLUMN_NAMES_TO_PROPERTIES,
// HISTORY_COLUMNS_LOCAL_TO_SERVER, HISTORY_PROPERTIES_EXCLUDED, writeable);
// }
//
// static {
// HISTORY_PROPERTIES_LOCAL_TO_SERVER = new HashMap<Property<?>, String>();
// HISTORY_COLUMN_NAMES_TO_PROPERTIES = new HashMap<String, Property<?>>();
// HISTORY_COLUMNS_LOCAL_TO_SERVER = new HashMap<String, String>();
// HISTORY_PROPERTIES_EXCLUDED = new HashSet<String>();
//
// putHistoryPropertyToServerName(History.UUID, "id", false);
// putHistoryPropertyToServerName(History.CREATED_AT, "created_at", false);
// putHistoryPropertyToServerName(History.USER_UUID, "user_id", false);
// putHistoryPropertyToServerName(History.COLUMN, "column", false);
// putHistoryPropertyToServerName(History.OLD_VALUE, "prev", false);
// putHistoryPropertyToServerName(History.NEW_VALUE, "value", false);
//
// // Reverse the mapping to construct the server to local map
// HISTORY_PROPERTIES_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(USER_ACTIVITY_PROPERTIES_LOCAL_TO_SERVER);
// }
// ----------
// Mapping helpers
// ----------
private static <A, B> B mapColumnName(String table, String col, Map<A, B> taskMap, Map<A, B> tagMap, Map<A, B> userMap, Map<A, B> userActivityMap, Map<A, B> historyMap) {
private static <A, B> B mapColumnName(String table, String col, Map<A, B> taskMap, Map<A, B> tagMap, Map<A, B> userMap, Map<A, B> userActivityMap) {
Map<A, B> map = null;
if (TABLE_ID_TASKS.equals(table))
map = taskMap;
@ -284,8 +283,6 @@ public class NameMaps {
map = userMap;
else if (TABLE_ID_USER_ACTIVITY.equals(table))
map = userActivityMap;
else if (TABLE_ID_HISTORY.equals(table))
map = historyMap;
if (map == null)
return null;
@ -308,15 +305,15 @@ public class NameMaps {
}
public static String localColumnNameToServerColumnName(String table, String localColumn) {
return mapColumnName(table, localColumn, TASK_COLUMNS_LOCAL_TO_SERVER, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, USER_COLUMNS_LOCAL_TO_SERVER, USER_ACTIVITY_COLUMNS_LOCAL_TO_SERVER, HISTORY_COLUMNS_LOCAL_TO_SERVER);
return mapColumnName(table, localColumn, TASK_COLUMNS_LOCAL_TO_SERVER, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, USER_COLUMNS_LOCAL_TO_SERVER, USER_ACTIVITY_COLUMNS_LOCAL_TO_SERVER);
}
public static Property<?> localColumnNameToProperty(String table, String localColumn) {
return mapColumnName(table, localColumn, TASK_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, USER_COLUMN_NAMES_TO_PROPERTIES, USER_ACTIVITY_COLUMN_NAMES_TO_PROPERTIES, HISTORY_COLUMN_NAMES_TO_PROPERTIES);
return mapColumnName(table, localColumn, TASK_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, USER_COLUMN_NAMES_TO_PROPERTIES, USER_ACTIVITY_COLUMN_NAMES_TO_PROPERTIES);
}
public static Property<?> serverColumnNameToLocalProperty(String table, String serverColumn) {
return mapColumnName(table, serverColumn, TASK_PROPERTIES_SERVER_TO_LOCAL, TAG_DATA_PROPERTIES_SERVER_TO_LOCAL, USER_PROPERTIES_SERVER_TO_LOCAL, USER_ACTIVITY_PROPERTIES_SERVER_TO_LOCAL, HISTORY_PROPERTIES_SERVER_TO_LOCAL);
return mapColumnName(table, serverColumn, TASK_PROPERTIES_SERVER_TO_LOCAL, TAG_DATA_PROPERTIES_SERVER_TO_LOCAL, USER_PROPERTIES_SERVER_TO_LOCAL, USER_ACTIVITY_PROPERTIES_SERVER_TO_LOCAL);
}
}

@ -215,7 +215,7 @@ public class UpdateAdapter extends CursorAdapter {
private static void readHistoryProperties(TodorooCursor<UserActivity> unionCursor, History history) {
history.setValue(History.CREATED_AT, unionCursor.getLong(0));
history.setValue(History.UUID, unionCursor.getString(1));
history.setValue(History.UUID, unionCursor.getLong(1));
history.setValue(History.COLUMN, unionCursor.getString(2));
history.setValue(History.TABLE_ID, unionCursor.getString(3));
history.setValue(History.OLD_VALUE, unionCursor.getString(4));
@ -246,6 +246,7 @@ public class UpdateAdapter extends CursorAdapter {
String pictureUrl = user.getPictureUrl(USER_PICTURE, RemoteModel.PICTURE_THUMB);
pictureView.setUrl(pictureUrl);
}
pictureView.setVisibility(View.VISIBLE);
}
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); {
@ -274,7 +275,23 @@ public class UpdateAdapter extends CursorAdapter {
}
private void setupHistoryRow(View view, History history) {
//
final AsyncImageView pictureView = (AsyncImageView)view.findViewById(R.id.picture);
pictureView.setVisibility(View.GONE);
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture);
commentPictureView.setVisibility(View.GONE);
final TextView nameView = (TextView)view.findViewById(R.id.title); {
nameView.setText("Changed " + history.getValue(History.COLUMN) + " from " + history.getValue(History.OLD_VALUE) +
" to " + history.getValue(History.NEW_VALUE));
}
final TextView date = (TextView)view.findViewById(R.id.date); {
CharSequence dateString = DateUtils.getRelativeTimeSpanString(history.getValue(History.CREATED_AT),
DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
date.setText(dateString);
}
}
@Override

@ -2,12 +2,13 @@ package com.todoroo.astrid.dao;
import android.content.ContentValues;
import com.todoroo.andlib.data.DatabaseDao;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.History;
public class HistoryDao extends RemoteModelDao<History> {
public class HistoryDao extends DatabaseDao<History> {
@Autowired
private Database database;

@ -182,7 +182,9 @@ public class TagDataService {
}
Query historyQuery = Query.select(AndroidUtilities.addToArray(UpdateAdapter.HISTORY_PROPERTIES, paddingArray)).from(History.TABLE)
.where(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TAGS), History.TARGET_ID.eq(tagData.getUuid())))
.where(Criterion.or(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TAGS), History.TARGET_ID.eq(tagData.getUuid())),
Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TASKS), History.TARGET_ID.in(Query.select(TaskToTagMetadata.TASK_UUID)
.from(Metadata.TABLE).where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(tagData.getUuid())))))))
.from(History.TABLE);
Query resultQuery = activityQuery.union(historyQuery).orderBy(Order.desc("1")); //$NON-NLS-1$

Loading…
Cancel
Save