User info delete user.
authorVincent Veronis <veroni_v@epitech.net>
Thu, 01 Oct 2009 17:23:21 +0200
changeset 425 2e33fad3ec98
parent 424 489d3728f7b7
child 426 7a884504e36c
User info delete user. User info resend subscription.
res/values-en/strings.xml
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/ContactDialog.java
src/com/beem/project/beem/ui/UserInfo.java
--- a/res/values-en/strings.xml	Thu Oct 01 16:57:07 2009 +0200
+++ b/res/values-en/strings.xml	Thu Oct 01 17:23:21 2009 +0200
@@ -225,5 +225,6 @@
 	 <string name="userinfo_label_block">Block</string>
 	 <string name="userinfo_label_delete">Delete</string>
 	 <string name="userinfo_def_vcard">User informations</string>
+	 <string name="userinfo_resend">Suscription resend</string>
 
 </resources>
--- a/res/values-fr/strings.xml	Thu Oct 01 16:57:07 2009 +0200
+++ b/res/values-fr/strings.xml	Thu Oct 01 17:23:21 2009 +0200
@@ -217,4 +217,5 @@
 	 <string name="userinfo_label_block">Bloquer</string>
 	 <string name="userinfo_label_delete">Supprimer</string>
 	 <string name="userinfo_def_vcard">Informations utilisateur</string>
+	 <string name="userinfo_resend">Souscription réenvoyée</string>
 </resources>
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Thu Oct 01 16:57:07 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Thu Oct 01 17:23:21 2009 +0200
@@ -3,7 +3,6 @@
  */
 package com.beem.project.beem.service;
 
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -85,15 +84,10 @@
      * {@inheritDoc}
      */
     @Override
