merge
authorDa Risk <darisk972@gmail.com>
Wed, 09 Jun 2010 02:28:23 +0200
changeset 768 3afcf695da44
parent 765 3eb5041d6821 (diff)
parent 767 74a987c3efb5 (current diff)
child 769 be86f7f9b875
merge
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 @@
 	<ListView android:id="@+id/chat_messages"
 		android:layout_width="fill_parent" android:layout_height="0dip"
 		android:layout_weight="1" android:transcriptMode="normal"
+		android:stackFromBottom="true"
 		android:fastScrollEnabled="true" android:smoothScrollbar="false"
 		android:layout_marginBottom="20sp" android:padding="4px"
 		android:focusable="true"/>
--- 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">
 		<ListView android:id="@+id/contactlist" android:layout_width="fill_parent"
-			android:layout_height="fill_parent" android:transcriptMode="disabled" />
+		    android:layout_height="fill_parent" android:transcriptMode="disabled"
+		    android:textFilterEnabled="true" />
+
 	</LinearLayout>
 </LinearLayout>
--- 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<Contact>();
     private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
     private List<Contact> 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<Contact> 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<String, List<Contact>> entry : mContactOnGroup.entrySet()) {
 		    List<Contact> 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<String> groups = contact.getGroups();
 		for (Map.Entry<String, List<Contact>> entry : mContactOnGroup.entrySet()) {
 		    List<Contact> contactByGroups = entry.getValue();
-		    if (contactByGroups == mListContact) {
+		    if (mSelectedGroup.equals(entry.getKey())) {
 			updateCurrentList(entry.getKey(), contact);
 			continue;
 		    }
@@ -486,7 +492,7 @@
 	    List<String> groups = contact.getGroups();
 	    for (Map.Entry<String, List<Contact>> entry : mContactOnGroup.entrySet()) {
 		List<Contact> 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<Contact> result = mListContact;
+		if (constraint.length() > 0) {
+		    result = new LinkedList<Contact>();
+		    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<Contact> contacts = (List<Contact>) results.values;
+		mListContact = contacts;
+		notifyDataSetChanged();
+	    }
+	}
     }
 
     /**