|
|
|
|
@ -13,11 +13,9 @@ import com.todoroo.andlib.service.Autowired;
|
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
|
import com.todoroo.andlib.utility.Preferences;
|
|
|
|
|
import com.todoroo.astrid.data.RemoteModel;
|
|
|
|
|
import com.todoroo.astrid.data.TagData;
|
|
|
|
|
import com.todoroo.astrid.data.User;
|
|
|
|
|
import com.todoroo.astrid.service.TagDataService;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
@ -82,8 +80,7 @@ public final class ActFmSyncService {
|
|
|
|
|
/**
|
|
|
|
|
* invoke authenticated method against the server
|
|
|
|
|
*/
|
|
|
|
|
public JSONObject invoke(String method, Object... getParameters) throws IOException,
|
|
|
|
|
ActFmServiceException {
|
|
|
|
|
public JSONObject invoke(String method, Object... getParameters) throws IOException {
|
|
|
|
|
if (!checkForToken()) {
|
|
|
|
|
throw new ActFmServiceException("not logged in", null);
|
|
|
|
|
}
|
|
|
|
|
@ -115,10 +112,6 @@ public final class ActFmSyncService {
|
|
|
|
|
*/
|
|
|
|
|
public static class JsonHelper {
|
|
|
|
|
|
|
|
|
|
protected static long readDate(JSONObject item, String key) {
|
|
|
|
|
return item.optLong(key, 0) * 1000L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void jsonFromUser(JSONObject json, User model) throws JSONException {
|
|
|
|
|
json.put("id", model.getValue(User.UUID));
|
|
|
|
|
json.put("name", model.getDisplayName());
|
|
|
|
|
@ -126,49 +119,6 @@ public final class ActFmSyncService {
|
|
|
|
|
json.put("picture", model.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_THUMB));
|
|
|
|
|
json.put("first_name", model.getValue(User.FIRST_NAME));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void featuredListFromJson(JSONObject json, TagData model) throws JSONException {
|
|
|
|
|
parseTagDataFromJson(json, model, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void parseTagDataFromJson(JSONObject json, TagData model, boolean featuredList) throws JSONException {
|
|
|
|
|
model.clearValue(TagData.UUID);
|
|
|
|
|
model.setValue(TagData.UUID, Long.toString(json.getLong("id")));
|
|
|
|
|
model.setValue(TagData.NAME, json.getString("name"));
|
|
|
|
|
|
|
|
|
|
if (featuredList) {
|
|
|
|
|
model.setFlag(TagData.FLAGS, TagData.FLAG_FEATURED, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json.has("picture")) {
|
|
|
|
|
model.setValue(TagData.PICTURE, json.optString("picture", ""));
|
|
|
|
|
}
|
|
|
|
|
if (json.has("thumb")) {
|
|
|
|
|
model.setValue(TagData.THUMB, json.optString("thumb", ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json.has("is_silent")) {
|
|
|
|
|
model.setFlag(TagData.FLAGS, TagData.FLAG_SILENT, json.getBoolean("is_silent"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!json.isNull("description")) {
|
|
|
|
|
model.setValue(TagData.TAG_DESCRIPTION, json.getString("description"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json.has("members")) {
|
|
|
|
|
JSONArray members = json.getJSONArray("members");
|
|
|
|
|
model.setValue(TagData.MEMBERS, members.toString());
|
|
|
|
|
model.setValue(TagData.MEMBER_COUNT, members.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json.has("deleted_at")) {
|
|
|
|
|
model.setValue(TagData.DELETION_DATE, readDate(json, "deleted_at"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json.has("tasks")) {
|
|
|
|
|
model.setValue(TagData.TASK_COUNT, json.getInt("tasks"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|