# HG changeset patch # User nikita@nikita-lab # Date 1243000488 -7200 # Node ID 1d39db6ea3cb24a743a6afcab3200c406a83be85 # Parent fc72cf12c7017ffe09e1814b2acc5c5b22a81403# Parent d7b9162a5db298e5bb8037a208626cc0011d433f merged diff -r d7b9162a5db2 -r 1d39db6ea3cb src/com/beem/project/beem/BeemApplication.java --- a/src/com/beem/project/beem/BeemApplication.java Fri May 22 15:52:50 2009 +0200 +++ b/src/com/beem/project/beem/BeemApplication.java Fri May 22 15:54:48 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 d7b9162a5db2 -r 1d39db6ea3cb src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Fri May 22 15:52:50 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Fri May 22 15:54:48 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 d7b9162a5db2 -r 1d39db6ea3cb src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Fri May 22 15:52:50 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Fri May 22 15:54:48 2009 +0200 @@ -65,46 +65,25 @@ 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() { + super.onResume(); - mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable() { - @Override - public void run() { - mService = mBeemApplication.getXmppFacade(); - try { - mRoster = mService.getRoster(); - } catch (RemoteException e1) { - Log.e(TAG, "Get roster failed", e1); } - if (mRoster != null) { - try { - mRoster.addConnectionListener(mRosterListener); - } catch (RemoteException e) { - e.printStackTrace(); - } + + @Override + protected void onDestroy() { + mBeemApplication.unbindBeemService(); + super.onDestroy(); } - if (mAdapter == null) - callbackShowContactList(); - } - }); - } - - @Override - protected void onDestroy() { - mBeemApplication.unbindBeemService(); - super.onDestroy(); - } private void callbackShowContactList() { - /* - * @TODO: A ameliorer apres listener de nikita - */ if (mRoster != null) try { buildContactList(mRoster.getContactList()); @@ -135,17 +114,17 @@ 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; @@ -159,8 +138,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PREFERENCECHANGED) { if (resultCode == RESULT_OK) { - mAdapter = null; - setListAdapter(mAdapter); + if (!groupMap.isEmpty()) + groupMap.clear(); mBeemApplication.stopBeemService(); } } @@ -279,7 +258,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; } @@ -332,23 +310,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 @@ -366,13 +343,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); } @@ -430,20 +405,80 @@ @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 d7b9162a5db2 -r 1d39db6ea3cb src/com/beem/project/beem/ui/ContactListSettings.java --- a/src/com/beem/project/beem/ui/ContactListSettings.java Fri May 22 15:52:50 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactListSettings.java Fri May 22 15:54:48 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 d7b9162a5db2 -r 1d39db6ea3cb src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Fri May 22 15:52:50 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Fri May 22 15:54:48 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(); } /**