Suppression du contact.
authormarseille@marseille-desktop
Mon, 22 Jun 2009 22:14:25 +0200
changeset 267 ab5493f08c57
parent 263 ff0b4790a5ed
child 268 68eb7cb08ba3
Suppression du contact. Mettre a jour la contactlist ...
res/layout/contactdialog.xml
res/values/strings.xml
src/com/beem/project/beem/service/Contact.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/aidl/IRoster.aidl
src/com/beem/project/beem/ui/ContactDialog.java
src/com/beem/project/beem/ui/ContactList.java
--- a/res/layout/contactdialog.xml	Mon Jun 22 19:16:38 2009 +0200
+++ b/res/layout/contactdialog.xml	Mon Jun 22 22:14:25 2009 +0200
@@ -9,8 +9,8 @@
 	<Button android:id="@+id/CDAlias" android:layout_width="fill_parent"
 		android:layout_height="wrap_content" android:text="@string/CDAlias" />
 
-	<Button android:id="@+id/CDGroup" android:layout_width="fill_parent"
-		android:layout_height="wrap_content" android:text="@string/CDGroup" />
+	<Button android:id="@+id/CDDelete" android:layout_width="fill_parent"
+		android:layout_height="wrap_content" android:text="@string/CDDelete" />
 
 	<Button android:id="@+id/CDResend" android:layout_width="fill_parent"
 		android:layout_height="wrap_content" android:text="@string/CDResend" />
--- a/res/values/strings.xml	Mon Jun 22 19:16:38 2009 +0200
+++ b/res/values/strings.xml	Mon Jun 22 22:14:25 2009 +0200
@@ -5,23 +5,23 @@
 	<string name="ClearButton">Clear</string>
 	<string name="AcceptButton">Accept</string>
 	<string name="RefuseButton">Refuse</string>
-	
+
 	<!--  Beem class -->
-	
+
 	<string name="BeemJabberID">Jabber ID</string>
-	
+
 	<!--  BeemApplication class -->
-	
+
 	<string name="BeemApplicationConnect">Connecting...</string>
-	
+
 	<!--  BeemService class -->
-	
+
 	<string name="BeemServiceDescription">Use the Beem Service</string>
 	<string name="BeemServiceCreated">BeemService Created</string>
 	<string name="BeemServiceDestroyed">BeemService destroyed</string>
 
 	<!--  Preferences informations -->
-	
+
 	<string name="PreferenceFileName">Beem</string>
 	<string name="PreferenceHostKey">host</string>
 	<string name="PreferenceJID">Jabber ID</string>
@@ -51,14 +51,18 @@
 	<string name="CLSProxyInfo">Proxy informations</string>
 	<string name="CLSLogin">Login:</string>
 	<string name="CLSOkButton">Ok</string>
-	
+
 	<!--  ContactDialog class -->
 	<string name="CDChat">Chat</string>
 	<string name="CDAlias">Alias</string>
-	<string name="CDGroup">Change group</string>
 	<string name="CDResend">Resend suscription</string>
 	<string name="CDInfos">User infos</string>
-	
+	<string name="CDDelete">Delete user</string>
+	<string name="CDSure2Delete">Are you sure you want to delete this contact?
+	</string>
+	<string name="CDSure2DeleteYes">Yes</string>
+	<string name="CDSure2DeleteNo">No</string>
+
 	<!-- AccountCreation class -->
 	<string name="ACLogin">Login:</string>
 	<string name="ACEmail">Email:</string>
@@ -68,7 +72,7 @@
 	<string name="ACOkLoginButton">Log with</string>
 	<string name="ACBadForm">Bad form</string>
 	<string name="ACCreated">Account created</string>
-	
+
 	<!-- AddContact class -->
 	<string name="AddCActTitle">Beem - Add contact</string>
 	<string name="AddCLogin">Login:</string>
@@ -77,7 +81,7 @@
 	<string name="AddCOkButton">Ok</string>
 	<string name="AddCContactAdded">Contact added</string>
 	<string name="AddCBadForm">Bad form</string>
-	
+
 	<!--  SendIM class -->
 
 	<string name="SendIMActTitle">Beem - Chat</string>
