Implemented finer grained queries now supported by new sync api

pull/14/head
Sam Bosley 13 years ago
parent 00f9747e8d
commit ddc9622ffe

@ -121,6 +121,18 @@ public final class TagData extends RemoteModel {
public static final LongProperty PUSHED_AT = new LongProperty(
TABLE, PUSHED_AT_PROPERTY_NAME, Property.PROP_FLAG_DATE);
/** Tasks pushed at date */
public static final LongProperty TASKS_PUSHED_AT = new LongProperty(
TABLE, "tasks_pushed_at", Property.PROP_FLAG_DATE);
/** Metadata pushed at date */
public static final LongProperty METADATA_PUSHED_AT = new LongProperty(
TABLE, "metadata_pushed_at", Property.PROP_FLAG_DATE);
/** User activities pushed at date */
public static final LongProperty USER_ACTIVITIES_PUSHED_AT = new LongProperty(
TABLE, "activities_pushed_at", Property.PROP_FLAG_DATE);
/** Tag ordering */
public static final StringProperty TAG_ORDERING = new StringProperty(
TABLE, "tagOrdering");
@ -169,6 +181,9 @@ public final class TagData extends RemoteModel {
defaultValues.put(TASK_COUNT.name, 0);
defaultValues.put(TAG_DESCRIPTION.name, "");
defaultValues.put(PUSHED_AT.name, 0L);
defaultValues.put(TASKS_PUSHED_AT.name, 0L);
defaultValues.put(METADATA_PUSHED_AT.name, 0L);
defaultValues.put(USER_ACTIVITIES_PUSHED_AT.name, 0L);
defaultValues.put(TAG_ORDERING.name, "[]");
}

@ -178,6 +178,14 @@ public final class Task extends RemoteModel {
public static final LongProperty PUSHED_AT = new LongProperty(
TABLE, PUSHED_AT_PROPERTY_NAME, Property.PROP_FLAG_DATE);
/** Attachments pushed at date */
public static final LongProperty ATTACHMENTS_PUSHED_AT = new LongProperty(
TABLE, "attachments_pushed_at", Property.PROP_FLAG_DATE);
/** User activities pushed at date */
public static final LongProperty USER_ACTIVITIES_PUSHED_AT = new LongProperty(
TABLE, "activities_pushed_at", Property.PROP_FLAG_DATE);
/** History fetch time */
public static final LongProperty HISTORY_FETCH_DATE = new LongProperty(
TABLE, "historyFetch");
@ -311,6 +319,8 @@ public final class Task extends RemoteModel {
defaultValues.put(USER.name, "");
// defaultValues.put(USER_EMAIL.name, "");
defaultValues.put(PUSHED_AT.name, 0L);
defaultValues.put(ATTACHMENTS_PUSHED_AT.name, 0L);
defaultValues.put(USER_ACTIVITIES_PUSHED_AT.name, 0L);
}
@Override

@ -128,7 +128,7 @@ public class TagCommentsFragment extends CommentsFragment {
@Override
protected void performFetch(boolean manual, Runnable done) {
if (tagData != null) {
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TagData>(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), done);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), done);
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, done).execute();
}
}

@ -66,6 +66,7 @@ import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagMetadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
@ -355,7 +356,10 @@ public class TagViewFragment extends TaskListFragment {
};
ActFmSyncThread.getInstance().repopulateQueueFromOutstandingTables();
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<Task>(Task.class, null, tagData.getValue(TagData.TASKS_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TagData>(TagData.class, tagData.getUuid(), tagData.getValue(TagData.PUSHED_AT)), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, tagData.getValue(TagData.USER_ACTIVITIES_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TaskListMetadata>(TaskListMetadata.class, null, tagData.getValue(TagData.METADATA_PUSHED_AT), BriefMe.TAG_ID_KEY, tagData.getUuid()), callback);
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TAGS, tagData.getUuid(), null, tagData.getValue(TagData.HISTORY_FETCH_DATE), true, null).execute();
}
}

@ -81,7 +81,7 @@ public class TaskCommentsFragment extends CommentsFragment {
@Override
protected void performFetch(boolean manual, Runnable done) {
if (task != null) {
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<Task>(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), done);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), done);
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), false, done).execute();
}
}

