# HG changeset patch # User Vincent Veronis # Date 1255005778 -7200 # Node ID 2771e1b2e0800ef70fe34dd71cdd708d4987fdab # Parent b33eed682a0d6fd78bcfd58ecc7ac1b07003f476 Correction gestion des groups. diff -r b33eed682a0d -r 2771e1b2e080 src/com/beem/project/beem/ui/ContactDialog.java --- a/src/com/beem/project/beem/ui/ContactDialog.java Sat Oct 03 16:24:18 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactDialog.java Thu Oct 08 14:42:58 2009 +0200 @@ -119,7 +119,7 @@ public void onClick(View v) { Activity a = ContactDialog.this.getOwnerActivity(); Intent i = new Intent(mContext, UserInfo.class); - i.putExtra("contact", mContact); + i.putExtra("contact", mContact.getJID()); a.startActivity(i); dismiss(); } diff -r b33eed682a0d -r 2771e1b2e080 src/com/beem/project/beem/ui/GroupList.java --- a/src/com/beem/project/beem/ui/GroupList.java Sat Oct 03 16:24:18 2009 +0200 +++ b/src/com/beem/project/beem/ui/GroupList.java Thu Oct 08 14:42:58 2009 +0200 @@ -14,10 +14,12 @@ import android.view.KeyEvent; import android.view.View; import android.view.View.OnKeyListener; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CheckedTextView; import android.widget.ListView; import android.widget.TextView; +import android.widget.AdapterView.OnItemClickListener; import com.beem.project.beem.BeemService; import com.beem.project.beem.R; @@ -65,6 +67,7 @@ listView.setItemsCanFocus(false); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + listView.setOnItemClickListener(new GroupOnItemClickListener()); mText = (TextView) findViewById(R.id.GroupListText); mText.setOnKeyListener(new GroupListOnKeyListener()); @@ -100,21 +103,7 @@ * @param id The row id of the item that was clicked */ protected void onListItemClick(ListView l, View v, int position, long id) { - Log.d("GROUPLIST", "CLICK"); - CheckedTextView textView = (CheckedTextView) v; - if (textView.isChecked()) { - try { - mRoster.addContactToGroup(textView.getText().toString(), mJID); - } catch (RemoteException e) { - e.printStackTrace(); - } - } else { - try { - mRoster.removeContactFromGroup(textView.getText().toString(), mJID); - } catch (RemoteException e) { - e.printStackTrace(); - } - } + } /** @@ -122,11 +111,10 @@ */ private void setAdapter() { try { - for (String group: mRoster.getGroupsNames()) { + for (String group : mRoster.getGroupsNames()) { mStrings.add(group); } - mGroups = new ArrayAdapter(this, - android.R.layout.simple_list_item_multiple_choice, mStrings); + mGroups = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, mStrings); setListAdapter(mGroups); mContact = mRoster.getContact(mJID); for (String group : mContact.getGroups()) { @@ -150,11 +138,6 @@ String groupname = mText.getText().toString(); mGroups.add(groupname); mText.setText(null); - try { - mRoster.createGroup(groupname); - } catch (RemoteException e) { - e.printStackTrace(); - } return true; default: return false; @@ -165,6 +148,31 @@ } + private class GroupOnItemClickListener implements OnItemClickListener { + + @Override + public void onItemClick(AdapterView arg0, View v, int arg2, long arg3) { + Log.d("GROUPLIST", "CLICK"); + CheckedTextView textView = (CheckedTextView) v; + if (!textView.isChecked()) { + try { + mRoster.createGroup(textView.getText().toString()); + mRoster.addContactToGroup(textView.getText().toString(), mJID); + } catch (RemoteException e) { + e.printStackTrace(); + } + } else { + try { + mRoster.removeContactFromGroup(textView.getText().toString(), mJID); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + + } + + } + /** * The ServiceConnection used to connect to the Beem service. */ @@ -173,7 +181,8 @@ /** * Constructor. */ - public BeemServiceConnection() { } + public BeemServiceConnection() { + } @Override public void onServiceConnected(ComponentName name, IBinder service) { diff -r b33eed682a0d -r 2771e1b2e080 src/com/beem/project/beem/ui/UserInfo.java --- a/src/com/beem/project/beem/ui/UserInfo.java Sat Oct 03 16:24:18 2009 +0200 +++ b/src/com/beem/project/beem/ui/UserInfo.java Thu Oct 08 14:42:58 2009 +0200 @@ -77,12 +77,6 @@ mTextAlias = (TextView) findViewById(R.id.userinfo_alias); mGalleryGroups = (Gallery) findViewById(R.id.userinfo_groups); mReceiver = new BeemBroadcastReceiver(mServConn); - - mContact = getIntent().getParcelableExtra("contact"); - mJID = mContact.getJID(); - mTextAlias.setText(mContact.getName()); - mGalleryGroups.setAdapter(new BeemGroups(UserInfo.this, mContact.getGroups())); - setTitle(mJID); } /** @@ -265,25 +259,25 @@ AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this); builder.setMessage(UserInfo.this.getString(R.string.userinfo_sureresend)).setCancelable(false) - .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - Presence presencePacket = new Presence(Presence.Type.subscribe); - presencePacket.setTo(mContact.getJID()); - try { - mXmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket)); - } catch (RemoteException e) { - e.printStackTrace(); - } - Toast.makeText(UserInfo.this, getString(R.string.userinfo_resend), Toast.LENGTH_SHORT) - .show(); - } - }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); + .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Presence presencePacket = new Presence(Presence.Type.subscribe); + presencePacket.setTo(mContact.getJID()); + try { + mXmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket)); + } catch (RemoteException e) { + e.printStackTrace(); + } + Toast.makeText(UserInfo.this, getString(R.string.userinfo_resend), Toast.LENGTH_SHORT) + .show(); + } + }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); AlertDialog alert = builder.create(); alert.show(); } @@ -305,21 +299,21 @@ public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this); builder.setMessage(UserInfo.this.getString(R.string.userinfo_sure2delete)).setCancelable(false) - .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - try { - mRoster.deleteContact(mContact); - } catch (RemoteException e) { - e.printStackTrace(); - } - } - }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); + .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + try { + mRoster.deleteContact(mContact); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); AlertDialog alert = builder.create(); alert.show(); } @@ -343,7 +337,12 @@ public void onServiceConnected(ComponentName name, IBinder service) { mXmppFacade = IXmppFacade.Stub.asInterface(service); try { - mRoster = mXmppFacade.getRoster(); + mRoster = mXmppFacade.getRoster(); + mJID = getIntent().getStringExtra("contact"); + mContact = mRoster.getContact(mJID); + mTextAlias.setText(mContact.getName()); + mGalleryGroups.setAdapter(new BeemGroups(UserInfo.this, mContact.getGroups())); + setTitle(mJID); } catch (RemoteException e) { e.printStackTrace(); }