Add a tag data column for keeping track of history fetch times

pull/14/head
Sam Bosley 12 years ago
parent 44bd887dfb
commit c1c1323b07

@ -125,6 +125,10 @@ public final class TagData extends RemoteModel {
public static final StringProperty TAG_ORDERING = new StringProperty( public static final StringProperty TAG_ORDERING = new StringProperty(
TABLE, "tagOrdering"); TABLE, "tagOrdering");
/** History fetch date */
public static final LongProperty HISTORY_FETCH_DATE = new LongProperty(
TABLE, "historyFetch");
/** List of all properties for this model */ /** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(TagData.class); public static final Property<?>[] PROPERTIES = generateProperties(TagData.class);
@ -156,6 +160,7 @@ public final class TagData extends RemoteModel {
defaultValues.put(FLAGS.name, 0); defaultValues.put(FLAGS.name, 0);
defaultValues.put(COMPLETION_DATE.name, 0); defaultValues.put(COMPLETION_DATE.name, 0);
defaultValues.put(DELETION_DATE.name, 0); defaultValues.put(DELETION_DATE.name, 0);
defaultValues.put(HISTORY_FETCH_DATE.name, 0);
defaultValues.put(THUMB.name, ""); defaultValues.put(THUMB.name, "");
defaultValues.put(LAST_ACTIVITY_DATE.name, 0); defaultValues.put(LAST_ACTIVITY_DATE.name, 0);

@ -57,6 +57,7 @@ import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.core.SortHelper; import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TagMetadataDao; import com.todoroo.astrid.dao.TagMetadataDao;
import com.todoroo.astrid.dao.TagMetadataDao.TagMetadataCriteria; import com.todoroo.astrid.dao.TagMetadataDao.TagMetadataCriteria;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
@ -106,6 +107,8 @@ public class TagViewFragment extends TaskListFragment {
@Autowired TagDataService tagDataService; @Autowired TagDataService tagDataService;
@Autowired TagDataDao tagDataDao;
@Autowired ActFmSyncService actFmSyncService; @Autowired ActFmSyncService actFmSyncService;
@Autowired ActFmPreferenceService actFmPreferenceService; @Autowired ActFmPreferenceService actFmPreferenceService;
@ -353,7 +356,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(), null, tagData.getValue(TagData.PUSHED_AT), true).execute(); new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true).execute();
} }
} }

@ -10,21 +10,25 @@ import org.json.JSONObject;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities; 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.RemoteModelDao;
import com.todoroo.astrid.dao.UserDao; 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.RemoteModel;
import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.User;
public class FetchHistory { public class FetchHistory<TYPE extends RemoteModel> {
private static final String ERROR_TAG = "actfm-fetch-history"; //$NON-NLS-1$ private static final String ERROR_TAG = "actfm-fetch-history"; //$NON-NLS-1$
private final RemoteModelDao<TYPE> dao;
private final LongProperty historyTimeProperty;
private final String table; private final String table;
private final String uuid; private final String uuid;
private final String taskTitle; private final String taskTitle;
@ -43,8 +47,11 @@ public class FetchHistory {
@Autowired @Autowired
private ActFmPreferenceService actFmPreferenceService; private ActFmPreferenceService actFmPreferenceService;
public FetchHistory(String table, String uuid, String taskTitle, long modifiedAfter, boolean includeTaskHistory) { public FetchHistory(RemoteModelDao<TYPE> dao, LongProperty historyTimeProperty,
String table, String uuid, String taskTitle, long modifiedAfter, boolean includeTaskHistory) {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
this.dao = dao;
this.historyTimeProperty = historyTimeProperty;
this.table = table; this.table = table;
this.uuid = uuid; this.uuid = uuid;
this.taskTitle = taskTitle; this.taskTitle = taskTitle;
@ -83,6 +90,7 @@ public class FetchHistory {
try { try {
JSONObject result = actFmInvoker.invoke("model_history_list", params.toArray(new Object[params.size()])); JSONObject result = actFmInvoker.invoke("model_history_list", params.toArray(new Object[params.size()]));
JSONArray list = result.optJSONArray("list"); JSONArray list = result.optJSONArray("list");
long time = result.optLong("time") * 1000;
if (list != null) { if (list != null) {
for (int i = 0; i < list.length(); i++) { for (int i = 0; i < list.length(); i++) {
JSONObject historyJson = list.optJSONObject(i); JSONObject historyJson = list.optJSONObject(i);
@ -114,6 +122,18 @@ public class FetchHistory {
} }
} }
} }
if (time > 0) {
TYPE template;
try {
template = dao.getModelClass().newInstance();
template.setValue(historyTimeProperty, time);
dao.update(RemoteModel.UUID_PROPERTY.eq(uuid), template);
} catch (InstantiationException e) {
Log.e(ERROR_TAG, "Error instantiating model for recording time", e);
} catch (IllegalAccessException e) {
Log.e(ERROR_TAG, "Error instantiating model for recording time", e);
}
}
} }
JSONObject users = result.optJSONObject("users"); JSONObject users = result.optJSONObject("users");

@ -348,6 +348,7 @@ public class Database extends AbstractDatabase {
database.execSQL(addColumnSql(Task.TABLE, Task.IS_READONLY, visitor, "0")); database.execSQL(addColumnSql(Task.TABLE, Task.IS_READONLY, visitor, "0"));
database.execSQL(addColumnSql(Task.TABLE, Task.CLASSIFICATION, visitor, null)); database.execSQL(addColumnSql(Task.TABLE, Task.CLASSIFICATION, visitor, null));
database.execSQL(addColumnSql(TagData.TABLE, TagData.PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(TagData.TABLE, TagData.PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(TagData.TABLE, TagData.HISTORY_FETCH_DATE, visitor, null));
database.execSQL(addColumnSql(Metadata.TABLE, Metadata.DELETION_DATE, visitor, "0")); database.execSQL(addColumnSql(Metadata.TABLE, Metadata.DELETION_DATE, visitor, "0"));
database.execSQL(addColumnSql(User.TABLE, User.PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(User.TABLE, User.PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(User.TABLE, User.FIRST_NAME, visitor, null)); database.execSQL(addColumnSql(User.TABLE, User.FIRST_NAME, visitor, null));

Loading…
Cancel
Save