Check uniqueness of list members by email

pull/14/head
Sam Bosley 12 years ago
parent 42da848122
commit 56fb16aace

@ -1,5 +1,7 @@
package com.todoroo.astrid.ui; package com.todoroo.astrid.ui;
import java.util.HashSet;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -204,6 +206,8 @@ public class PeopleContainer extends LinearLayout {
JSONException, ParseSharedException { JSONException, ParseSharedException {
JSONObject sharedWith = new JSONObject(); JSONObject sharedWith = new JSONObject();
HashSet<String> addedEmails = new HashSet<String>();
JSONArray peopleList = new JSONArray(); JSONArray peopleList = new JSONArray();
for(int i = 0; i < getChildCount(); i++) { for(int i = 0; i < getChildCount(); i++) {
TextView textView = getTextView(i); TextView textView = getTextView(i);
@ -217,9 +221,15 @@ public class PeopleContainer extends LinearLayout {
activity.getString(R.string.actfm_EPA_invalid_email, text)); activity.getString(R.string.actfm_EPA_invalid_email, text));
if (peopleAsJSON) { if (peopleAsJSON) {
JSONObject person = PeopleContainer.createUserJson(textView); JSONObject person = PeopleContainer.createUserJson(textView);
if (person != null) if (person != null) {
peopleList.put(person); String email = person.optString("email");
} else { if (!TextUtils.isEmpty(email) && !addedEmails.contains(email)) {
addedEmails.add(email);
peopleList.put(person);
}
}
} else if (!addedEmails.contains(text)) {
addedEmails.add(text);
peopleList.put(text); peopleList.put(text);
} }
} }

Loading…
Cancel
Save