@ -3,12 +3,19 @@ package com.todoroo.astrid.actfm.sync.messages;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.RemoteModelDao;
import com.todoroo.astrid.data.RemoteModel;
public class BriefMe<TYPE extends RemoteModel> extends ClientToServerMessage<TYPE> {
private static final String ERROR_TAG = "actfm-brief-me"; //$NON-NLS-1$
public static final String TASK_ID_KEY = "task_id"; //$NON-NLS-1$
public static final String TAG_ID_KEY = "tag_id"; //$NON-NLS-1$
public static <TYPE extends RemoteModel> BriefMe<TYPE> instantiateBriefMeForClass(Class<TYPE> cls, String pushedAtKey) {
long pushedAt = Preferences.getLong(pushedAtKey, 0);
return new BriefMe<TYPE>(cls, null, pushedAt);
@ -16,15 +23,31 @@ public class BriefMe<TYPE extends RemoteModel> extends ClientToServerMessage<TYP
public BriefMe(long id, Class<TYPE> modelClass, RemoteModelDao<TYPE> modelDao) {
super(id, modelClass, modelDao);
this.extraParameters = null;
}
public BriefMe(Class<TYPE> modelClass, String uuid, long pushedAt) {
private final Object[] extraParameters;
public BriefMe(Class<TYPE> modelClass, String uuid, long pushedAt, Object...extraParameters) {
super(modelClass, uuid, pushedAt);
this.extraParameters = extraParameters;
}
@Override
protected boolean serializeExtrasToJSON(JSONObject serializeTo) throws JSONException {
// No extras
if (extraParameters != null && extraParameters.length > 0) {
for (int i = 0; i < extraParameters.length - 1; i++) {
try {
String key = (String) extraParameters[i];
Object value = extraParameters[i + 1];
serializeTo.put(key, value);
} catch (ClassCastException e) {
Log.e(ERROR_TAG, "ClassCastException serializing BriefMe", e); //$NON-NLS-1$
} catch (JSONException e) {
Log.e(ERROR_TAG, "JSONException serializing BriefMe", e); //$NON-NLS-1$
}
}
}
return true;
}

@ -9,8 +9,11 @@ import android.util.Log;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.RemoteModelDao;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
@SuppressWarnings("nls")
public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage {
@ -20,12 +23,16 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
private final RemoteModelDao<TYPE> dao;
private final String table;
private final String uuid;
private final String taskId;
private final String tagId;
private long pushedAt;
public NowBriefed(JSONObject json, RemoteModelDao<TYPE> dao) {
super(json);
this.table = json.optString("table");
this.uuid = json.optString("uuid");
this.taskId = json.optString(BriefMe.TASK_ID_KEY);
this.tagId = json.optString(BriefMe.TAG_ID_KEY);
this.dao = dao;
try {
this.pushedAt = DateUtilities.parseIso8601(json.optString("pushed_at"));
@ -38,6 +45,29 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
public void processMessage() {
if (pushedAt > 0) {
if (TextUtils.isEmpty(uuid)) {
if (!TextUtils.isEmpty(taskId)) {
Task template = new Task();
if (NameMaps.TABLE_ID_ATTACHMENTS.equals(table))
template.setValue(Task.ATTACHMENTS_PUSHED_AT, pushedAt);
else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table))
template.setValue(Task.USER_ACTIVITIES_PUSHED_AT, pushedAt);
if (template.getSetValues() != null)
PluginServices.getTaskDao().update(Task.UUID.eq(taskId), template);
} else if (!TextUtils.isEmpty(tagId)) {
TagData template = new TagData();
if (NameMaps.TABLE_ID_TASKS.equals(table))
template.setValue(TagData.TASKS_PUSHED_AT, pushedAt);
if (NameMaps.TABLE_ID_TASK_LIST_METADATA.equals(table))
template.setValue(TagData.METADATA_PUSHED_AT, pushedAt);
else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table))
template.setValue(TagData.USER_ACTIVITIES_PUSHED_AT, pushedAt);
if (template.getSetValues() != null)
PluginServices.getTagDataDao().update(TagData.UUID.eq(tagId), template);
} else {
String pushedAtKey = null;
if (NameMaps.TABLE_ID_TASKS.equals(table))
pushedAtKey = NameMaps.PUSHED_AT_TASKS;
@ -52,6 +82,7 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
if (pushedAtKey != null)
Preferences.setLong(pushedAtKey, pushedAt);
}
} else {
try {

@ -66,6 +66,7 @@ import com.todoroo.astrid.data.History;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskAttachment;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
@ -423,7 +424,8 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
}
};
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<Task>(Task.class, task.getUuid(), task.getValue(Task.PUSHED_AT)), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback);
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<TaskAttachment>(TaskAttachment.class, null, task.getValue(Task.ATTACHMENTS_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback);
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, NameMaps.TABLE_ID_TASKS, task.getUuid(), task.getValue(Task.TITLE), task.getValue(Task.HISTORY_FETCH_DATE), false, callback).execute();
}

@ -360,8 +360,13 @@ public class Database extends AbstractDatabase {
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.HISTORY_FETCH_DATE, visitor, null));
database.execSQL(addColumnSql(Task.TABLE, Task.ATTACHMENTS_PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(Task.TABLE, Task.USER_ACTIVITIES_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(TagData.TABLE, TagData.TASKS_PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(TagData.TABLE, TagData.METADATA_PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(TagData.TABLE, TagData.USER_ACTIVITIES_PUSHED_AT, visitor, null));
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.FIRST_NAME, visitor, null));

Loading…
Cancel
Save