diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java index f6d2b3640..91f2450f2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java @@ -1,5 +1,7 @@ package com.todoroo.astrid.actfm; +import greendroid.widget.AsyncImageView; + import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -21,6 +23,7 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -143,6 +146,7 @@ public class EditPeopleControlSet implements TaskEditControlSet { new Thread(new Runnable() { @Override public void run() { + ArrayList collaborators = new ArrayList(); TodorooCursor tags = TagService.getInstance().getTags(task.getId()); try { Metadata metadata = new Metadata(); @@ -151,23 +155,26 @@ public class EditPeopleControlSet implements TaskEditControlSet { final String tag = metadata.getValue(TagService.TAG); TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT, TagData.MEMBERS, TagData.USER); if(tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - TextView textView = sharedWithContainer.addPerson("#" + tag); - textView.setEnabled(false); - } - }); JSONArray members = new JSONArray(tagData.getValue(TagData.MEMBERS)); - for(int i = 0; i < members.length(); i++) - sharedPeople.add(members.getJSONObject(i)); - if(!TextUtils.isEmpty(tagData.getValue(TagData.USER))) - sharedPeople.add(new JSONObject(tagData.getValue(TagData.USER))); + for(int i = 0; i < members.length(); i++) { + JSONObject user = members.getJSONObject(i); + user.put("tag", tag); + sharedPeople.add(user); + collaborators.add(user); + } + if(!TextUtils.isEmpty(tagData.getValue(TagData.USER))) { + JSONObject user = new JSONObject(tagData.getValue(TagData.USER)); + user.put("tag", tag); + sharedPeople.add(user); + collaborators.add(user); + } } else { nonSharedTags.add((Metadata) metadata.clone()); } } + if(collaborators.size() > 0) + buildCollaborators(collaborators); buildAssignedToSpinner(sharedPeople); } catch (JSONException e) { exceptionService.reportError("json-reading-data", e); @@ -182,6 +189,41 @@ public class EditPeopleControlSet implements TaskEditControlSet { } } + @SuppressWarnings("nls") + private void buildCollaborators(final ArrayList sharedPeople) throws JSONException { + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + HashSet userIds = new HashSet(); + LinearLayout collaborators = (LinearLayout) activity.findViewById(R.id.collaborators); + + for(JSONObject person : sharedPeople) { + if(person == null) + continue; + long id = person.optLong("id", -1); + if(id == 0 || id == ActFmPreferenceService.userId() || (id > -1 && userIds.contains(id))) + continue; + userIds.add(id); + + System.err.println("inflated person: " + person); + View contact = activity.getLayoutInflater().inflate(R.layout.contact_adapter_row, collaborators, false); + AsyncImageView icon = (AsyncImageView) contact.findViewById(android.R.id.icon); + TextView name = (TextView) contact.findViewById(android.R.id.text1); + TextView tag = (TextView) contact.findViewById(android.R.id.text2); + + icon.setUrl(person.optString("picture")); + name.setText(person.optString("name")); + name.setTextAppearance(activity, android.R.style.TextAppearance_Medium); + tag.setText(activity.getString(R.string.actfm_EPA_list, person.optString("tag"))); + tag.setTextAppearance(activity, android.R.style.TextAppearance); + + collaborators.addView(contact); + } + } + }); + } + private class AssignedToUser { public String label; public JSONObject user; @@ -204,14 +246,15 @@ public class EditPeopleControlSet implements TaskEditControlSet { HashSet emails = new HashSet(); HashMap names = new HashMap(); - JSONObject myself = new JSONObject(); - myself.put("id", 0L); - sharedPeople.add(0, myself); if(task.getValue(Task.USER_ID) != 0) { JSONObject user = new JSONObject(task.getValue(Task.USER)); sharedPeople.add(0, user); } + JSONObject myself = new JSONObject(); + myself.put("id", 0L); + sharedPeople.add(0, myself); + // de-duplicate by user id and/or email spinnerValues.clear(); for(int i = 0; i < sharedPeople.size(); i++) { diff --git a/astrid/res/layout/contact_adapter_row.xml b/astrid/res/layout/contact_adapter_row.xml index 93f762844..898732e86 100644 --- a/astrid/res/layout/contact_adapter_row.xml +++ b/astrid/res/layout/contact_adapter_row.xml @@ -1,6 +1,7 @@ - + android:scaleType="fitCenter" + astrid:defaultSrc="@drawable/ic_contact_picture_2" /> + Add Collaborators: + + List: %s + Contact Name