maj de groupList, ce devrait etre bon pour l'ajout de group et l'ajout de contact dans un groupe, mais a debug encore
authorNikita Kozlov <nikita@beem-project.com>
Sat, 03 Oct 2009 12:45:25 +0200
changeset 443 97c8c32b61d0
parent 439 bd4ab0cd1a34
child 444 5fedf5cec9c9
maj de groupList, ce devrait etre bon pour l'ajout de group et l'ajout de contact dans un groupe, mais a debug encore
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/XmppFacade.java
src/com/beem/project/beem/service/aidl/IRoster.aidl
src/com/beem/project/beem/service/aidl/IXmppFacade.aidl
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/GroupList.java
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Sat Oct 03 11:40:30 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Sat Oct 03 12:45:25 2009 +0200
@@ -162,6 +162,27 @@
     public PresenceAdapter getPresence(String jid) throws RemoteException {
 	return new PresenceAdapter(mAdaptee.getPresence(jid));
     }
+    
+    @Override
+    public void addContactToGroup(String groupName, String jid) throws RemoteException {
+	createGroup(groupName);
+	RosterGroup group = mAdaptee.getGroup(groupName);
+	try {
+	    group.addEntry(mAdaptee.getEntry(jid));
+	} catch (XMPPException e) {
+	    e.printStackTrace();
+	}	
+    }
+    
+    @Override
+    public void removeContactFromGroup(String groupName, String jid) throws RemoteException {
+	RosterGroup group = mAdaptee.getGroup(groupName);
+	try {
+	    group.removeEntry(mAdaptee.getEntry(jid));
+	} catch (XMPPException e) {
+	    e.printStackTrace();
+	}
+    }
 
     /**
      * Get a contact from a RosterEntry.
@@ -175,7 +196,7 @@
 	c.setGroups(entry.getGroups());
 	c.setName(entry.getName());
 	return c;
-    }
+    }    
 
     /**
      * Listener for the roster events. It will call the remote listeners registered.
@@ -293,6 +314,5 @@
 	    }
 	    mRemoteRosListeners.finishBroadcast();
 	}
-    }
-
+    }    
 }
--- a/src/com/beem/project/beem/service/XmppFacade.java	Sat Oct 03 11:40:30 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppFacade.java	Sat Oct 03 12:45:25 2009 +0200
@@ -134,7 +134,7 @@
     }
 
     @Override
-    public byte[] getVcardAvater(String jid) throws RemoteException {
+    public byte[] getVcardAvatar(String jid) throws RemoteException {
 	VCard vcard = new VCard();
 
 	try {
--- a/src/com/beem/project/beem/service/aidl/IRoster.aidl	Sat Oct 03 11:40:30 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl	Sat Oct 03 12:45:25 2009 +0200
@@ -15,6 +15,10 @@
      
     void createGroup(in String groupname);
     
+    void addContactToGroup(in String groupName, in String jid);
+    
+    void removeContactFromGroup(in String groupName, in String jid);
+    
     List<Contact> getContactList();
     
     List<String> getGroupsNames();
--- a/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl	Sat Oct 03 11:40:30 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl	Sat Oct 03 12:45:25 2009 +0200
@@ -58,5 +58,5 @@
       * get the user vcard avatar
       * @param jid the user jid
       */
-      byte[] getVcardAvater(in String jid);
+      byte[] getVcardAvatar(in String jid);
 }
--- a/src/com/beem/project/beem/ui/ContactList.java	Sat Oct 03 11:40:30 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Sat Oct 03 12:45:25 2009 +0200
@@ -559,7 +559,7 @@
 		    byte[] rawImg;
 		    try {
 			//TODO: le faire en asynchrone, car la ca bloque tout.
-			rawImg = mXmppFacade.getVcardAvater(curContact.getJID());
+			rawImg = mXmppFacade.getVcardAvatar(curContact.getJID());
 			if (rawImg != null)
 			    imgV.setImageBitmap(BitmapFactory.decodeByteArray(rawImg, 0, rawImg.length));
 		    } catch (RemoteException e) {
--- a/src/com/beem/project/beem/ui/GroupList.java	Sat Oct 03 11:40:30 2009 +0200
+++ b/src/com/beem/project/beem/ui/GroupList.java	Sat Oct 03 12:45:25 2009 +0200
@@ -1,5 +1,7 @@
 package com.beem.project.beem.ui;
 
+import java.util.ArrayList;
+
 import android.app.ListActivity;
 import android.content.ComponentName;
 import android.content.Intent;
@@ -13,6 +15,7 @@
 import android.view.View;
 import android.view.View.OnKeyListener;
 import android.widget.ArrayAdapter;
+import android.widget.CheckedTextView;
 import android.widget.ListView;
 import android.widget.TextView;
 
@@ -39,6 +42,7 @@
     private ArrayAdapter<String> mGroups;
     private Contact mContact;
     private TextView mText;
+    private ArrayList<String> mStrings = new ArrayList<String>();
 
     static {
 	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
@@ -97,6 +101,20 @@
      */
     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();
+	    }
+	}
     }
 
     /**
@@ -104,9 +122,11 @@
      */
     private void setAdapter() {
 	try {
+	    for (String group: mRoster.getGroupsNames()) {
+		mStrings.add(group);
+	    }
 	    mGroups = new ArrayAdapter<String>(this,
-		android.R.layout.simple_list_item_multiple_choice,
-		mRoster.getGroupsNames().toArray(new String[mRoster.getGroupsNames().size()]));
+		android.R.layout.simple_list_item_multiple_choice, mStrings);
 	    setListAdapter(mGroups);
 	    mContact = mRoster.getContact(mJID);
 	    for (String group : mContact.getGroups()) {
@@ -125,7 +145,16 @@
 		switch (keyCode) {
 		    case KeyEvent.KEYCODE_DPAD_CENTER:
 		    case KeyEvent.KEYCODE_ENTER:
-			Log.d("GROUPLIST", "ADD GROUP");
+			if (mText.getText().length() == 0)
+			    return false;
+			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;