|
|
|
@ -7,6 +7,7 @@ import org.json.JSONObject;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Editable;
|
|
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
@ -19,6 +20,8 @@ import android.widget.TextView;
|
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
|
|
|
|
|
|
|
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.utility.Preferences;
|
|
|
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
|
|
|
|
|
|
|
|
|
|
|
public class PeopleContainer extends LinearLayout {
|
|
|
|
public class PeopleContainer extends LinearLayout {
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,6 +55,7 @@ public class PeopleContainer extends LinearLayout {
|
|
|
|
|
|
|
|
|
|
|
|
/** Adds a tag to the tag field */
|
|
|
|
/** Adds a tag to the tag field */
|
|
|
|
public TextView addPerson(String person) {
|
|
|
|
public TextView addPerson(String person) {
|
|
|
|
|
|
|
|
System.err.println("ADD PERSON: " + person);
|
|
|
|
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
|
// check if already exists
|
|
|
|
// check if already exists
|
|
|
|
@ -64,7 +68,7 @@ public class PeopleContainer extends LinearLayout {
|
|
|
|
|
|
|
|
|
|
|
|
final View tagItem = inflater.inflate(R.layout.contact_edit_row, null);
|
|
|
|
final View tagItem = inflater.inflate(R.layout.contact_edit_row, null);
|
|
|
|
if(person.length() == 0)
|
|
|
|
if(person.length() == 0)
|
|
|
|
addView(tagItem, 0);
|
|
|
|
addView(tagItem, getChildCount());
|
|
|
|
else
|
|
|
|
else
|
|
|
|
addView(tagItem);
|
|
|
|
addView(tagItem);
|
|
|
|
final ContactsAutoComplete textView = (ContactsAutoComplete)tagItem.
|
|
|
|
final ContactsAutoComplete textView = (ContactsAutoComplete)tagItem.
|
|
|
|
@ -135,7 +139,7 @@ public class PeopleContainer extends LinearLayout {
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private TextView getLastTextView() {
|
|
|
|
private TextView getLastTextView() {
|
|
|
|
for(int i = 0; i < getChildCount(); i++) {
|
|
|
|
for(int i = getChildCount() - 1; i >= 0; i--) {
|
|
|
|
View lastItem = getChildAt(i);
|
|
|
|
View lastItem = getChildAt(i);
|
|
|
|
TextView lastText = (TextView) lastItem.findViewById(R.id.text1);
|
|
|
|
TextView lastText = (TextView) lastItem.findViewById(R.id.text1);
|
|
|
|
if(lastText.isEnabled())
|
|
|
|
if(lastText.isEnabled())
|
|
|
|
@ -164,6 +168,30 @@ public class PeopleContainer extends LinearLayout {
|
|
|
|
return people;
|
|
|
|
return people;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Add people from JSON Array
|
|
|
|
|
|
|
|
* @param people
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
|
|
|
|
public void fromJSONArray(JSONArray people) throws JSONException {
|
|
|
|
|
|
|
|
for(int i = 0; i < people.length(); i++) {
|
|
|
|
|
|
|
|
JSONObject person = people.getJSONObject(i);
|
|
|
|
|
|
|
|
TextView textView = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(person.has("id") && person.getLong("id") == ActFmPreferenceService.userId())
|
|
|
|
|
|
|
|
textView = addPerson(Preferences.getStringValue(ActFmPreferenceService.PREF_NAME));
|
|
|
|
|
|
|
|
else if(!TextUtils.isEmpty(person.optString("name")))
|
|
|
|
|
|
|
|
textView = addPerson(person.getString("name"));
|
|
|
|
|
|
|
|
else if(!TextUtils.isEmpty(person.optString("email")))
|
|
|
|
|
|
|
|
textView = addPerson(person.getString("email"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(textView != null) {
|
|
|
|
|
|
|
|
textView.setTag(person);
|
|
|
|
|
|
|
|
textView.setEnabled(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
public static JSONObject createUserJson(TextView textView) {
|
|
|
|
public static JSONObject createUserJson(TextView textView) {
|
|
|
|
if(textView.isEnabled() == false)
|
|
|
|
if(textView.isEnabled() == false)
|
|
|
|
|