diff --git a/api/src/com/todoroo/andlib/data/Property.java b/api/src/com/todoroo/andlib/data/Property.java index ae255c796..e481eb662 100644 --- a/api/src/com/todoroo/andlib/data/Property.java +++ b/api/src/com/todoroo/andlib/data/Property.java @@ -49,6 +49,8 @@ public abstract class Property extends Field implements Cloneable { public static final int PROP_FLAG_BOOLEAN = 1 << 3; /** Is this field a serialized JSON object? */ public static final int PROP_FLAG_JSON = 1 << 4; + /** Is this field for pictures? (usually as a json object containing "path" key or urls) */ + public static final int PROP_FLAG_PICTURE = 1 << 5; public int flags = 0; diff --git a/api/src/com/todoroo/astrid/data/TagData.java b/api/src/com/todoroo/astrid/data/TagData.java index 797f8b2d6..8002f79cc 100644 --- a/api/src/com/todoroo/astrid/data/TagData.java +++ b/api/src/com/todoroo/astrid/data/TagData.java @@ -63,7 +63,7 @@ public final class TagData extends RemoteModel { /** Project picture */ public static final StringProperty PICTURE = new StringProperty( - TABLE, "picture", Property.PROP_FLAG_JSON); + TABLE, "picture", Property.PROP_FLAG_JSON | Property.PROP_FLAG_PICTURE); /** Tag team array (JSON) */ @Deprecated public static final StringProperty MEMBERS = new StringProperty( diff --git a/api/src/com/todoroo/astrid/data/UserActivity.java b/api/src/com/todoroo/astrid/data/UserActivity.java index 87b9712b5..590c13e39 100644 --- a/api/src/com/todoroo/astrid/data/UserActivity.java +++ b/api/src/com/todoroo/astrid/data/UserActivity.java @@ -54,7 +54,7 @@ public class UserActivity extends RemoteModel { /** Picture */ public static final StringProperty PICTURE = new StringProperty( - TABLE, "picture", Property.PROP_FLAG_JSON); + TABLE, "picture", Property.PROP_FLAG_JSON | Property.PROP_FLAG_PICTURE); /** Target id */ public static final StringProperty TARGET_ID = new StringProperty( diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java index 72d20a464..826376659 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java @@ -12,14 +12,12 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.List; import java.util.TimeZone; import org.apache.commons.codec.digest.DigestUtils; import org.apache.http.HttpEntity; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.message.BasicNameValuePair; -import org.apache.http.protocol.HTTP; +import org.apache.http.entity.mime.MultipartEntity; +import org.apache.http.entity.mime.content.StringBody; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -185,7 +183,7 @@ public class ActFmInvoker { } } - public JSONObject postSync(JSONArray data, String token) throws IOException, + public JSONObject postSync(JSONArray data, MultipartEntity entity, String token) throws IOException, ActFmServiceException { try { String dataString = data.toString(); @@ -194,11 +192,9 @@ public class ActFmInvoker { String request = createFetchUrl("api/" + API_VERSION, "synchronize", "token", token, "data", dataString, "time", timeString); if (SYNC_DEBUG) Log.e("act-fm-post", request); - List pairs = new ArrayList(); - pairs.add(new BasicNameValuePair("token", token)); - pairs.add(new BasicNameValuePair("data", data.toString())); - pairs.add(new BasicNameValuePair("time", timeString)); - UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, HTTP.UTF_8); + entity.addPart("token", new StringBody(token)); + entity.addPart("data", new StringBody(data.toString())); + entity.addPart("time", new StringBody(timeString)); String response = restClient.post(request, entity); JSONObject object = new JSONObject(response); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java index 0dbf3531e..b35901526 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.http.entity.mime.MultipartEntity; import org.json.JSONArray; import org.json.JSONObject; @@ -295,8 +296,9 @@ public class ActFmSyncThread { if (!messageBatch.isEmpty() && checkForToken()) { JSONArray payload = new JSONArray(); + MultipartEntity entity = new MultipartEntity(); for (ClientToServerMessage message : messageBatch) { - JSONObject serialized = message.serializeToJSON(); + JSONObject serialized = message.serializeToJSON(entity); if (serialized != null) { payload.put(serialized); syncLog("Sending: " + serialized); @@ -309,7 +311,7 @@ public class ActFmSyncThread { continue; try { - JSONObject response = actFmInvoker.postSync(payload, token); + JSONObject response = actFmInvoker.postSync(payload, entity, token); // process responses JSONArray serverMessagesJson = response.optJSONArray("messages"); if (serverMessagesJson != null) { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java index 4cfb89933..7c74ee98f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java @@ -1,5 +1,6 @@ package com.todoroo.astrid.actfm.sync.messages; +import org.apache.http.entity.mime.MultipartEntity; import org.json.JSONException; import org.json.JSONObject; @@ -34,7 +35,7 @@ public class BriefMe extends ClientToServerMessage 0) { for (int i = 0; i < extraParameters.length - 1; i++) { try { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java index aa16200a2..acddf7607 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java @@ -4,6 +4,8 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import org.apache.http.entity.mime.MultipartEntity; +import org.apache.http.entity.mime.content.FileBody; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -80,9 +82,9 @@ public class ChangesHappened { return pushedAt; } - public final JSONObject serializeToJSON() { + public final JSONObject serializeToJSON(MultipartEntity entity) { JSONObject json = new JSONObject(); try { json.put(TYPE_KEY, getTypeString()); @@ -69,7 +70,7 @@ public abstract class ClientToServerMessage { json.put(UUID_KEY, uuid); String dateValue = DateUtilities.timeToIso8601(pushedAt, true); json.put(PUSHED_AT_KEY, dateValue != null ? dateValue : 0); - if (serializeExtrasToJSON(json)) + if (serializeExtrasToJSON(json, entity)) return json; else return null; @@ -109,6 +110,6 @@ public abstract class ClientToServerMessage { return true; } - protected abstract boolean serializeExtrasToJSON(JSONObject serializeTo) throws JSONException; + protected abstract boolean serializeExtrasToJSON(JSONObject serializeTo, MultipartEntity entity) throws JSONException; protected abstract String getTypeString(); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java index 0f70b0da8..5f405f783 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java @@ -1,5 +1,6 @@ package com.todoroo.astrid.actfm.sync.messages; +import org.apache.http.entity.mime.MultipartEntity; import org.json.JSONException; import org.json.JSONObject; @@ -13,7 +14,7 @@ public class RequestDoubleCheck extends ClientToServer } @Override - protected boolean serializeExtrasToJSON(JSONObject serializeTo) throws JSONException { + protected boolean serializeExtrasToJSON(JSONObject serializeTo, MultipartEntity entity) throws JSONException { // No extras return true; }