diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java index 9909cc08f..f4fc50083 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java @@ -55,6 +55,7 @@ import com.todoroo.andlib.service.NotificationManager; import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Query; +import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.Preferences; @@ -125,7 +126,7 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList // --- UI initialization @Override - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); getListView().setOnKeyListener(null); @@ -145,9 +146,19 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList tabHost.setCurrentTabByTag(getIntent().getStringExtra(EXTRA_START_TAB)); if(savedInstanceState != null && savedInstanceState.containsKey(MEMBERS_IN_PROGRESS)) { - String members = savedInstanceState.getString(MEMBERS_IN_PROGRESS); - if(members != null) - updateMembers(members); + final String members = savedInstanceState.getString(MEMBERS_IN_PROGRESS); + new Thread(new Runnable() { + @Override + public void run() { + AndroidUtilities.sleepDeep(500); + runOnUiThread(new Runnable() { + @Override + public void run() { + updateMembers(members); + } + }); + } + }).start(); } } @@ -440,27 +451,10 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList @SuppressWarnings("nls") private void updateMembers(String peopleJson) { tagMembers.removeAllViews(); - System.err.println("gotta grab ppl - " + peopleJson); - Log.e("GAH", "gaga", new Throwable()); if(!TextUtils.isEmpty(peopleJson)) { try { JSONArray people = new JSONArray(peopleJson); - 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 = tagMembers.addPerson(Preferences.getStringValue(ActFmPreferenceService.PREF_NAME)); - else if(!TextUtils.isEmpty(person.optString("name"))) - textView = tagMembers.addPerson(person.getString("name")); - else if(!TextUtils.isEmpty(person.optString("email"))) - textView = tagMembers.addPerson(person.getString("email")); - - if(textView != null) { - textView.setTag(person); - textView.setEnabled(false); - } - } + tagMembers.fromJSONArray(people); } catch (JSONException e) { System.err.println(peopleJson); Log.e("tag-view-activity", "json error refresh members", e); diff --git a/astrid/res/layout/task_list_body_tag.xml b/astrid/res/layout/task_list_body_tag.xml index 07db61c17..abf4e11b8 100644 --- a/astrid/res/layout/task_list_body_tag.xml +++ b/astrid/res/layout/task_list_body_tag.xml @@ -133,7 +133,7 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" - android:layout_marginLeft="5dip" + android:paddingLeft="45dip" android:text="@string/actfm_TVA_silence_label" /> diff --git a/astrid/src/com/todoroo/astrid/ui/PeopleContainer.java b/astrid/src/com/todoroo/astrid/ui/PeopleContainer.java index 5c14a5f82..a70f693f0 100644 --- a/astrid/src/com/todoroo/astrid/ui/PeopleContainer.java +++ b/astrid/src/com/todoroo/astrid/ui/PeopleContainer.java @@ -7,6 +7,7 @@ import org.json.JSONObject; import android.content.Context; import android.content.res.TypedArray; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; import android.util.AttributeSet; import android.view.KeyEvent; @@ -19,6 +20,8 @@ import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import com.timsu.astrid.R; +import com.todoroo.andlib.utility.Preferences; +import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; public class PeopleContainer extends LinearLayout { @@ -52,6 +55,7 @@ public class PeopleContainer extends LinearLayout { /** Adds a tag to the tag field */ public TextView addPerson(String person) { + System.err.println("ADD PERSON: " + person); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // check if already exists @@ -64,7 +68,7 @@ public class PeopleContainer extends LinearLayout { final View tagItem = inflater.inflate(R.layout.contact_edit_row, null); if(person.length() == 0) - addView(tagItem, 0); + addView(tagItem, getChildCount()); else addView(tagItem); final ContactsAutoComplete textView = (ContactsAutoComplete)tagItem. @@ -135,7 +139,7 @@ public class PeopleContainer extends LinearLayout { * @return */ private TextView getLastTextView() { - for(int i = 0; i < getChildCount(); i++) { + for(int i = getChildCount() - 1; i >= 0; i--) { View lastItem = getChildAt(i); TextView lastText = (TextView) lastItem.findViewById(R.id.text1); if(lastText.isEnabled()) @@ -164,6 +168,30 @@ public class PeopleContainer extends LinearLayout { 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") public static JSONObject createUserJson(TextView textView) { if(textView.isEnabled() == false)