-    public void deleteContact(Contact contact, String group) throws RemoteException {
+    public void deleteContact(Contact contact) throws RemoteException {
 	try {
 	    RosterEntry entry = mAdaptee.getEntry(contact.getJID());
-	    if (entry.getGroups().size() == 0) {
-		mAdaptee.removeEntry(entry);
-	    } else {
-		mAdaptee.getGroup(group).removeEntry(entry);
-		mRosterListener.onEntryDeleteFromGroup(group, contact.getJID());
-	    }
+	    mAdaptee.removeEntry(entry);
 	} catch (XMPPException e) {
 	    e.printStackTrace();
 	}
@@ -107,7 +101,7 @@
 	try {
 	    mAdaptee.createGroup(groupname);
 	} catch (IllegalArgumentException e) {
-	    //pas grave, plus simple a gerer comme ca.
+	    // pas grave, plus simple a gerer comme ca.
 	    Log.e(TAG, "Error while creating group", e);
 	}
     }
@@ -201,7 +195,7 @@
 	 * @param jid the jid of the entry which is deleted.
 	 */
 	public void onEntryDeleteFromGroup(String group, String jid) {
-	    //Log.i(TAG, "entry delete listener");
+	    // Log.i(TAG, "entry delete listener");
 	    final int n = mRemoteRosListeners.beginBroadcast();
 	    for (int i = 0; i < n; i++) {
 		IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
@@ -220,7 +214,7 @@
 	 */
 	@Override
 	public void entriesAdded(Collection<String> addresses) {
-	    //Log.i(TAG, "Ajout de l'entry " + addresses.size() + " " + addresses.toArray()[0]);
+	    // Log.i(TAG, "Ajout de l'entry " + addresses.size() + " " + addresses.toArray()[0]);
 	    final int n = mRemoteRosListeners.beginBroadcast();
 
 	    List<String> tab = new ArrayList<String>();
@@ -241,7 +235,7 @@
 	 */
 	@Override
 	public void entriesDeleted(Collection<String> addresses) {
-	    //Log.i(TAG, "Suppression de l'entry");
+	    // Log.i(TAG, "Suppression de l'entry");
 	    final int n = mRemoteRosListeners.beginBroadcast();
 
 	    List<String> tab = new ArrayList<String>();
@@ -262,7 +256,7 @@
 	 */
 	@Override
 	public void entriesUpdated(Collection<String> addresses) {
-	    //Log.i(TAG, "Update de l'entry " + addresses.size() + " " + addresses.toArray()[0]);
+	    // Log.i(TAG, "Update de l'entry " + addresses.size() + " " + addresses.toArray()[0]);
 	    final int n = mRemoteRosListeners.beginBroadcast();
 
 	    List<String> tab = new ArrayList<String>();
@@ -283,7 +277,7 @@
 	 */
 	@Override
 	public void presenceChanged(Presence presence) {
-	    //Log.i(TAG, "presence Changed");
+	    // Log.i(TAG, "presence Changed");
 	    /* redispatch vers les IBeemRosterListener */
 	    final int n = mRemoteRosListeners.beginBroadcast();
 
--- a/src/com/beem/project/beem/service/aidl/IRoster.aidl	Thu Oct 01 16:57:07 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl	Thu Oct 01 17:23:21 2009 +0200
@@ -8,7 +8,7 @@
     
     Contact addContact(in String user, in String name, in String[] groups);
     
-    void deleteContact(in Contact contact, in String group);
+    void deleteContact(in Contact contact);
     
     Contact getContact(in String jid);
     void setContactName(in String jid, in String name);
--- a/src/com/beem/project/beem/ui/ContactDialog.java	Thu Oct 01 16:57:07 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactDialog.java	Thu Oct 01 17:23:21 2009 +0200
@@ -113,32 +113,6 @@
 
     }
 
-    class deleteListener implements View.OnClickListener {
-
-	@Override
-	public void onClick(View v) {
-	    final Activity a = ContactDialog.this.getOwnerActivity();
-	    AlertDialog.Builder builder = new AlertDialog.Builder(a);
-	    builder.setMessage(a.getString(R.string.CDDelete)).setCancelable(false).setPositiveButton(
-		a.getString(R.string.CDSure2DeleteYes), new DialogInterface.OnClickListener() {
-		    public void onClick(DialogInterface dialog, int id) {
-			try {
-			    mXmppFacade.getRoster().deleteContact(mContact, mGroup);
-			} catch (RemoteException e) {
-			    e.printStackTrace();
-			}
-			dismiss();
-		    }
-		}).setNegativeButton(a.getString(R.string.CDSure2DeleteNo), new DialogInterface.OnClickListener() {
-		    public void onClick(DialogInterface dialog, int id) {
-			dialog.cancel();
-		    }
-		});
-	    AlertDialog alert = builder.create();
-	    alert.show();
-	}
-    }
-
     class infosListener implements View.OnClickListener {
 
 	@Override
@@ -152,22 +126,6 @@
 
     }
 
-    class resendListener implements View.OnClickListener {
-
-	@Override
-	public void onClick(View v) {
-	    Presence presencePacket = new Presence(Presence.Type.subscribe);
-	    presencePacket.setTo(mContact.getJID());
-	    try {
-		mXmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket));
-	    } catch (RemoteException e) {
-		Log.e(TAG, "resend subscription error", e);
-	    }
-	    dismiss();
-	}
-
-    }
-
     private class BeemServiceConnection implements ServiceConnection {
 
 	@Override
--- a/src/com/beem/project/beem/ui/UserInfo.java	Thu Oct 01 16:57:07 2009 +0200
+++ b/src/com/beem/project/beem/ui/UserInfo.java	Thu Oct 01 17:23:21 2009 +0200
@@ -2,16 +2,21 @@
 
 import java.util.List;
 
+import org.jivesoftware.smack.packet.Presence;
+
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.RemoteException;
+import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
@@ -19,10 +24,12 @@
 import android.widget.EditText;
 import android.widget.Gallery;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.Contact;
+import com.beem.project.beem.service.PresenceAdapter;
 import com.beem.project.beem.service.aidl.IRoster;
 import com.beem.project.beem.service.aidl.IXmppFacade;
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
@@ -60,6 +67,10 @@
 	setContentView(R.layout.userinfo);
 	View v = (View) findViewById(R.id.userinfo_layout_alias);
 	v.setOnClickListener(new AliasListener());
+	v = findViewById(R.id.userinfo_layout_delete);
+	v.setOnClickListener(new DeleteListener());
+	v = findViewById(R.id.userinfo_layout_re_suscription);
+	v.setOnClickListener(new ResendListener());
 	mTextAlias = (TextView) findViewById(R.id.userinfo_alias);
 	mGalleryGroups = (Gallery) findViewById(R.id.userinfo_groups);
 	mReceiver = new BeemBroadcastReceiver(mServConn);
@@ -99,18 +110,18 @@
 
 	@Override
 	public void onClick(View v) {
-	    Dialog d = new ContactDialogAliasDialog();
+	    Dialog d = new DialogAlias();
 	    d.show();
 	}
 
     }
 
-    public class ContactDialogAliasDialog extends Dialog {
+    public class DialogAlias extends Dialog {
 
 	/**
 	 * Constructor.
 	 */
-	public ContactDialogAliasDialog() {
+	public DialogAlias() {
 	    super(UserInfo.this);
 	    setContentView(R.layout.contactdialogaliasdialog);
 	    setTitle(mContact.getJID());
@@ -202,6 +213,65 @@
     }
 
     /**
+     * Event simple click on layout resend suscription.
+     */
+    class ResendListener implements View.OnClickListener {
+
+	/**
+	 * Constructor.
+	 */
+	public ResendListener() {
+	}
+
+	@Override
+	public void onClick(View v) {
+	    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_LONG).show();
+	}
+
+    }
+
+    /**
+     * Event simple click on layout delete
+     */
+    class DeleteListener implements View.OnClickListener {
+
+	/**
+	 * Constructor.
+	 */
+	public DeleteListener() {
+	}
+
+	@Override
+	public void onClick(View v) {
+	    AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
+	    builder.setMessage(UserInfo.this.getString(R.string.CDSure2Delete)).setCancelable(false).setPositiveButton(
+		UserInfo.this.getString(R.string.CDSure2DeleteYes), new DialogInterface.OnClickListener() {
+		    public void onClick(DialogInterface dialog, int id) {
+			try {
+			    mXmppFacade.getRoster().deleteContact(mContact);
+			} catch (RemoteException e) {
+			    e.printStackTrace();
+			}
+		    }
+		}).setNegativeButton(UserInfo.this.getString(R.string.CDSure2DeleteNo),
+		new DialogInterface.OnClickListener() {
+		    public void onClick(DialogInterface dialog, int id) {
+			dialog.cancel();
+		    }
+		});
+	    AlertDialog alert = builder.create();
+	    alert.show();
+	}
+    }
+
+    /**
      * The ServiceConnection used to connect to the Beem service.
      */
     private class BeemServiceConnection implements ServiceConnection {