merge
authormarseille
Fri, 24 Apr 2009 13:26:52 +0200
changeset 175 0e59b0a9509b
parent 174 f106a71a4cf6 (diff)
parent 172 471893ecd402 (current diff)
child 177 779ac7aefd71
merge
src/com/beem/project/beem/ui/ContactList.java
--- a/src/com/beem/project/beem/ui/ContactList.java	Fri Apr 24 13:21:23 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Fri Apr 24 13:26:52 2009 +0200
@@ -42,6 +42,7 @@
     private static final String CHILD = "CHILD";
     private static final String GROUP = "GROUP";
     private IXmppFacade mService = null;
+    private ExpandableListAdapter mAdapter;
     private BeemApplication mBeemApplication;
     private BeemRosterListener mRosterListener;
     private SharedPreferences mSettings;
@@ -63,6 +64,7 @@
 	super.onCreate(saveBundle);
 	mRosterListener = new BeemRosterListener();
 	mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
+	mBeemApplication = BeemApplication.getApplication(this);
 	// bug fixe temporaire des betises de marseille
 //	
 //	 SharedPreferences mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
@@ -74,9 +76,11 @@
     @Override
     protected void onResume() {
 	super.onResume();
-	mBeemApplication = BeemApplication.getApplication(this);
-	if (!mBeemApplication.isConnected())
+
+	if (!mBeemApplication.isConnected()) {
+	    mBeemApplication = BeemApplication.getApplication(this);
 	    mBeemApplication.startBeemService();
+	}
 	mBeemApplication.callWhenConnectedToServer(new Handler(), new Runnable() {
 	    @Override
 	    public void run() {
@@ -93,7 +97,8 @@
 			e.printStackTrace();
 		    }
 		}
-		callbackShowContactList();
+		if (mAdapter == null)
+		    callbackShowContactList();
 	    }
 	});
     }
@@ -159,19 +164,18 @@
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 	if (requestCode == PREFERENCECHANGED) {
 	    if (resultCode == RESULT_OK) {
-		setListAdapter(null);
+		mAdapter = null;
+		setListAdapter(mAdapter);
 		mBeemApplication.stopBeemService();
-		mBeemApplication.startBeemService();
 	    }
 	}
     }
 
     private void showContactList(List<String> listGroup, List<Contact> listContact) {
-	ExpandableListAdapter Adapter;
 	List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
 	List<List<Map<String, Contact>>> childData = new ArrayList<List<Map<String, Contact>>>();
-
-	if (listGroup.size() == 0)
+	int groupSize = listGroup.size();
+	if (groupSize == 0)
 	    listGroup.add("Default");
 	for (int i = 0; i < listGroup.size(); i++) {
 	    Map<String, String> curGroupMap = new HashMap<String, String>();
@@ -182,18 +186,20 @@
 	    List<Map<String, Contact>> children = new ArrayList<Map<String, Contact>>();
 	    for (int j = 0; j < listContact.size(); ++j) {
 		Contact c = listContact.get(j);
-		Log.i(TAG, c.getID() + " " + c.getJID());
-		Map<String, Contact> curChildMap = new HashMap<String, Contact>();
-		children.add(curChildMap);
-		curChildMap.put(CHILD, c);
+		if (groupSize == 0 /* || listGroup.get(i).equals(c.getGroupName()) */) {
+		    Log.i(TAG, c.getID() + " " + c.getJID());
+		    Map<String, Contact> curChildMap = new HashMap<String, Contact>();
+		    children.add(curChildMap);
+		    curChildMap.put(CHILD, c);
+		}
 	    }
 	    childData.add(children);
 	}
 
-	Adapter = new ContactExpandableListAdapter(this, groupData, R.layout.contactlistgroup, new String[] { GROUP },
+	mAdapter = new ContactExpandableListAdapter(this, groupData, R.layout.contactlistgroup, new String[] { GROUP },
 	    new int[] { R.id.textgroup }, childData, R.layout.contactlistcontact, new String[] { CHILD }, new int[] {
 		R.id.contactliststatus, R.id.contactlistpseudo, R.id.contactlistmsgperso, R.id.contactlistavatar });
-	setListAdapter(Adapter);
+	setListAdapter(mAdapter);
     }
 
     /**