diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java index 40b090295..b96188da5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java @@ -280,8 +280,21 @@ public class EditPeopleControlSet extends PopupControlSet { } if(Task.isRealUserId(t.getValue(Task.USER_ID))) { - JSONObject user = new JSONObject(t.getValue(Task.USER)); - coreUsersJson.add(0, user); + try { + JSONObject user = new JSONObject(t.getValue(Task.USER)); + coreUsersJson.add(0, user); + } catch (JSONException e) { + User user = userDao.fetch(t.getValue(Task.USER_ID), User.PROPERTIES); + if (user != null) { + try { + JSONObject assignedUser = new JSONObject(); + ActFmSyncService.JsonHelper.jsonFromUser(assignedUser, user); + coreUsersJson.add(0, assignedUser); + } catch (JSONException e2) { + // + } + } + } } ArrayList astridFriends = getAstridFriends(); @@ -400,27 +413,41 @@ public class EditPeopleControlSet extends PopupControlSet { } @SuppressWarnings("nls") - private int findAssignedIndex(Task t, ArrayList... userLists) throws JSONException { + private int findAssignedIndex(Task t, ArrayList... userLists) { String assignedStr = t.getValue(Task.USER); - if (!TextUtils.isEmpty(assignedStr)) { + long assignedId = -2; + String assignedEmail = t.getValue(Task.USER_EMAIL); + try { JSONObject assigned = new JSONObject(assignedStr); - long assignedId = assigned.optLong("id", -2); - String assignedEmail = assigned.optString("email"); + assignedId = assigned.optLong("id", -2); + assignedEmail = assigned.optString("email"); + } catch (JSONException e) { + User assignedUser = userDao.fetch(t.getValue(Task.USER_ID), User.PROPERTIES); + JSONObject assigned = new JSONObject(); + try { + if (assignedUser != null) { + ActFmSyncService.JsonHelper.jsonFromUser(assigned, assignedUser); + assignedId = assigned.optLong("id", -2); + assignedEmail = assigned.optString("email"); + } + } catch (JSONException e2) { + // + } + } - int index = 0; - for (ArrayList userList : userLists) { - for (int i = 0; i < userList.size(); i++) { - JSONObject user = userList.get(i).user; - if (user != null) { - if (user.optLong("id") == assignedId || - (user.optString("email").equals(assignedEmail) && - !(TextUtils.isEmpty(assignedEmail)))) - return index; - } - index++; + int index = 0; + for (ArrayList userList : userLists) { + for (int i = 0; i < userList.size(); i++) { + JSONObject user = userList.get(i).user; + if (user != null) { + if (user.optLong("id") == assignedId || + (user.optString("email").equals(assignedEmail) && + !(TextUtils.isEmpty(assignedEmail)))) + return index; } - index++; // Add one for headers separating user lists + index++; } + index++; // Add one for headers separating user lists } return 0; } diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 977ec4742..4762152ee 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -37,7 +37,6 @@ import android.text.Spanned; import android.text.TextUtils; import android.text.TextUtils.TruncateAt; import android.util.DisplayMetrics; -import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -1131,7 +1130,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { // image view final AsyncImageView pictureView = viewHolder.picture; { if (pictureView != null) { - if(task.getValue(Task.USER_ID) == Task.USER_ID_SELF && !viewHolder.isTaskRabbit) { + if(Task.USER_ID_SELF.equals(task.getValue(Task.USER_ID)) && !viewHolder.isTaskRabbit) { pictureView.setVisibility(View.GONE); if (viewHolder.pictureBorder != null) viewHolder.pictureBorder.setVisibility(View.GONE); @@ -1142,16 +1141,17 @@ public class TaskAdapter extends CursorAdapter implements Filterable { pictureView.setUrl(null); if (viewHolder.isTaskRabbit) { pictureView.setDefaultImageResource(R.drawable.task_rabbit_image); - } else if(task.getValue(Task.USER_ID) == Task.USER_ID_UNASSIGNED) + } else if(Task.USER_ID_UNASSIGNED.equals(task.getValue(Task.USER_ID))) pictureView.setDefaultImageResource(R.drawable.icn_anyone_transparent); else { pictureView.setDefaultImageResource(R.drawable.icn_default_person_image); - // TODO: Implement a join here try { JSONObject user = new JSONObject(task.getValue(Task.USER)); pictureView.setUrl(user.optString("picture")); //$NON-NLS-1$ } catch (JSONException e) { - Log.w("astrid", "task-adapter-image", e); //$NON-NLS-1$ //$NON-NLS-2$ + if (Task.isRealUserId(task.getValue(Task.USER_ID))) { + // TODO: Implement a join here + } } } }