# HG changeset patch # User Da Risk # Date 1276043303 -7200 # Node ID 3afcf695da44203bda8a7cbc19302c1ab9ef41a2 # Parent 3eb5041d6821eabafd18a3b379edc00504b6a0b0# Parent 74a987c3efb5c3a887cfa160a93f2baac6a5a71b merge diff -r 74a987c3efb5 -r 3afcf695da44 res/layout/chat.xml --- a/res/layout/chat.xml Tue Jun 08 17:31:00 2010 -0500 +++ b/res/layout/chat.xml Wed Jun 09 02:28:23 2010 +0200 @@ -34,6 +34,7 @@ diff -r 74a987c3efb5 -r 3afcf695da44 res/layout/contactlist.xml --- a/res/layout/contactlist.xml Tue Jun 08 17:31:00 2010 -0500 +++ b/res/layout/contactlist.xml Wed Jun 09 02:28:23 2010 +0200 @@ -8,6 +8,8 @@ android:layout_height="fill_parent" android:orientation="horizontal" android:padding="2px"> + android:layout_height="fill_parent" android:transcriptMode="disabled" + android:textFilterEnabled="true" /> + diff -r 74a987c3efb5 -r 3afcf695da44 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Tue Jun 08 17:31:00 2010 -0500 +++ b/src/com/beem/project/beem/ui/ContactList.java Wed Jun 09 02:28:23 2010 +0200 @@ -77,6 +77,8 @@ import android.view.ViewStub; import android.widget.AdapterView; import android.widget.BaseAdapter; +import android.widget.Filter; +import android.widget.Filterable; import android.widget.Gallery; import android.widget.LinearLayout; import android.widget.ListView; @@ -124,6 +126,7 @@ new ComparatorContactListByStatusAndName(); private final BeemRosterListener mBeemRosterListener = new BeemRosterListener(); private List mListContact; + private String mSelectedGroup; private IRoster mRoster; private Contact mSelectedContact; private IXmppFacade mXmppFacade; @@ -311,6 +314,7 @@ */ private void buildContactList(String group) { mListContact = mContactOnGroup.get(group); + mSelectedGroup = group; Log.d(TAG, "buildContactList for group " + group); mAdapterContactList.notifyDataSetChanged(); } @@ -377,7 +381,7 @@ mContactOnGroup.put(group, tmplist); } List contactByGroups = mContactOnGroup.get(group); - if (contactByGroups == mListContact) { + if (mSelectedGroup.equals(group)) { updateCurrentList(group, contact); continue; } @@ -404,7 +408,7 @@ Contact contact = new Contact(cToDelete); for (Map.Entry> entry : mContactOnGroup.entrySet()) { List contactByGroups = entry.getValue(); - if (contactByGroups == mListContact) { + if (mSelectedGroup.equals(entry.getKey())) { updateCurrentList(entry.getKey(), contact); continue; } @@ -415,7 +419,9 @@ mHandler.post(new Runnable() { public void run() { - mListContact = mContactOnGroup.get(getString(R.string.contact_list_all_contact)); + mSelectedGroup = getString(R.string.contact_list_all_contact); + mListContact = mContactOnGroup.get(mSelectedGroup); + mAdapterContactList.notifyDataSetChanged(); } }); @@ -440,7 +446,7 @@ List groups = contact.getGroups(); for (Map.Entry> entry : mContactOnGroup.entrySet()) { List contactByGroups = entry.getValue(); - if (contactByGroups == mListContact) { + if (mSelectedGroup.equals(entry.getKey())) { updateCurrentList(entry.getKey(), contact); continue; } @@ -486,7 +492,7 @@ List groups = contact.getGroups(); for (Map.Entry> entry : mContactOnGroup.entrySet()) { List contactByGroups = entry.getValue(); - if (contactByGroups == mListContact) { + if (mSelectedGroup.equals(entry.getKey())) { updateCurrentList(entry.getKey(), contact); continue; } @@ -565,12 +571,15 @@ /** * Adapter contact list. */ - private class BeemContactList extends BaseAdapter { + private class BeemContactList extends BaseAdapter implements Filterable { + + private final ContactFilter mFilter; /** * Constructor. */ public BeemContactList() { + mFilter = new ContactFilter(); } /** @@ -594,9 +603,10 @@ */ @Override public long getItemId(int position) { - return position; + return mListContact.get(position).hashCode(); } + /** * {@inheritDoc} */ @@ -618,13 +628,17 @@ return v; } + @Override + public Filter getFilter() { + return mFilter; + } + /** * Adapte curContact to the view. * @param view the row view. * @param curContact the current contact. */ private void bindView(View view, Contact curContact) { - if (curContact != null) { TextView v = (TextView) view.findViewById(R.id.contactlistpseudo); LevelListDrawable mStatusDrawable = (LevelListDrawable) getResources() @@ -636,6 +650,34 @@ v.setText(curContact.getMsgState()); } } + + private class ContactFilter extends Filter { + + @Override + protected Filter.FilterResults performFiltering(CharSequence constraint) { + Log.d(TAG, "performFiltering"); + List result = mListContact; + if (constraint.length() > 0) { + result = new LinkedList(); + for(Contact c : mContactOnGroup.get(mSelectedGroup)) { + if (c.getJID().contains(constraint)) + result.add(c); + } + } + Filter.FilterResults fr = new Filter.FilterResults(); + fr.values = result; + fr.count = result.size(); + return fr; + } + + @Override + protected void publishResults(CharSequence constraint, Filter.FilterResults results) { + Log.d(TAG, "publishResults"); + List contacts = (List) results.values; + mListContact = contacts; + notifyDataSetChanged(); + } + } } /**