Contact List :
authormarseille@marseille-desktop
Thu, 18 Jun 2009 11:53:00 +0200
changeset 240 f879726d6295
parent 239 65369afd96d3
child 241 a81519fc4024
Contact List : + Ajout d'un tri par Name + Ajout d'un tri par Status et Name
src/com/beem/project/beem/ui/ContactList.java
--- a/src/com/beem/project/beem/ui/ContactList.java	Thu Jun 18 11:30:23 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Thu Jun 18 11:53:00 2009 +0200
@@ -104,18 +104,32 @@
 	unbindService(mServConn);
     }
 
-    class ComparatorContactListByStatus<T> implements Comparator<T> {
+    class ComparatorContactListByName<T> implements Comparator<T> {
+
 	@Override
 	public int compare(T c1, T c2) {
-	    if (((Contact) c1).getStatus() < ((Contact) c2).getStatus())
+	    return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
+	}
+
+    }
+
+    class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
+
+	@Override
+	public int compare(T c1, T c2) {
+	    if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) {
 		return 1;
-	    return -1;
+	    } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) {
+		return -1;
+	    } else
+		return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
 	}
 
     }
 
     private void buildContactList(List<Contact> listContact) {
-	Collections.sort(listContact, new ComparatorContactListByStatus<Contact>());
+	Collections.sort(listContact, new ComparatorContactListByStatusAndName<Contact>());
+	// Collections.sort(listContact, new ComparatorContactListByName<Contact>());
 	mListContact = listContact;
 	for (Contact contact : listContact) {
 	    for (String group : contact.getGroups()) {