|
|
|
|
@ -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,20 +45,44 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
|
|
|
|
|
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;
|
|
|
|
|
else if (NameMaps.TABLE_ID_USERS.equals(table))
|
|
|
|
|
pushedAtKey = NameMaps.PUSHED_AT_USERS;
|
|
|
|
|
else if (NameMaps.TABLE_ID_TASK_LIST_METADATA.equals(table))
|
|
|
|
|
pushedAtKey = NameMaps.PUSHED_AT_TASK_LIST_METADATA;
|
|
|
|
|
|
|
|
|
|
if (pushedAtKey != null)
|
|
|
|
|
Preferences.setLong(pushedAtKey, pushedAt);
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
else if (NameMaps.TABLE_ID_USERS.equals(table))
|
|
|
|
|
pushedAtKey = NameMaps.PUSHED_AT_USERS;
|
|
|
|
|
else if (NameMaps.TABLE_ID_TASK_LIST_METADATA.equals(table))
|
|
|
|
|
pushedAtKey = NameMaps.PUSHED_AT_TASK_LIST_METADATA;
|
|
|
|
|
|
|
|
|
|
if (pushedAtKey != null)
|
|
|
|
|
Preferences.setLong(pushedAtKey, pushedAt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
|