diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java index 2f4725c20..23853d869 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java @@ -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 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); - - } } } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java new file mode 100644 index 000000000..3292a8d7e --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java @@ -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 extends ServerToClientMessage { + + private static final String ERROR_TAG = "actfm-now-briefed"; + + private final RemoteModelDao dao; + private final String table; + private final String uuid; + private long pushedAt; + + public NowBriefed(JSONObject json, RemoteModelDao 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); + } + } + } + } + +} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java index 7d98ccdc8..a5394bded 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java @@ -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(json, PluginServices.getUserDao(), pushedAt); else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table)) return new MakeChanges(json, PluginServices.getUserActivityDao(), pushedAt); - else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table)) - return new MakeChanges(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(json, PluginServices.getTaskDao()); + else if (NameMaps.TABLE_ID_TAGS.equals(table)) + return new NowBriefed(json, PluginServices.getTagDataDao()); + else if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(table)) + return new NowBriefed(json, PluginServices.getUserActivityDao()); else return null; }