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.JSONObject;
import android.text.TextUtils;
@SuppressWarnings("nls")
public class ProducteevInvoker {
@ -309,6 +311,25 @@ public class ProducteevInvoker {
"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
*
@ -317,6 +338,7 @@ public class ProducteevInvoker {
*
* @return array: tasks/view
*/
@Deprecated
public JSONObject tasksSetLabel(long idTask, long idLabel) throws ApiServiceException, IOException {
return callAuthenticated("tasks/set_label.json",
"token", token,
@ -332,6 +354,7 @@ public class ProducteevInvoker {
*
* @return array: tasks/view
*/
@Deprecated
public JSONObject tasksUnsetLabel(long idTask, long idLabel) throws ApiServiceException, IOException {
return callAuthenticated("tasks/unset_label.json",
"token", token,
@ -506,6 +529,9 @@ public class ProducteevInvoker {
return new JSONObject();
}
try {
if(TextUtils.isEmpty(response))
return new JSONObject();
return new JSONObject(response);
} catch (JSONException e) {
System.err.println(response);
@ -566,7 +592,9 @@ public class ProducteevInvoker {
String encoded = URLEncoder.encode(value, "UTF-8");
requestBuilder.append(key).append('=').append(encoded).append('&');
sigBuilder.append(key).append(value);
if(!key.endsWith("[]"))
sigBuilder.append(key).append(value);
}
sigBuilder.append(apiSecret);

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

Loading…
Cancel
Save