Changed producteev api to use change_labels call instead of set/unset labels

pull/14/head
Tim Su 15 years ago
parent 127cdd081a
commit cded7963f9

@ -12,6 +12,8 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.text.TextUtils;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ProducteevInvoker { public class ProducteevInvoker {
@ -309,6 +311,25 @@ public class ProducteevInvoker {
"id_task", idTask), "labels"); "id_task", idTask), "labels");
} }
/**
* change labels for a task
*
* @param idTask
* @param idLabels
*
* @return array: tasks/view
*/
public JSONObject tasksChangeLabel(long idTask, long... idLabels) throws ApiServiceException, IOException {
Object[] parameters = new Object[2 * (idLabels.length + 2)];
parameters[0] = "token"; parameters[1] = token;
parameters[2] = "id_task"; parameters[3] = idTask;
for(int i = 0; i < idLabels.length; i++) {
parameters[i * 2 + 4] = "id_label[]";
parameters[i * 2 + 5] = idLabels[i];
}
return callAuthenticated("tasks/change_labels.json", parameters);
}
/** /**
* set a labels to a task * set a labels to a task
* *
@ -317,6 +338,7 @@ public class ProducteevInvoker {
* *
* @return array: tasks/view * @return array: tasks/view
*/ */
@Deprecated
public JSONObject tasksSetLabel(long idTask, long idLabel) throws ApiServiceException, IOException { public JSONObject tasksSetLabel(long idTask, long idLabel) throws ApiServiceException, IOException {
return callAuthenticated("tasks/set_label.json", return callAuthenticated("tasks/set_label.json",
"token", token, "token", token,
@ -332,6 +354,7 @@ public class ProducteevInvoker {
* *
* @return array: tasks/view * @return array: tasks/view
*/ */
@Deprecated
public JSONObject tasksUnsetLabel(long idTask, long idLabel) throws ApiServiceException, IOException { public JSONObject tasksUnsetLabel(long idTask, long idLabel) throws ApiServiceException, IOException {
return callAuthenticated("tasks/unset_label.json", return callAuthenticated("tasks/unset_label.json",
"token", token, "token", token,
@ -506,6 +529,9 @@ public class ProducteevInvoker {
return new JSONObject(); return new JSONObject();
} }
try { try {
if(TextUtils.isEmpty(response))
return new JSONObject();
return new JSONObject(response); return new JSONObject(response);
} catch (JSONException e) { } catch (JSONException e) {
System.err.println(response); System.err.println(response);
@ -566,6 +592,8 @@ public class ProducteevInvoker {
String encoded = URLEncoder.encode(value, "UTF-8"); String encoded = URLEncoder.encode(value, "UTF-8");
requestBuilder.append(key).append('=').append(encoded).append('&'); requestBuilder.append(key).append('=').append(encoded).append('&');
if(!key.endsWith("[]"))
sigBuilder.append(key).append(value); sigBuilder.append(key).append(value);
} }

@ -592,30 +592,17 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
} }
if(!localTags.equals(remoteTags)) { if(!localTags.equals(remoteTags)) {
HashSet<String> toAdd = new HashSet<String>(localTags); long[] labels = new long[localTags.size()];
toAdd.removeAll(remoteTags); int index = 0;
HashSet<String> toRemove = remoteTags; for(String label : localTags) {
toRemove.removeAll(localTags);
if(toAdd.size() > 0) {
for(String label : toAdd) {
String pdvLabel = idDashboard + label; String pdvLabel = idDashboard + label;
final long id;
if(!labelMap.containsKey(pdvLabel)) { if(!labelMap.containsKey(pdvLabel)) {
JSONObject result = invoker.labelsCreate(idDashboard, label).getJSONObject("label"); JSONObject result = invoker.labelsCreate(idDashboard, label).getJSONObject("label");
long id = putLabelIntoCache(result); id = putLabelIntoCache(result);
invoker.tasksSetLabel(idTask, id);
} else } else
invoker.tasksSetLabel(idTask, labelMap.get(pdvLabel)); id = labelMap.get(pdvLabel);
} labels[index++] = id;
}
if(toRemove.size() > 0) {
for(String label : toRemove) {
String pdvLabel = idDashboard + label;
if(!labelMap.containsKey(pdvLabel))
continue;
invoker.tasksUnsetLabel(idTask, labelMap.get(pdvLabel));
}
} }
} }
} }

Loading…
Cancel
Save