Implemented AcknowledgeChange

pull/14/head
Sam Bosley 12 years ago
parent d4b02c174b
commit af5921a175

@ -1,17 +1,62 @@
package com.todoroo.astrid.actfm.sync.messages; package com.todoroo.astrid.actfm.sync.messages;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.text.TextUtils;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.dao.OutstandingEntryDao;
import com.todoroo.astrid.dao.TagOutstandingDao;
import com.todoroo.astrid.dao.TaskOutstandingDao;
public class AcknowledgeChange extends ServerToClientMessage { public class AcknowledgeChange extends ServerToClientMessage {
@Autowired
private TaskOutstandingDao taskOutstandingDao;
@Autowired
private TagOutstandingDao tagOutstandingDao;
public AcknowledgeChange(JSONObject json) { public AcknowledgeChange(JSONObject json) {
super(json); super(json);
throw new RuntimeException("No constructor for AcknowledgeChange implemented"); //$NON-NLS-1$ DependencyInjectionService.getInstance().inject(this);
} }
@Override @Override
@SuppressWarnings("nls")
public void processMessage() { public void processMessage() {
// TODO Auto-generated method stub JSONArray idsArray = json.optJSONArray("ids");
String table = json.optString("table");
if (idsArray != null && !TextUtils.isEmpty(table)) {
OutstandingEntryDao<?> dao = null;
if (NameMaps.SERVER_TABLE_TASKS.equals(table))
dao = taskOutstandingDao;
else if (NameMaps.SERVER_TABLE_TAGS.equals(table))
dao = tagOutstandingDao;
if (dao == null)
return;
ArrayList<Long> idsList = new ArrayList<Long>();
for (int i = 0; i < idsArray.length(); i++) {
try {
Long id = idsArray.getLong(i);
if (id <= 0)
continue;
idsList.add(id);
} catch (JSONException e) {
//
}
}
dao.deleteWhere(AbstractModel.ID_PROPERTY.in(idsList.toArray(new Long[idsList.size()])));
}
} }
} }

@ -18,12 +18,16 @@ public class NameMaps {
private static final Map<Table, String> TABLE_LOCAL_TO_SERVER; private static final Map<Table, String> TABLE_LOCAL_TO_SERVER;
private static final Map<String, Table> TABLE_SERVER_TO_LOCAL; private static final Map<String, Table> TABLE_SERVER_TO_LOCAL;
public static final String SERVER_TABLE_TASKS = "tasks";
public static final String SERVER_TABLE_TAGS = "tags";
public static final String SERVER_TABLE_USERS = "users";
static { static {
// Hardcoded local tables mapped to corresponding server names // Hardcoded local tables mapped to corresponding server names
TABLE_LOCAL_TO_SERVER = new HashMap<Table, String>(); TABLE_LOCAL_TO_SERVER = new HashMap<Table, String>();
TABLE_LOCAL_TO_SERVER.put(Task.TABLE, "tasks"); TABLE_LOCAL_TO_SERVER.put(Task.TABLE, SERVER_TABLE_TASKS);
TABLE_LOCAL_TO_SERVER.put(TagData.TABLE, "tags"); TABLE_LOCAL_TO_SERVER.put(TagData.TABLE, SERVER_TABLE_TAGS);
TABLE_LOCAL_TO_SERVER.put(User.TABLE, "users"); TABLE_LOCAL_TO_SERVER.put(User.TABLE, SERVER_TABLE_USERS);
// Reverse the mapping to construct the server to local map // Reverse the mapping to construct the server to local map
TABLE_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(TABLE_LOCAL_TO_SERVER); TABLE_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(TABLE_LOCAL_TO_SERVER);

@ -12,9 +12,10 @@ public abstract class ServerToClientMessage {
private static final String TYPE_DOUBLE_CHECK = "DoubleCheck"; private static final String TYPE_DOUBLE_CHECK = "DoubleCheck";
private static final String TYPE_DEBUG = "Debug"; private static final String TYPE_DEBUG = "Debug";
@SuppressWarnings("unused") protected final JSONObject json;
public ServerToClientMessage(JSONObject json) { public ServerToClientMessage(JSONObject json) {
// this.json = json;
} }
public static ServerToClientMessage instantiateMessage(JSONObject json) { public static ServerToClientMessage instantiateMessage(JSONObject json) {

Loading…
Cancel
Save