# HG changeset patch # User nikita@nikita-lab # Date 1242937094 -7200 # Node ID 4f1b3af03671c87e233acdd739b57a554ce346c4 # Parent 54e1e3f0bd4b16e8f82870ff68dff5e9265be64a debug de la contactlist avec reecriture d'une bonne grosse partie diff -r 54e1e3f0bd4b -r 4f1b3af03671 src/com/beem/project/beem/BeemApplication.java --- a/src/com/beem/project/beem/BeemApplication.java Thu May 21 16:33:11 2009 +0200 +++ b/src/com/beem/project/beem/BeemApplication.java Thu May 21 22:18:14 2009 +0200 @@ -99,9 +99,12 @@ mBeemApp.mProgressDialog.setTitle("Beem"); mBeemApp.mProgressDialog.setIcon(R.drawable.signal); mBeemApp.mProgressDialog.setMessage("Connecting..."); + mBeemApp.mProgressDialog.setCancelable(true); + mBeemApp.mApplicationContext = activity.getApplication(); activity.getResources(); mBeemApp.onCreate(); + //mBeemApp.mProgressDialog.show(); return mBeemApp; } @@ -110,8 +113,8 @@ */ public synchronized void startBeemService() { if (!mIsConnected) { - mProgressDialog.setMessage("Connecting..."); - mProgressDialog.show(); + ConnectionRunnable cRun = new ConnectionRunnable("Connecting..."); + mBeemApp.mActivity.runOnUiThread(cRun); // the connection will be made on service connect mApplicationContext.bindService(BeemApplication.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); } diff -r 54e1e3f0bd4b -r 4f1b3af03671 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Thu May 21 16:33:11 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Thu May 21 22:18:14 2009 +0200 @@ -72,7 +72,7 @@ Contact res = new Contact(user); mContacts.put(user, res); for (String group : groups) { - mAdaptee.createGroup(group); + //mAdaptee.createGroup(group); res.addGroup(group); } return res; diff -r 54e1e3f0bd4b -r 4f1b3af03671 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu May 21 16:33:11 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Thu May 21 22:18:14 2009 +0200 @@ -60,14 +60,14 @@ mRosterListener = new BeemRosterListener(); mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE); mBeemApplication = BeemApplication.getApplication(this); - if (mSettings.getString(getString(R.string.PreferenceHostKey), "").equals("")) - startActivityForResult(new Intent(this, ContactListSettings.class), PREFERENCECHANGED); + + //TODO: a refaire + /*if (mSettings.getString(getString(R.string.PreferenceHostKey), "").equals("")) + startActivityForResult(new Intent(this, ContactListSettings.class), PREFERENCECHANGED);*/ } @Override - protected void onResume() { - super.onResume(); - + protected void onResume() { mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable() { @Override public void run() { @@ -84,10 +84,10 @@ e.printStackTrace(); } } - if (mAdapter == null) - callbackShowContactList(); + callbackShowContactList(); } }); + super.onResume(); } @Override @@ -97,9 +97,6 @@ } private void callbackShowContactList() { - /* - * @TODO: A ameliorer apres listener de nikita - */ if (mRoster != null) try { buildContactList(mRoster.getContactList()); @@ -130,26 +127,42 @@ public final boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.account_edit: - startActivityForResult(new Intent(this, ContactListSettings.class), PREFERENCECHANGED); + startActivityForResult(new Intent(ContactList.this, ContactListSettings.class), PREFERENCECHANGED); return true; case R.id.account_about: Intent t = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.beem-project.com")); startActivity(t); return true; case R.id.account_create: - startActivity(new Intent(this, AccountCreation.class)); + startActivity(new Intent(ContactList.this, AccountCreation.class)); return true; case R.id.add_contact: - startActivity(new Intent(this, AddContact.class)); + startActivity(new Intent(ContactList.this, AddContact.class)); return true; default: return false; } } + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + //TODO:marche pas + Log.d(TAG, "onActivityResult" ); + if (requestCode == PREFERENCECHANGED) { + Log.d(TAG, "onPREFERENCECHANGED"); + if (resultCode == RESULT_OK) { + if (!groupMap.isEmpty()) + groupMap.clear(); + mBeemApplication.stopBeemService(); + } + } + if (requestCode == 1) { + Log.d(TAG, "onSENDIMRESULT"); + } + } + @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - Intent i = new Intent(this, SendIM.class); + Intent i = new Intent(ContactList.this, SendIM.class); try { i.putExtra("contact", groupMap.get(groupName.get(groupPosition)).get(childPosition)); startActivity(i); @@ -160,16 +173,6 @@ } } - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == PREFERENCECHANGED) { - if (resultCode == RESULT_OK) { - mAdapter = null; - setListAdapter(mAdapter); - mBeemApplication.stopBeemService(); - } - } - } - private void buildContactList(List listContact) { mListContact = listContact; groupMap = new HashMap>(); @@ -201,18 +204,18 @@ private class MyExpandableListAdapter implements ExpandableListAdapter { private List observers; - + public MyExpandableListAdapter() { observers = new ArrayList(); } - + public void changed() { for (DataSetObserver obs : observers) { obs.onChanged(); } } - - + + @Override public boolean areAllItemsEnabled() { return true; @@ -245,7 +248,6 @@ View v; if (convertView == null) { v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null); - Log.d(TAG, "Convert view est vide sur un getChildView"); } else { v = convertView; } @@ -295,23 +297,22 @@ @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { - Log.d(TAG, "View getGroupView"); - View holder = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null); - TextView groupTextView = (TextView) holder.findViewById(R.id.textgroup); + if (convertView == null) { + convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null); + } + TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup); groupTextView.setText(groupName.get(groupPosition)); - return holder; + return convertView; } @Override public boolean hasStableIds() { - Log.d(TAG, "boolean hasStableIds"); return false; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { - Log.d(TAG, "boolean isChildSelectable"); - return !false; + return true; } @Override @@ -332,13 +333,11 @@ @Override public void registerDataSetObserver(DataSetObserver observer) { - Log.d(TAG, "registerDataSetObserver"); observers.add(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { - Log.d(TAG, "unregisterDataSetObserver"); observers.remove(observer); } @@ -397,20 +396,82 @@ @Override public void onEntriesAdded(List addresses) throws RemoteException { - Log.i(TAG, "ENTRIES ADDED"); - + for (String str: addresses) { + Contact curContact = mRoster.getContact(str); + for (String group: curContact.getGroups()) { + if (!groupMap.containsKey(group)) { + groupMap.put(group, new ArrayList()); + groupName.add(group); + } + try { + groupMap.get(group).add(curContact); + } catch (NullPointerException e) { + Log.e(TAG, "Failed to find group in groupMap", e); + } + } + } + mHandler.post(new Runnable() { + @Override + public void run() { + mAdapter.changed(); + } + }); } @Override public void onEntriesDeleted(List addresses) throws RemoteException { - Log.i(TAG, "ENTRIES DEL"); - + + + for (List cList : groupMap.values()) { + for (Contact curContact:cList) { + for (String addr:addresses) { + if (addr.equals(curContact.getJID())) { + cList.remove(curContact); + if (cList.isEmpty()) { + groupMap.values().remove(cList); + } + } + } + } + } + mHandler.post(new Runnable() { + @Override + public void run() { + mAdapter.changed(); + } + }); } @Override public void onEntriesUpdated(List addresses) throws RemoteException { - Log.i(TAG, "ENTRIES UPD"); - + for (String str: addresses) { + Contact curContact = mRoster.getContact(str); + for (String group: curContact.getGroups()) { + if (!groupMap.containsKey(group)) { + groupMap.put(group, new ArrayList()); + groupName.add(group); + groupMap.get(group).add(curContact); + } else { + boolean found = false; + for (Contact tempContact:groupMap.get(group)) { + if (tempContact.getJID() == str) { + curContact = tempContact; + found = true; + break ; + } + } + if (!found) { + groupMap.get(group).add(curContact); + } + } + } + } + mHandler.post(new Runnable() { + @Override + public void run() { + mAdapter.changed(); + } + }); } @Override diff -r 54e1e3f0bd4b -r 4f1b3af03671 src/com/beem/project/beem/ui/ContactListSettings.java --- a/src/com/beem/project/beem/ui/ContactListSettings.java Thu May 21 16:33:11 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactListSettings.java Thu May 21 22:18:14 2009 +0200 @@ -46,9 +46,10 @@ sp.setSelection(i); sp.setOnItemSelectedListener(mProxyType); - showSettings(); Button ok = (Button) findViewById(R.id.ok); ok.setOnClickListener(mOkListener); + + showSettings(); } private OnItemSelectedListener mProxyType = new OnItemSelectedListener() { diff -r 54e1e3f0bd4b -r 4f1b3af03671 src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Thu May 21 16:33:11 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Thu May 21 22:18:14 2009 +0200 @@ -146,11 +146,12 @@ Log.d(TAG, "mchat open false", e); } super.onPause(); + finish(); } @Override protected void onStop() { - super.onStop(); + Log.d(TAG, "onStop"); try { mChat.setOpen(false); @@ -158,11 +159,12 @@ Log.d(TAG, "mchat open false", e); } mBeemApplication.unbindBeemService(); + super.onStop(); } @Override protected void onDestroy() { - super.onDestroy(); + if (mChatManager != null) { try { mChatManager.removeChatCreationListener(mChatManagerListener); @@ -171,6 +173,7 @@ Log.e(TAG, "mchat manager and SendIM destroy", e); } } + super.onDestroy(); } /**