diff --git a/api/src/com/todoroo/astrid/data/History.java b/api/src/com/todoroo/astrid/data/History.java index f752953b1..8bfaa73fa 100644 --- a/api/src/com/todoroo/astrid/data/History.java +++ b/api/src/com/todoroo/astrid/data/History.java @@ -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); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index b2962e856..e7074bc5f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -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.class, tagData.getValue(TagData.UUID), tagData.getValue(TagData.PUSHED_AT)), callback); + 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(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java index c8de8d43f..4c8662146 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java @@ -64,7 +64,6 @@ public class ChangesHappened(); - Log.e("CH", "Allocating", new Throwable()); } 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 7d56523bd..c86133479 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 @@ -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(); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java index cf894db9f..9efd4b686 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java @@ -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, String> HISTORY_PROPERTIES_LOCAL_TO_SERVER; - private static final Map> HISTORY_COLUMN_NAMES_TO_PROPERTIES; - private static final Map HISTORY_COLUMNS_LOCAL_TO_SERVER; - private static final Map> HISTORY_PROPERTIES_SERVER_TO_LOCAL; - private static final Set 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, String>(); - HISTORY_COLUMN_NAMES_TO_PROPERTIES = new HashMap>(); - HISTORY_COLUMNS_LOCAL_TO_SERVER = new HashMap(); - HISTORY_PROPERTIES_EXCLUDED = new HashSet(); - - 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, String> HISTORY_PROPERTIES_LOCAL_TO_SERVER; +// private static final Map> HISTORY_COLUMN_NAMES_TO_PROPERTIES; +// private static final Map HISTORY_COLUMNS_LOCAL_TO_SERVER; +// private static final Map> HISTORY_PROPERTIES_SERVER_TO_LOCAL; +// private static final Set 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, String>(); +// HISTORY_COLUMN_NAMES_TO_PROPERTIES = new HashMap>(); +// HISTORY_COLUMNS_LOCAL_TO_SERVER = new HashMap(); +// HISTORY_PROPERTIES_EXCLUDED = new HashSet(); +// +// 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 B mapColumnName(String table, String col, Map taskMap, Map tagMap, Map userMap, Map userActivityMap, Map historyMap) { + private static B mapColumnName(String table, String col, Map taskMap, Map tagMap, Map userMap, Map userActivityMap) { Map 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); } } diff --git a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java index c239a5a76..6b040f183 100644 --- a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java @@ -215,7 +215,7 @@ 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.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 diff --git a/astrid/src/com/todoroo/astrid/dao/HistoryDao.java b/astrid/src/com/todoroo/astrid/dao/HistoryDao.java index 49411f0de..1d815fa4c 100644 --- a/astrid/src/com/todoroo/astrid/dao/HistoryDao.java +++ b/astrid/src/com/todoroo/astrid/dao/HistoryDao.java @@ -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 { +public class HistoryDao extends DatabaseDao { @Autowired private Database database; diff --git a/astrid/src/com/todoroo/astrid/service/TagDataService.java b/astrid/src/com/todoroo/astrid/service/TagDataService.java index 1b1ce8184..6402b81b1 100644 --- a/astrid/src/com/todoroo/astrid/service/TagDataService.java +++ b/astrid/src/com/todoroo/astrid/service/TagDataService.java @@ -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$