From 586fc12a5e7140f4a4ae3b81f286314c18f2b5f1 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 20 Mar 2013 14:53:13 -0700 Subject: [PATCH] Adjusted error handling to match the actual format of errors --- .../astrid/actfm/CommentsFragment.java | 3 ++- .../todoroo/astrid/actfm/TagViewFragment.java | 8 +++---- .../astrid/actfm/sync/ActFmSyncThread.java | 23 +++++++++---------- .../astrid/notes/EditNoteActivity.java | 3 ++- .../astrid/people/PersonViewFragment.java | 4 ++-- astrid/res/values/strings-actfm.xml | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java index ef774c2c3..bee56e708 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/CommentsFragment.java @@ -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 errors) {/**/} + public void runOnErrors(List errors) {/**/} }; if (hasModel()) { performFetch(manual, doneRunnable); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index 690679a54..96cf11755 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -371,12 +371,12 @@ public class TagViewFragment extends TaskListFragment { } } @Override - public void runOnErrors(List errors) { + public void runOnErrors(List 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, 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 e5d1d9d8a..676358aa8 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java @@ -120,7 +120,7 @@ public class ActFmSyncThread { public static interface SyncMessageCallback { public void runOnSuccess(); - public void runOnErrors(List errors); + public void runOnErrors(List errors); } public static enum ModelType { @@ -282,7 +282,7 @@ public class ActFmSyncThread { } @Override - public void runOnErrors(List errors) {/**/} + public void runOnErrors(List errors) {/**/} }; @SuppressWarnings("nls") @@ -382,14 +382,14 @@ public class ActFmSyncThread { } Set callbacksExecutedThisLoop = new HashSet(); - Map> errorMap = buildErrorMap(errors); + Map> 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 errorList = errorMap.get(i); + List errorList = errorMap.get(i); if (errorList == null || errorList.isEmpty()) r.runOnSuccess(); else @@ -415,19 +415,18 @@ public class ActFmSyncThread { } - private Map> buildErrorMap(JSONArray errors) { - Map> result = new HashMap>(); + private Map> buildErrorMap(JSONArray errors) { + Map> result = new HashMap>(); 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 errorList = result.get(index); + JSONArray error = errors.optJSONArray(i); + if (error != null && error.length() > 0) { + int index = error.optInt(0); + List errorList = result.get(index); if (errorList == null) { - errorList = new LinkedList(); + errorList = new LinkedList(); result.put(index, errorList); } - error.remove("index"); //$NON-NLS-1$ errorList.add(error); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index 3bfd0b246..2d78fc5ed 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -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 errors) {/**/} + public void runOnErrors(List errors) {/**/} }; ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(UserActivity.class, null, task.getValue(Task.USER_ACTIVITIES_PUSHED_AT), BriefMe.TASK_ID_KEY, task.getUuid()), callback); diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java index 4555289f7..cbf383b8d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java @@ -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 errors) {/**/} + public void runOnErrors(List errors) {/**/} }; ActFmSyncThread.getInstance().enqueueMessage(new BriefMe(User.class, user.getValue(User.UUID), user.getValue(User.PUSHED_AT)), callback); } diff --git a/astrid/res/values/strings-actfm.xml b/astrid/res/values/strings-actfm.xml index b1650b3e7..beb9d1170 100644 --- a/astrid/res/values/strings-actfm.xml +++ b/astrid/res/values/strings-actfm.xml @@ -370,7 +370,7 @@ Processing existing data... Not authorized - 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? + 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? Create new list Leave list