Ajout du message d'etat dans la contact list
authormarseille
Fri, 24 Apr 2009 21:41:32 +0200
changeset 184 e9d73490be9b
parent 178 393009fc8265 (current diff)
parent 183 ec2072a6089a (diff)
child 185 16373c4cd733
Ajout du message d'etat dans la contact list
AndroidManifest.xml
src/com/beem/project/beem/service/Contact.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/ui/ContactList.java
--- a/AndroidManifest.xml	Fri Apr 24 21:13:54 2009 +0200
+++ b/AndroidManifest.xml	Fri Apr 24 21:41:32 2009 +0200
@@ -17,6 +17,7 @@
 		<activity android:name=".ui.ChangeStatus" android:label="@string/app_name" />
 		<activity android:name=".ui.AccountCreation" android:label="@string/app_name" />
 		<activity android:name=".ui.AddContact" android:label="@string/app_name" />
+		<activity android:name=".ui.Subscription" android:label="@string/app_name" />
 		<service android:name="BeemService" android:enabled="true"
 			android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE">
 			<intent-filter>
--- a/src/com/beem/project/beem/service/Contact.java	Fri Apr 24 21:13:54 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java	Fri Apr 24 21:41:32 2009 +0200
@@ -4,8 +4,10 @@
 package com.beem.project.beem.service;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
+import org.jivesoftware.smack.RosterGroup;
 import org.jivesoftware.smack.packet.Presence;
 
 import com.beem.project.beem.utils.Status;
@@ -27,6 +29,7 @@
     private String mJID;
     private String mMsgState;
     private List<String> mRes;
+    private List<String> mGroups;
 
     /**
      * Parcelable.Creator needs by Android.
@@ -60,6 +63,7 @@
 	mStatus = Status.CONTACT_STATUS_DISCONNECT;
 	mRes = new ArrayList<String>();
 	mRes.add("none");
+	mGroups = new ArrayList<String>();
     }
 
     /**
@@ -72,7 +76,9 @@
 	mJID = in.readString();
 	mMsgState = in.readString();
 	mRes = new ArrayList<String>();
+	mGroups = new ArrayList<String>();
 	in.readStringList(mRes);
+	in.readStringList(mGroups);
     }
 
     /**
@@ -85,6 +91,7 @@
 	dest.writeString(mJID);
 	dest.writeString(mMsgState);
 	dest.writeStringList(getMRes());
+	dest.writeStringList(getGroups());
     }
 
     /**
@@ -135,6 +142,7 @@
     public void setStatus(Presence presence) {
 	Log.i(TAG,"PRESENCE");
 	mStatus = Status.getStatusFromPresence(presence);
+	mMsgState = presence.getStatus();
     }
 
     /**
@@ -206,4 +214,24 @@
 	    return mJID;
 	return super.toString();
     }
+
+    public void setGroups(Collection<RosterGroup> groups) {
+	for (RosterGroup rosterGroup : groups) {
+	    mGroups.add(rosterGroup.getName());
+	}
+    }
+
+    /**
+     * @param mGroups the mGroups to set
+     */
+    public void setGroups(List<String> mGroups) {
+	this.mGroups = mGroups;
+    }
+
+    /**
+     * @return the mGroups
+     */
+    public List<String> getGroups() {
+	return mGroups;
+    }
 }
--- a/src/com/beem/project/beem/service/PresenceAdapter.java	Fri Apr 24 21:13:54 2009 +0200
+++ b/src/com/beem/project/beem/service/PresenceAdapter.java	Fri Apr 24 21:41:32 2009 +0200
@@ -13,6 +13,7 @@
 	private int mType;
 	private int mStatus;
 	private String mTo;
+	private String mFrom;
 	
 	/**
 	 * Parcelable.Creator needs by Android.
@@ -34,6 +35,7 @@
 		mType = PresenceType.getPresenceType(presence);
 		mStatus = Status.getStatusFromPresence(presence);
 		mTo = presence.getTo();
+		mFrom = presence.getFrom();
 	}
 	
 	
@@ -41,6 +43,7 @@
 		mType = source.readInt();
 		mStatus = source.readInt();
 		mTo = source.readString();
+		mFrom = source.readString();
 	}
 
 	@Override
@@ -54,6 +57,7 @@
 		dest.writeInt(mType);
 		dest.writeInt(mStatus);
 		dest.writeString(mTo);
+		dest.writeString(mFrom);
 	}
 
 
@@ -102,4 +106,20 @@
 	public String getTo() {
 	    return mTo;
 	}
+
+
+	/**
+	 * @param mFrom the mFrom to set
+	 */
+	public void setFrom(String mFrom) {
+	    this.mFrom = mFrom;
+	}
+
+
+	/**
+	 * @return the mFrom
+	 */
+	public String getFrom() {
+	    return mFrom;
+	}
 }
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Fri Apr 24 21:13:54 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Fri Apr 24 21:41:32 2009 +0200
@@ -31,8 +31,7 @@
 
     private static final String TAG = "RosterAdapter";
     private Roster mAdaptee;
-    private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = 
-	new RemoteCallbackList<IBeemRosterListener>();
+    private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = new RemoteCallbackList<IBeemRosterListener>();
     private Map<String, Contact> mContacts = new HashMap<String, Contact>();
 
     private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
@@ -49,7 +48,8 @@
 	    if (!mContacts.containsKey(user)) {
 		Contact c = new Contact(user);
 		c.setStatus(roster.getPresence(user));
-		mContacts.put(user, c);		
+		c.setGroups(entry.getGroups());
+		mContacts.put(user, c);
 	    }
 	}
     }
@@ -123,10 +123,8 @@
     }
 
     /**
-     * Listener for the roster events.
-     * It will call the remote listeners registered.
+     * Listener for the roster events. It will call the remote listeners registered.
      * @author darisk
-     *
      */
     private class RosterListenerAdapter implements RosterListener {
 
@@ -222,6 +220,7 @@
 	    }
 	    c.addRes(StringUtils.parseResource(presence.getFrom()));
 	    c.setStatus(mAdaptee.getPresence(presence.getFrom()));
+	    c.setMsgState(presence.getStatus());
 	    /* redispatch vers les IBeemRosterListener */
 	    final int n = mRemoteRosListeners.beginBroadcast();
 
--- a/src/com/beem/project/beem/ui/ContactList.java	Fri Apr 24 21:13:54 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Fri Apr 24 21:41:32 2009 +0200
@@ -65,12 +65,6 @@
 	mRosterListener = new BeemRosterListener();
 	mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
 	mBeemApplication = BeemApplication.getApplication(this);
-	// bug fixe temporaire des betises de marseille
-//	
-//	 SharedPreferences mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
-//	 SharedPreferences.Editor editor = mSettings.edit(); editor.putInt(getString(R.string.PreferencePortKey),
-//	 5222); editor.commit();
-	 
     }
 
     @Override
@@ -186,7 +180,7 @@
 	    List<Map<String, Contact>> children = new ArrayList<Map<String, Contact>>();
 	    for (int j = 0; j < listContact.size(); ++j) {
 		Contact c = listContact.get(j);
-		if (groupSize == 0 /* || listGroup.get(i).equals(c.getGroupName()) */) {
+		if (groupSize == 0 || c.getGroups().contains(listGroup.get(i)) ) {
 		    Log.i(TAG, c.getID() + " " + c.getJID());
 		    Map<String, Contact> curChildMap = new HashMap<String, Contact>();
 		    children.add(curChildMap);
@@ -320,4 +314,4 @@
 	}
 
     }
-}
\ No newline at end of file
+}