Fix for contacts get auutoloaded, add them as collaborators

pull/14/head
Tim Su 15 years ago
parent bb8d4ec060
commit 0153ec1bda

@ -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<JSONObject> collaborators = new ArrayList<JSONObject>();
TodorooCursor<Metadata> 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<JSONObject> sharedPeople) throws JSONException {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
HashSet<Long> userIds = new HashSet<Long>();
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<String> emails = new HashSet<String>();
HashMap<String, AssignedToUser> names = new HashMap<String, AssignedToUser>();
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++) {

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- See the file "LICENSE" for the full license governing this code. -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:astrid="http://schemas.android.com/apk/res/com.timsu.astrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/list_selector_background"
@ -9,17 +10,18 @@
android:orientation="horizontal">
<!-- picture thumbnail -->
<ImageView android:id="@android:id/icon"
<greendroid.widget.AsyncImageView android:id="@android:id/icon"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_height="44dip"
android:gravity="center"
android:scaleType="fitCenter" />
android:scaleType="fitCenter"
astrid:defaultSrc="@drawable/ic_contact_picture_2" />
<!-- person name -->
<TextView android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"
android:layout_marginLeft="55dip"
style="@android:attr/dropDownItemStyle"
android:textAppearance="@android:attr/textAppearanceLargeInverse"
android:singleLine="true"
@ -29,7 +31,7 @@
<TextView android:id="@android:id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"
android:layout_marginLeft="55dip"
android:layout_below="@android:id/text1"
style="@android:attr/dropDownItemStyle"
android:textAppearance="@android:attr/textAppearanceInverse"

@ -265,6 +265,12 @@
android:layout_height="1dip"
android:background="@android:drawable/divider_horizontal_dark" />
</LinearLayout>
<LinearLayout
android:id="@+id/collaborators"
android:orientation="vertical"
android:padding="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/checkbox_facebook"
android:text="@string/actfm_EPA_facebook"

@ -90,6 +90,9 @@
<!-- task sharing dialog: shared with label -->
<string name="actfm_EPA_share_with">Add Collaborators:</string>
<!-- task sharing dialog: collaborator list name (%s => name of list) -->
<string name="actfm_EPA_list">List: %s</string>
<!-- task sharing dialog: assigned hint -->
<string name="actfm_EPA_assigned_hint">Contact Name</string>

Loading…
Cancel
Save