Implement NowBriefed message

pull/14/head
Sam Bosley 13 years ago
parent 0f4b94011b
commit 1e9839b4b6

@ -1,6 +1,5 @@
package com.todoroo.astrid.actfm.sync.messages;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
@ -16,8 +15,6 @@ import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.sql.Criterion;
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.dao.TagMetadataDao;
@ -89,26 +86,6 @@ 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)) {
long tablePushedAt = 0;
try {
tablePushedAt = DateUtilities.parseIso8601(changes.optString(NameMaps.TABLE_ID_PUSHED_AT));
} catch (ParseException e) {
//
}
if (tablePushedAt > 0) {
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;
else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(uuid))
pushedAtKey = NameMaps.PUSHED_AT_ACTIVITY;
if (pushedAtKey != null)
Preferences.setLong(pushedAtKey, tablePushedAt);
}
}
}
}

@ -0,0 +1,66 @@
package com.todoroo.astrid.actfm.sync.messages;
import java.text.ParseException;
import org.json.JSONObject;
import android.text.TextUtils;
import android.util.Log;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.RemoteModelDao;
import com.todoroo.astrid.data.RemoteModel;
@SuppressWarnings("nls")
public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage {
private static final String ERROR_TAG = "actfm-now-briefed";
private final RemoteModelDao<TYPE> dao;
private final String table;
private final String uuid;
private long pushedAt;
public NowBriefed(JSONObject json, RemoteModelDao<TYPE> dao) {
super(json);
this.table = json.optString("table");
this.uuid = json.optString("uuid");
this.dao = dao;
try {
this.pushedAt = DateUtilities.parseIso8601(json.optString("pushed_at"));
} catch (ParseException e) {
this.pushedAt = 0;
}
}
@Override
public void processMessage() {
if (pushedAt > 0) {
if (TextUtils.isEmpty(uuid)) {
String pushedAtKey = null;
if (NameMaps.TABLE_ID_TASKS.equals(table))
pushedAtKey = NameMaps.PUSHED_AT_TASKS;
else if (NameMaps.TABLE_ID_TAGS.equals(table))
pushedAtKey = NameMaps.PUSHED_AT_TAGS;
else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table))
pushedAtKey = NameMaps.PUSHED_AT_ACTIVITY;
if (pushedAtKey != null)
Preferences.setLong(pushedAtKey, pushedAt);
} else {
try {
TYPE instance = dao.getModelClass().newInstance();
instance.setValue(RemoteModel.PUSHED_AT_PROPERTY, pushedAt);
dao.update(RemoteModel.UUID_PROPERTY.eq(uuid), instance);
} catch (IllegalAccessException e) {
Log.e(ERROR_TAG, "Error instantiating model for NowBriefed", e);
} catch (InstantiationException e) {
Log.e(ERROR_TAG, "Error instantiating model for NowBriefed", e);
}
}
}
}
}

@ -3,7 +3,6 @@ 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;
import com.todoroo.astrid.data.User;
@ -15,6 +14,7 @@ public abstract class ServerToClientMessage {
public abstract void processMessage();
public static final String TYPE_MAKE_CHANGES = "MakeChanges";
public static final String TYPE_NOW_BRIEFED = "NowBriefed";
public static final String TYPE_ACKNOWLEDGE_CHANGE = "AcknowledgeChange";
public static final String TYPE_USER_DATA = "UserData";
public static final String TYPE_DOUBLE_CHECK = "DoubleCheck";
@ -30,6 +30,8 @@ public abstract class ServerToClientMessage {
String type = json.optString("type");
if (TYPE_MAKE_CHANGES.equals(type))
return instantiateMakeChanges(json, pushedAt);
else if (TYPE_NOW_BRIEFED.equals(type))
return instantiateNowBriefed(json);
else if (TYPE_ACKNOWLEDGE_CHANGE.equals(type))
return new AcknowledgeChange(json);
else if (TYPE_USER_DATA.equals(type))
@ -52,8 +54,18 @@ public abstract class ServerToClientMessage {
return new MakeChanges<User>(json, PluginServices.getUserDao(), pushedAt);
else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table))
return new MakeChanges<UserActivity>(json, PluginServices.getUserActivityDao(), pushedAt);
else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table))
return new MakeChanges<RemoteModel>(json, null, 0);
else
return null;
}
private static NowBriefed<?> instantiateNowBriefed(JSONObject json) {
String table = json.optString("table");
if (NameMaps.TABLE_ID_TASKS.equals(table))
return new NowBriefed<Task>(json, PluginServices.getTaskDao());
else if (NameMaps.TABLE_ID_TAGS.equals(table))
return new NowBriefed<TagData>(json, PluginServices.getTagDataDao());
else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table))
return new NowBriefed<UserActivity>(json, PluginServices.getUserActivityDao());
else
return null;
}

Loading…
Cancel
Save