Adjusted error handling to match the actual format of errors

pull/14/head
Sam Bosley 12 years ago
parent 5d7c392d39
commit 586fc12a5e

@ -7,6 +7,7 @@ package com.todoroo.astrid.actfm;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
@ -287,7 +288,7 @@ public abstract class CommentsFragment extends SherlockListFragment {
}
@Override
public void runOnErrors(List<JSONObject> errors) {/**/}
public void runOnErrors(List<JSONArray> errors) {/**/}
};
if (hasModel()) {
performFetch(manual, doneRunnable);

@ -371,12 +371,12 @@ public class TagViewFragment extends TaskListFragment {
}
}
@Override
public void runOnErrors(List<JSONObject> errors) {
public void runOnErrors(List<JSONArray> errors) {
Activity activity = getActivity();
if (activity != null && activity instanceof TaskListActivity) {
boolean notAuthorized = false;
for (JSONObject error : errors) {
String errorCode = error.optString("code"); //$NON-NLS-1$
for (JSONArray error : errors) {
String errorCode = error.optString(1);
if ("not_authorized".equals(errorCode)) { //$NON-NLS-1$
notAuthorized = true;
break;
@ -391,7 +391,7 @@ public class TagViewFragment extends TaskListFragment {
public void run() {
DialogUtilities.okCancelCustomDialog(tla,
tla.getString(R.string.actfm_tag_not_authorized_title),
tla.getString(R.string.actfm_tag_not_authorized_body),
tla.getString(R.string.actfm_tag_not_authorized_body, tagName),
R.string.actfm_tag_not_authorized_new_list,
R.string.actfm_tag_not_authorized_leave_list,
android.R.drawable.ic_dialog_alert,

@ -120,7 +120,7 @@ public class ActFmSyncThread {
public static interface SyncMessageCallback {
public void runOnSuccess();
public void runOnErrors(List<JSONObject> errors);
public void runOnErrors(List<JSONArray> errors);
}
public static enum ModelType {
@ -282,7 +282,7 @@ public class ActFmSyncThread {
}
@Override
public void runOnErrors(List<JSONObject> errors) {/**/}
public void runOnErrors(List<JSONArray> errors) {/**/}
};
@SuppressWarnings("nls")
@ -382,14 +382,14 @@ public class ActFmSyncThread {
}
Set<SyncMessageCallback> callbacksExecutedThisLoop = new HashSet<SyncMessageCallback>();
Map<Integer, List<JSONObject>> errorMap = buildErrorMap(errors);
Map<Integer, List<JSONArray>> errorMap = buildErrorMap(errors);
for (int i = 0; i < messageBatch.size(); i++) {
ClientToServerMessage<?> message = messageBatch.get(i);
incrementProgress();
try {
SyncMessageCallback r = pendingCallbacks.remove(message);
if (r != null && !callbacksExecutedThisLoop.contains(r)) {
List<JSONObject> errorList = errorMap.get(i);
List<JSONArray> errorList = errorMap.get(i);
if (errorList == null || errorList.isEmpty())
r.runOnSuccess();
else
@ -415,19 +415,18 @@ public class ActFmSyncThread {
}
private Map<Integer, List<JSONObject>> buildErrorMap(JSONArray errors) {
Map<Integer, List<JSONObject>> result = new HashMap<Integer, List<JSONObject>>();
private Map<Integer, List<JSONArray>> buildErrorMap(JSONArray errors) {
Map<Integer, List<JSONArray>> result = new HashMap<Integer, List<JSONArray>>();
if (errors != null) {
for (int i = 0; i < errors.length(); i++) {
JSONObject error = errors.optJSONObject(i);
if (error != null && error.has("index")) { //$NON-NLS-1$
int index = error.optInt("index"); //$NON-NLS-1$
List<JSONObject> errorList = result.get(index);
JSONArray error = errors.optJSONArray(i);
if (error != null && error.length() > 0) {
int index = error.optInt(0);
List<JSONArray> errorList = result.get(index);
if (errorList == null) {
errorList = new LinkedList<JSONObject>();
errorList = new LinkedList<JSONArray>();
result.put(index, errorList);
}
error.remove("index"); //$NON-NLS-1$
errorList.add(error);
}
}

@ -12,6 +12,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
@ -431,7 +432,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
}
}
@Override
public void runOnErrors(List<JSONObject> errors) {/**/}
public void runOnErrors(List<JSONArray> errors) {/**/}
};
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<UserActivity>(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback);

@ -7,7 +7,7 @@ package com.todoroo.astrid.people;
import java.util.List;
import org.json.JSONObject;
import org.json.JSONArray;
import android.app.Activity;
import android.content.ContentValues;
@ -222,7 +222,7 @@ public class PersonViewFragment extends TaskListFragment {
}
}
@Override
public void runOnErrors(List<JSONObject> errors) {/**/}
public void runOnErrors(List<JSONArray> errors) {/**/}
};
ActFmSyncThread.getInstance().enqueueMessage(new BriefMe<User>(User.class, user.getValue(User.UUID), user.getValue(User.PUSHED_AT)), callback);
}

@ -370,7 +370,7 @@
<string name="actfm_logged_in_different_user_processing">Processing existing data...</string>
<string name="actfm_tag_not_authorized_title">Not authorized</string>
<string name="actfm_tag_not_authorized_body">You are no longer authorized to view this list (you may have been removed). Would you like to create a new list with the same name?</string>
<string name="actfm_tag_not_authorized_body">You are no longer authorized to view list %s (you may have been removed). Would you like to create a new list with the same name?</string>
<string name="actfm_tag_not_authorized_new_list">Create new list</string>
<string name="actfm_tag_not_authorized_leave_list">Leave list</string>

Loading…
Cancel
Save