Implement pushed_at for tasks and tag tables

pull/14/head
Sam Bosley 13 years ago
parent 58bd972029
commit 32f979c020

@ -140,8 +140,8 @@ public class ActFmSyncThread {
}
if (messageBatch.isEmpty() && timeForBackgroundSync()) {
messageBatch.add(BriefMe.instantiateBriefMeForClass(Task.class));
messageBatch.add(BriefMe.instantiateBriefMeForClass(TagData.class));
messageBatch.add(BriefMe.instantiateBriefMeForClass(Task.class, NameMaps.PUSHED_AT_TASKS));
messageBatch.add(BriefMe.instantiateBriefMeForClass(TagData.class, NameMaps.PUSHED_AT_TAGS));
}
if (!messageBatch.isEmpty() && checkForToken()) {

@ -3,14 +3,14 @@ package com.todoroo.astrid.actfm.sync.messages;
import org.json.JSONException;
import org.json.JSONObject;
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> {
public static <TYPE extends RemoteModel> BriefMe<TYPE> instantiateBriefMeForClass(Class<TYPE> cls) {
// TODO: compute last pushed at value for model class
long pushedAt = 0;
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);
}

@ -14,6 +14,7 @@ import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.PropertyVisitor;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.RemoteModelDao;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.SyncFlags;
@ -36,7 +37,8 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
public void processMessage() {
JSONArray changes = json.optJSONArray("changes");
String uuid = json.optString("uuid");
if (dao != null && changes != null && !TextUtils.isEmpty(uuid)) {
if (changes != null && !TextUtils.isEmpty(uuid)) {
if (dao != null) { // Model case
try {
TYPE model = dao.getModelClass().newInstance();
if (changes.length() > 0) {
@ -66,6 +68,21 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
} catch (InstantiationException e) {
Log.e(ERROR_TAG, "Error instantiating model for MakeChanges", e);
}
} else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table)) { // pushed_at case
JSONArray change = changes.optJSONArray(0);
if (change != null && change.optString(0).equals(NameMaps.TABLE_ID_PUSHED_AT)) {
long pushedAt = change.optLong(1);
String pushedAtKey = null;
if (NameMaps.TABLE_ID_TASKS.equals(uuid))
pushedAtKey = NameMaps.PUSHED_AT_TASKS;
else if (NameMaps.TABLE_ID_TAGS.equals(uuid))
pushedAtKey = NameMaps.PUSHED_AT_TAGS;
if (pushedAtKey != null)
Preferences.setLong(pushedAtKey, pushedAt);
}
}
}
}

@ -23,6 +23,10 @@ public class NameMaps {
public static final String TABLE_ID_TASKS = "tasks";
public static final String TABLE_ID_TAGS = "tags";
public static final String TABLE_ID_USERS = "users";
public static final String TABLE_ID_PUSHED_AT = "pushed_at";
public static final String PUSHED_AT_TASKS = TABLE_ID_PUSHED_AT + "_" + TABLE_ID_TASKS;
public static final String PUSHED_AT_TAGS = TABLE_ID_PUSHED_AT + "_" + TABLE_ID_TAGS;
static {
// Hardcoded local tables mapped to corresponding server names

@ -3,6 +3,7 @@ package com.todoroo.astrid.actfm.sync.messages;
import org.json.JSONObject;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
@ -42,6 +43,8 @@ public abstract class ServerToClientMessage {
return new MakeChanges<Task>(json, PluginServices.getTaskDao());
else if (NameMaps.TABLE_ID_TAGS.equals(table))
return new MakeChanges<TagData>(json, PluginServices.getTagDataDao());
else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table))
return new MakeChanges<RemoteModel>(json, null);
else
return null;
}

Loading…
Cancel
Save