# HG changeset patch # User Da Risk # Date 1329854862 -3600 # Node ID f27ce0166608590cd896a261bd3e001ba4fc1dad # Parent d7df77602216fc36c7274d4cff464c0d6c585d00 Fix bug when creating contact. The contact is created asynchronously so we cannot try to get it immediatly. As a consequence the method IRoster.createContact now return a boolean. diff -r d7df77602216 -r f27ce0166608 res/values-fr/strings.xml --- a/res/values-fr/strings.xml Tue Feb 21 12:11:58 2012 +0100 +++ b/res/values-fr/strings.xml Tue Feb 21 21:07:42 2012 +0100 @@ -39,7 +39,7 @@ Ajouter Contact ajouté Erreur Contact non ajouté - Error Nom d\'utilisateur + Mauvais nom d\'utilisateur Mauvais formulaire Contact déjà ajouté diff -r d7df77602216 -r f27ce0166608 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Tue Feb 21 12:11:58 2012 +0100 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Tue Feb 21 21:07:42 2012 +0100 @@ -50,6 +50,18 @@ import java.util.List; import java.util.Map; +import android.content.Context; +import android.os.RemoteCallbackList; +import android.os.RemoteException; +import android.util.Log; + +import com.beem.project.beem.R; +import com.beem.project.beem.service.aidl.IBeemRosterListener; +import com.beem.project.beem.smack.avatar.AvatarListener; +import com.beem.project.beem.smack.avatar.AvatarManager; +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info; +import com.beem.project.beem.utils.Status; + import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.RosterEntry; import org.jivesoftware.smack.RosterGroup; @@ -58,17 +70,6 @@ import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.util.StringUtils; -import android.content.Context; -import android.os.RemoteCallbackList; -import android.os.RemoteException; -import android.util.Log; - -import com.beem.project.beem.R; -import com.beem.project.beem.service.aidl.IBeemRosterListener; -import com.beem.project.beem.utils.Status; -import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info; -import com.beem.project.beem.smack.avatar.AvatarManager; -import com.beem.project.beem.smack.avatar.AvatarListener; /** * This class implement a Roster adapter for BEEM. @@ -124,16 +125,16 @@ * {@inheritDoc} */ @Override - public Contact addContact(String user, String name, String[] groups) throws RemoteException { + public boolean addContact(String user, String name, String[] groups) throws RemoteException { RosterEntry contact = mAdaptee.getEntry(user); try { mAdaptee.createEntry(user, name, groups); contact = mAdaptee.getEntry(user); } catch (XMPPException e) { Log.e(TAG, "Error while adding new contact", e); - return null; + return false; } - return getContactFromRosterEntry(contact); + return true; } /** diff -r d7df77602216 -r f27ce0166608 src/com/beem/project/beem/service/aidl/IRoster.aidl --- a/src/com/beem/project/beem/service/aidl/IRoster.aidl Tue Feb 21 12:11:58 2012 +0100 +++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Tue Feb 21 21:07:42 2012 +0100 @@ -49,7 +49,7 @@ interface IRoster { - Contact addContact(in String user, in String name, in String[] groups); + boolean addContact(in String user, in String name, in String[] groups); void deleteContact(in Contact contact); diff -r d7df77602216 -r f27ce0166608 src/com/beem/project/beem/ui/AddContact.java --- a/src/com/beem/project/beem/ui/AddContact.java Tue Feb 21 12:11:58 2012 +0100 +++ b/src/com/beem/project/beem/ui/AddContact.java Tue Feb 21 21:07:42 2012 +0100 @@ -64,6 +64,7 @@ import com.beem.project.beem.BeemService; import com.beem.project.beem.R; +import com.beem.project.beem.service.aidl.IRoster; import com.beem.project.beem.service.aidl.IXmppFacade; import com.beem.project.beem.utils.BeemBroadcastReceiver; @@ -139,6 +140,16 @@ } /** + * Get the text of a widget. + * @param id the id of the widget. + * @return the text of the widget. + */ + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } + + /** * The ServiceConnection used to connect to the Beem service. */ private class BeemServiceConnection implements ServiceConnection { @@ -161,16 +172,6 @@ } /** - * Get the text of a widget. - * @param id the id of the widget. - * @return the text of the widget. - */ - private String getWidgetText(int id) { - EditText widget = (EditText) this.findViewById(id); - return widget.getText().toString(); - } - - /** * Listener. */ private class OkListener implements OnClickListener { @@ -184,10 +185,6 @@ public void onClick(View v) { String login; login = getWidgetText(R.id.addc_login); - if (login.length() == 0) { - Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show(); - return; - } boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login); if (!isEmail) { Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT) @@ -200,13 +197,14 @@ mGroup.add(getWidgetText(R.id.addc_group)); try { if (mXmppFacade != null) { - if (mXmppFacade.getRoster().getContact(login) != null) { - mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups()); + IRoster roster = mXmppFacade.getRoster(); + if (roster.getContact(login) != null) { + mGroup.addAll(roster.getContact(login).getGroups()); Toast.makeText(AddContact.this, getString(R.string.AddCContactAlready), Toast.LENGTH_SHORT) .show(); return; } - if (mXmppFacade.getRoster().addContact(login, alias, mGroup.toArray(new String[mGroup.size()])) == null) { + if (!roster.addContact(login, alias, mGroup.toArray(new String[mGroup.size()]))) { Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT) .show(); return;