Fix bug when creating contact.
authorDa Risk <da_risk@beem-project.com>
Tue, 21 Feb 2012 21:07:42 +0100
changeset 962f27ce0166608
parent 961 d7df77602216
child 963 24474027eb45
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.
res/values-fr/strings.xml
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/aidl/IRoster.aidl
src/com/beem/project/beem/ui/AddContact.java
     1.1 --- a/res/values-fr/strings.xml	Tue Feb 21 12:11:58 2012 +0100
     1.2 +++ b/res/values-fr/strings.xml	Tue Feb 21 21:07:42 2012 +0100
     1.3 @@ -39,7 +39,7 @@
     1.4  	<string name="AddCOkButton">Ajouter</string>
     1.5  	<string name="AddCContactAdded">Contact ajouté</string>
     1.6  	<string name="AddCContactAddedError">Erreur Contact non ajouté</string>
     1.7 -	<string name="AddCContactAddedLoginError">Error Nom d\'utilisateur</string>
     1.8 +	<string name="AddCContactAddedLoginError">Mauvais nom d\'utilisateur</string>
     1.9  	<string name="AddCBadForm">Mauvais formulaire</string>
    1.10  	<string name="AddCContactAlready">Contact déjà ajouté</string>
    1.11  
     2.1 --- a/src/com/beem/project/beem/service/RosterAdapter.java	Tue Feb 21 12:11:58 2012 +0100
     2.2 +++ b/src/com/beem/project/beem/service/RosterAdapter.java	Tue Feb 21 21:07:42 2012 +0100
     2.3 @@ -50,6 +50,18 @@
     2.4  import java.util.List;
     2.5  import java.util.Map;
     2.6  
     2.7 +import android.content.Context;
     2.8 +import android.os.RemoteCallbackList;
     2.9 +import android.os.RemoteException;
    2.10 +import android.util.Log;
    2.11 +
    2.12 +import com.beem.project.beem.R;
    2.13 +import com.beem.project.beem.service.aidl.IBeemRosterListener;
    2.14 +import com.beem.project.beem.smack.avatar.AvatarListener;
    2.15 +import com.beem.project.beem.smack.avatar.AvatarManager;
    2.16 +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info;
    2.17 +import com.beem.project.beem.utils.Status;
    2.18 +
    2.19  import org.jivesoftware.smack.Roster;
    2.20  import org.jivesoftware.smack.RosterEntry;
    2.21  import org.jivesoftware.smack.RosterGroup;
    2.22 @@ -58,17 +70,6 @@
    2.23  import org.jivesoftware.smack.packet.Presence;
    2.24  import org.jivesoftware.smack.util.StringUtils;
    2.25  
    2.26 -import android.content.Context;
    2.27 -import android.os.RemoteCallbackList;
    2.28 -import android.os.RemoteException;
    2.29 -import android.util.Log;
    2.30 -
    2.31 -import com.beem.project.beem.R;
    2.32 -import com.beem.project.beem.service.aidl.IBeemRosterListener;
    2.33 -import com.beem.project.beem.utils.Status;
    2.34 -import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info;
    2.35 -import com.beem.project.beem.smack.avatar.AvatarManager;
    2.36 -import com.beem.project.beem.smack.avatar.AvatarListener;
    2.37  
    2.38  /**
    2.39   * This class implement a Roster adapter for BEEM.
    2.40 @@ -124,16 +125,16 @@
    2.41       * {@inheritDoc}
    2.42       */
    2.43      @Override
    2.44 -    public Contact addContact(String user, String name, String[] groups) throws RemoteException {
    2.45 +    public boolean addContact(String user, String name, String[] groups) throws RemoteException {
    2.46  	RosterEntry contact = mAdaptee.getEntry(user);
    2.47  	try {
    2.48  	    mAdaptee.createEntry(user, name, groups);
    2.49  	    contact = mAdaptee.getEntry(user);
    2.50  	} catch (XMPPException e) {
    2.51  	    Log.e(TAG, "Error while adding new contact", e);
    2.52 -	    return null;
    2.53 +	    return false;
    2.54  	}
    2.55 -	return getContactFromRosterEntry(contact);
    2.56 +	return true;
    2.57      }
    2.58  
    2.59      /**
     3.1 --- a/src/com/beem/project/beem/service/aidl/IRoster.aidl	Tue Feb 21 12:11:58 2012 +0100
     3.2 +++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl	Tue Feb 21 21:07:42 2012 +0100
     3.3 @@ -49,7 +49,7 @@
     3.4  
     3.5  interface IRoster {
     3.6  
     3.7 -    Contact addContact(in String user, in String name, in String[] groups);
     3.8 +    boolean addContact(in String user, in String name, in String[] groups);
     3.9  
    3.10      void deleteContact(in Contact contact);
    3.11  
     4.1 --- a/src/com/beem/project/beem/ui/AddContact.java	Tue Feb 21 12:11:58 2012 +0100
     4.2 +++ b/src/com/beem/project/beem/ui/AddContact.java	Tue Feb 21 21:07:42 2012 +0100
     4.3 @@ -64,6 +64,7 @@
     4.4  
     4.5  import com.beem.project.beem.BeemService;
     4.6  import com.beem.project.beem.R;
     4.7 +import com.beem.project.beem.service.aidl.IRoster;
     4.8  import com.beem.project.beem.service.aidl.IXmppFacade;
     4.9  import com.beem.project.beem.utils.BeemBroadcastReceiver;
    4.10  
    4.11 @@ -139,6 +140,16 @@
    4.12      }
    4.13  
    4.14      /**
    4.15 +     * Get the text of a widget.
    4.16 +     * @param id the id of the widget.
    4.17 +     * @return the text of the widget.
    4.18 +     */
    4.19 +    private String getWidgetText(int id) {
    4.20 +	EditText widget = (EditText) this.findViewById(id);
    4.21 +	return widget.getText().toString();
    4.22 +    }
    4.23 +
    4.24 +    /**
    4.25       * The ServiceConnection used to connect to the Beem service.
    4.26       */
    4.27      private class BeemServiceConnection implements ServiceConnection {
    4.28 @@ -161,16 +172,6 @@
    4.29      }
    4.30  
    4.31      /**
    4.32 -     * Get the text of a widget.
    4.33 -     * @param id the id of the widget.
    4.34 -     * @return the text of the widget.
    4.35 -     */
    4.36 -    private String getWidgetText(int id) {
    4.37 -	EditText widget = (EditText) this.findViewById(id);
    4.38 -	return widget.getText().toString();
    4.39 -    }
    4.40 -
    4.41 -    /**
    4.42       * Listener.
    4.43       */
    4.44      private class OkListener implements OnClickListener {
    4.45 @@ -184,10 +185,6 @@
    4.46  	public void onClick(View v) {
    4.47  	    String login;
    4.48  	    login = getWidgetText(R.id.addc_login);
    4.49 -	    if (login.length() == 0) {
    4.50 -		Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
    4.51 -		return;
    4.52 -	    }
    4.53  	    boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login);
    4.54  	    if (!isEmail) {
    4.55  		Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT)
    4.56 @@ -200,13 +197,14 @@
    4.57  		mGroup.add(getWidgetText(R.id.addc_group));
    4.58  	    try {
    4.59  		if (mXmppFacade != null) {
    4.60 -		    if (mXmppFacade.getRoster().getContact(login) != null) {
    4.61 -			mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups());
    4.62 +		    IRoster roster = mXmppFacade.getRoster();
    4.63 +		    if (roster.getContact(login) != null) {
    4.64 +			mGroup.addAll(roster.getContact(login).getGroups());
    4.65  			Toast.makeText(AddContact.this, getString(R.string.AddCContactAlready), Toast.LENGTH_SHORT)
    4.66  			    .show();
    4.67  			return;
    4.68  		    }
    4.69 -		    if (mXmppFacade.getRoster().addContact(login, alias, mGroup.toArray(new String[mGroup.size()])) == null) {
    4.70 +		    if (!roster.addContact(login, alias, mGroup.toArray(new String[mGroup.size()]))) {
    4.71  			Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT)
    4.72  			    .show();
    4.73  			return;