--- a/src/com/beem/project/beem/service/Contact.java	Mon Jun 22 19:16:38 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java	Mon Jun 22 22:14:25 2009 +0200
@@ -19,7 +19,6 @@
 
 /**
  * This class contains informations on a jabber contact.
- * 
  * @author darisk
  */
 public class Contact implements Parcelable {
@@ -29,24 +28,24 @@
      */
     public static final Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator<Contact>() {
 
-	                                                        @Override
-	                                                        public Contact createFromParcel(Parcel source) {
-		                                                    return new Contact(source);
-	                                                        }
+	@Override
+	public Contact createFromParcel(Parcel source) {
+	    return new Contact(source);
+	}
 
-	                                                        @Override
-	                                                        public Contact[] newArray(int size) {
-		                                                    return new Contact[size];
-	                                                        }
-	                                                    };
+	@Override
+	public Contact[] newArray(int size) {
+	    return new Contact[size];
+	}
+    };
 
-    private int                                     mID;
-    private int                                     mStatus;
-    private String                                  mJID;
-    private String                                  mMsgState;
-    private List<String>                            mRes;
-    private List<String>                            mGroups;
-    private String                                  mName;
+    private int mID;
+    private int mStatus;
+    private String mJID;
+    private String mMsgState;
+    private List<String> mRes;
+    private List<String> mGroups;
+    private String mName;
 
     /**
      * Constructor.
@@ -56,9 +55,7 @@
 
     /**
      * Construct a contact from a parcel.
-     * 
-     * @param in
-     *            parcel to use for construction
+     * @param in parcel to use for construction
      */
     private Contact(final Parcel in) {
 	mID = in.readInt();
@@ -74,9 +71,7 @@
 
     /**
      * Constructor.
-     * 
-     * @param jid
-     *            JID of the contact
+     * @param jid JID of the contact
      */
     public Contact(final String jid) {
 	mJID = jid;
@@ -89,11 +84,8 @@
 
     /**
      * Create a contact from a Uri.
-     * 
-     * @param uri
-     *            an uri for the contact
-     * @throws IllegalArgumentException
-     *             if it is not a xmpp uri
+     * @param uri an uri for the contact
+     * @throws IllegalArgumentException if it is not a xmpp uri
      */
     public Contact(Uri uri) {
 	if (!uri.getScheme().equals("xmpp"))
@@ -103,19 +95,20 @@
 
     /**
      * Add a group for the contact.
-     * 
-     * @param group
-     *            the group
+     * @param group the group
      */
     public void addGroup(String group) {
-	mGroups.add(group);
+	if (!mGroups.contains(group))
+	    mGroups.add(group);
+    }
+
+    public void delGroup(String group) {
+	mGroups.remove(group);
     }
 
     /**
      * Add a resource for this contact.
-     * 
-     * @param res
-     *            the resource to add
+     * @param res the resource to add
      */
     public void addRes(String res) {
 	if (!mRes.contains(res))
@@ -124,9 +117,7 @@
 
     /**
      * Delete a resource for this contact.
-     * 
-     * @param res
-     *            the resource de delete
+     * @param res the resource de delete
      */
     public void delRes(String res) {
 	mRes.remove(res);
@@ -143,7 +134,6 @@
 
     /**
      * Get the groups the contact is in.
-     * 
      * @return the mGroups
      */
     public List<String> getGroups() {
@@ -152,7 +142,6 @@
 
     /**
      * Get the id of the contact on the phone contact list.
-     * 
      * @return the mID
      */
     public int getID() {
@@ -161,7 +150,6 @@
 
     /**
      * Get the Jabber ID of the contact.
-     * 
      * @return the Jabber ID
      */
     public String getJID() {
@@ -170,7 +158,6 @@
 
     /**
      * Get the list of resource for the contact.
-     * 
      * @return the mRes
      */
     public List<String> getMRes() {
@@ -179,7 +166,6 @@
 
     /**
      * Get the message status of the contact.
-     * 
      * @return the message status of the contact.
      */
     public String getMsgState() {
@@ -195,7 +181,6 @@
 
     /**
      * Get the status of the contact.
-     * 
      * @return the mStatus
      */
     public int getStatus() {
@@ -204,9 +189,7 @@
 
     /**
      * Set the groups the contact is in.
-     * 
-     * @param groups
-     *            list of groups
+     * @param groups list of groups
      */
     public void setGroups(Collection<RosterGroup> groups) {
 	this.mGroups.clear();
@@ -217,9 +200,7 @@
 
     /**
      * Set the groups the contact is in.
-     * 
-     * @param mGroups
-     *            the mGroups to set
+     * @param mGroups the mGroups to set
      */
     public void setGroups(List<String> mGroups) {
 	this.mGroups = mGroups;
@@ -227,9 +208,7 @@
 
     /**
      * set the id of te contact on the phone contact list.
-     * 
-     * @param mid
-     *            the mID to set
+     * @param mid the mID to set
      */
     public void setID(int mid) {
 	mID = mid;
@@ -237,9 +216,7 @@
 
     /**
      * Set the Jabber ID of the contact.
-     * 
-     * @param jid
-     *            the jabber ID to set
+     * @param jid the jabber ID to set
      */
     public void setJID(String jid) {
 	mJID = jid;
@@ -247,9 +224,7 @@
 
     /**
      * Set a list of resource for the contact.
-     * 
-     * @param mRes
-     *            the mRes to set
+     * @param mRes the mRes to set
      */
     public void setMRes(List<String> mRes) {
 	this.mRes = mRes;
@@ -257,17 +232,14 @@
 
     /**
      * Set the message status of the contact.
-     * 
-     * @param msgState
-     *            the message status of the contact to set
+     * @param msgState the message status of the contact to set
      */
     public void setMsgState(String msgState) {
 	mMsgState = msgState;
     }
 
     /**
-     * @param mName
-     *            the mName to set
+     * @param mName the mName to set
      */
     public void setName(String mName) {
 	if (mName != null)
@@ -276,9 +248,7 @@
 
     /**
      * Set the status of the contact.
-     * 
-     * @param status
-     *            the mStatus to set
+     * @param status the mStatus to set
      */
     public void setStatus(int status) {
 	mStatus = status;
@@ -286,9 +256,7 @@
 
     /**
      * Set the status of the contact using a presence packet.
-     * 
-     * @param presence
-     *            the presence containing status
+     * @param presence the presence containing status
      */
     public void setStatus(Presence presence) {
 	mStatus = Status.getStatusFromPresence(presence);
@@ -297,9 +265,7 @@
 
     /**
      * Set status for the contact.
-     * 
-     * @param presence
-     *            The presence packet which contains the status
+     * @param presence The presence packet which contains the status
      */
     public void setStatus(PresenceAdapter presence) {
 	mStatus = presence.getStatus();
@@ -319,7 +285,6 @@
 
     /**
      * Get a URI to access the contact.
-     * 
      * @return the URI
      */
     public Uri toUri() {
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Mon Jun 22 19:16:38 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Mon Jun 22 22:14:25 2009 +0200
@@ -27,281 +27,282 @@
 
 /**
  * This class implement a Roster adapter for BEEM.
- * 
  * @author darisk
  */
 public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
 
-	/**
-	 * Listener for the roster events. It will call the remote listeners registered.
-	 * 
-	 * @author darisk
-	 */
-	private class RosterListenerAdapter implements RosterListener {
-
-		/**
-		 * Constructor.
-		 */
-		public RosterListenerAdapter() {
-			// TODO Auto-generated constructor stub
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void entriesAdded(Collection<String> addresses) {
-			Log.i(TAG, "Ajout de l'entry");
-			final int n = mRemoteRosListeners.beginBroadcast();
-
-			List<String> tab = new ArrayList<String>();
-			tab.addAll(addresses);
-			for (int i = 0; i < n; i++) {
-				IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-				try {					
-					listener.onEntriesAdded(tab);
-				} catch (RemoteException e) {
-					Log.w(TAG, "Error while adding roster entries", e);
-				}
-			}
-			mRemoteRosListeners.finishBroadcast();
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void entriesDeleted(Collection<String> addresses) {
-			Log.i(TAG, "Suppression de l'entry");
-			final int n = mRemoteRosListeners.beginBroadcast();
-
-			List<String> tab = new ArrayList<String>();
-			tab.addAll(addresses);
-			for (int i = 0; i < n; i++) {
-				IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-				try {					
-					listener.onEntriesDeleted(tab);
-				} catch (RemoteException e) {
-					Log.w(TAG, "Error while deleting roster entries", e);
-				}
-			}
-			mRemoteRosListeners.finishBroadcast();
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void entriesUpdated(Collection<String> addresses) {
-			Log.d(TAG, "Update de l'entry");
-			final int n = mRemoteRosListeners.beginBroadcast();
-
-			List<String> tab = new ArrayList<String>();
-			tab.addAll(addresses);
-			for (int i = 0; i < n; i++) {
-				IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-				try {					
-					listener.onEntriesUpdated(tab);
-				} catch (RemoteException e) {
-					Log.w(TAG, "Error while updating roster entries", e);
-				}
-			}
-			mRemoteRosListeners.finishBroadcast();
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		@Override
-		public void presenceChanged(Presence presence) {
-			Log.i(TAG, "Changement de Presence");
-			String user = StringUtils.parseBareAddress(presence.getFrom());
-			Log.d(TAG, "User : " + user);
-			Contact c = mContacts.get(StringUtils.parseBareAddress(user));
-			if (c == null) {
-				c = new Contact(user);
-				mContacts.put(user, c);
-			}
-			c.addRes(StringUtils.parseResource(presence.getFrom()));
-			c.setStatus(mAdaptee.getPresence(presence.getFrom()));
-			c.setMsgState(presence.getStatus());
-			c.setName(mAdaptee.getEntry(user).getName());
-			/* redispatch vers les IBeemRosterListener */
-			final int n = mRemoteRosListeners.beginBroadcast();
-
-			for (int i = 0; i < n; i++) {
-				IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
-				try {
-					listener.onPresenceChanged(new PresenceAdapter(presence));
-				} catch (RemoteException e) {
-					// The RemoteCallbackList will take care of removing the
-					// dead listeners.
-					Log.w(TAG, "Error while updating roster entries", e);
-				}
-			}
-			mRemoteRosListeners.finishBroadcast();
-		}
-	}
-
-	private static final String                     TAG                 = "RosterAdapter";
-	private Roster                                  mAdaptee;
-	private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = new RemoteCallbackList<IBeemRosterListener>();
-
-	private Map<String, Contact>                    mContacts           = new HashMap<String, Contact>();
-
-	private RosterListenerAdapter                   mRosterListener     = new RosterListenerAdapter();
+    /**
+     * Listener for the roster events. It will call the remote listeners registered.
+     * @author darisk
+     */
+    private class RosterListenerAdapter implements RosterListener {
 
 	/**
 	 * Constructor.
-	 * 
-	 * @param roster
-	 *            the roster to adapt
+	 */
+	public RosterListenerAdapter() {
+	    // TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void entriesAdded(Collection<String> addresses) {
+	    Log.i(TAG, "Ajout de l'entry");
+	    final int n = mRemoteRosListeners.beginBroadcast();
+
+	    List<String> tab = new ArrayList<String>();
+	    tab.addAll(addresses);
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    listener.onEntriesAdded(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while adding roster entries", e);
+		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
+	}
+
+	/**
+	 * {@inheritDoc}
 	 */
-	public RosterAdapter(final Roster roster) {
-		mAdaptee = roster;
-		roster.addRosterListener(mRosterListener);
-		for (RosterEntry entry : roster.getEntries()) {
-			String user = StringUtils.parseBareAddress(entry.getUser());
-			if (!mContacts.containsKey(user)) {
-				Contact c = new Contact(user);
-				c.setStatus(roster.getPresence(user));
-				c.setGroups(entry.getGroups());
-				c.setName(entry.getName());
-				mContacts.put(user, c);
-			}
+	@Override
+	public void entriesDeleted(Collection<String> addresses) {
+	    Log.i(TAG, "Suppression de l'entry");
+	    final int n = mRemoteRosListeners.beginBroadcast();
+
+	    List<String> tab = new ArrayList<String>();
+	    tab.addAll(addresses);
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    listener.onEntriesDeleted(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while deleting roster entries", e);
 		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void entriesUpdated(Collection<String> addresses) {
+	    Log.d(TAG, "Update de l'entry");
+	    final int n = mRemoteRosListeners.beginBroadcast();
+
+	    List<String> tab = new ArrayList<String>();
+	    tab.addAll(addresses);
+	    for (int i = 0; i < n; i++) {
+		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+		try {
+		    listener.onEntriesUpdated(tab);
+		} catch (RemoteException e) {
+		    Log.w(TAG, "Error while updating roster entries", e);
+		}
+	    }
+	    mRemoteRosListeners.finishBroadcast();
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
-		if (listen != null)
-			mRemoteRosListeners.register(listen);
+	public void presenceChanged(Presence presence) {
+	    Log.i(TAG, "Changement de Presence");
+	    String user = StringUtils.parseBareAddress(presence.getFrom());
+	    Log.d(TAG, "User : " + user);
+	    Contact c = mContacts.get(StringUtils.parseBareAddress(user));
+	    if (c == null) {
+		c = new Contact(user);
+		mContacts.put(user, c);
+	    }
+	    c.addRes(StringUtils.parseResource(presence.getFrom()));