[tuxdroid-svn] r4663 - software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-g
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-05-25 13:03:23
|
Author: jerome
Date: 2009-05-25 14:45:53 +0200 (Mon, 25 May 2009)
New Revision: 4663
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookFunctions.java
software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookGadget.java
Log:
* Retrieving user notifications.
Modified: software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookFunctions.java
===================================================================
--- software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookFunctions.java 2009-05-25 12:00:06 UTC (rev 4662)
+++ software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookFunctions.java 2009-05-25 12:45:53 UTC (rev 4663)
@@ -1,10 +1,13 @@
import java.io.IOException;
import java.util.EnumSet;
+import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
import com.facebook.api.FacebookException;
import com.facebook.api.ProfileField;
+import com.facebook.api.schema.Event;
+import com.facebook.api.schema.EventsGetResponse;
import com.facebook.api.schema.FriendsGetResponse;
import com.facebook.api.schema.User;
import com.facebook.api.schema.UsersGetInfoResponse;
@@ -34,6 +37,7 @@
public class FacebookFunctions {
private FacebookConnection connection;
+ private Hashtable<String, Vector<String>> notifications = new Hashtable<String, Vector<String>>();
/**
* Class constructor.
@@ -42,6 +46,7 @@
public FacebookFunctions(FacebookConnection connection)
{
this.connection = connection;
+ this.notifications = this.getUserNotification();
}
@@ -49,7 +54,7 @@
* Return the user friend list as Vector<String>.
* @return
*/
- private Vector<String> getFriends()
+ public Vector<String> getFriends()
{
Vector<String> friendsList = new Vector<String>();
@@ -83,4 +88,273 @@
return friendsList;
}
+
+
+ /**
+ * Gets all notifications.
+ */
+ private Hashtable<String, Vector<String>> getUserNotification()
+ {
+ //Will contain all availables notifications.
+ //availables notifications : messages, pokes, shares, friends_requests, group_invites, event_invites
+ Hashtable<String, Vector<String>> notifications = new Hashtable<String, Vector<String>>();
+
+ try
+ {
+ connection.getClient().notifications_get();
+ String notifs = connection.getClient().getRawResponse();
+
+ /**
+ * Getting messages notifications.
+ */
+ if(notifs.contains("<messages"))
+ {
+ String messagesString = notifs.substring(
+ notifs.indexOf("<messages"),
+ notifs.indexOf("</messages>"));
+
+ Vector<String> msDatas = new Vector<String>();
+
+ String unreaded = messagesString.substring(
+ messagesString.indexOf("<unread>") + "<unread>".length(),
+ messagesString.indexOf("</unread>"));
+
+ msDatas.add(unreaded);
+
+
+ if(Integer.valueOf(unreaded).intValue() > 0)
+ {
+ notifications.put("messages", msDatas);
+ }
+ }
+
+ /**
+ * Getting pokes notifications.
+ */
+ if(notifs.contains("<pokes"))
+ {
+ String pokesString;
+
+ try
+ {
+ pokesString = notifs.substring(notifs.indexOf("<pokes"), notifs.indexOf("</pokes>"));
+ }
+ catch(IndexOutOfBoundsException indexError)
+ {
+ pokesString = notifs.substring(notifs.indexOf("<pokes"), notifs.indexOf("/>"));
+ }
+
+ Vector<String> pkDatas = new Vector<String>();
+
+ String unreaded = pokesString.substring(
+ pokesString.indexOf("<unread>") + "<unread>".length(),
+ pokesString.indexOf("</unread>"));
+
+ pkDatas.add(unreaded);
+
+ if(Integer.valueOf(unreaded).intValue() > 0 )
+ {
+ notifications.put("pokes", pkDatas);
+ }
+ }
+
+ /**
+ * Getting shares notifications.
+ */
+ if(notifs.contains("<shares"))
+ {
+ String sharesString;
+
+ try
+ {
+ sharesString = notifs.substring(notifs.indexOf("<shares"), notifs.indexOf("</shares>"));
+ }
+ catch(IndexOutOfBoundsException indexError)
+ {
+ sharesString = notifs.substring(notifs.indexOf("<shares"), notifs.indexOf("/>"));
+ }
+
+ Vector<String> shDatas = new Vector<String>();
+
+ String unreaded = sharesString.substring(
+ sharesString.indexOf("<unread>") + "<unread>".length(),
+ sharesString.indexOf("</unread>"));
+
+ shDatas.add(unreaded);
+
+ if(Integer.valueOf(unreaded).intValue() > 0)
+ {
+ notifications.put("shares", shDatas);
+ }
+ }
+
+ /**
+ * Get the friend_requests notifications.
+ */
+ if(notifs.contains("<friend_requests"))
+ {
+ String friendsString = notifs.substring(notifs.indexOf("<friend_requests"), notifs.indexOf("</friend_requests>"));
+ Vector<String> friendsDatas = new Vector<String>();
+ Vector<Long> friendsDatasAsLong = new Vector<Long>();
+
+ //Getting friends uid that ask for friends.
+ if(friendsString.contains("<uid>"))
+ {
+ while(friendsString.contains("<uid>"))
+ {
+ String friend = friendsString.substring(
+ friendsString.indexOf("<uid>") + "<uid>".length(),
+ friendsString.indexOf("</uid>"));
+
+ friendsString = friendsString.replace("<uid>" + friend + "</uid>", "");
+
+ friendsDatasAsLong.add(Long.valueOf(friend).longValue());
+ }
+
+
+ // Go fetch the information for the user list of user ids
+ connection.getClient().users_getInfo(friendsDatasAsLong, EnumSet.of(ProfileField.NAME));
+
+ UsersGetInfoResponse userResponse = (UsersGetInfoResponse) connection.getClient().getResponsePOJO();
+
+ // Print out the user information
+ List<User> users = userResponse.getUser();
+ for (User user : users)
+ {
+ friendsDatas.add(user.getName());
+ }
+
+ notifications.put("friend_requests", friendsDatas);
+ }
+ }
+
+ /**
+ * Getting new groups invitations.
+ */
+ if(notifs.contains("<group_invites"))
+ {
+ String groupString;
+
+ try
+ {
+ groupString = notifs.substring(notifs.indexOf("<group_invites"), notifs.indexOf("</group_invites>"));
+ }
+ catch(IndexOutOfBoundsException indexError)
+ {
+ groupString = notifs.substring(notifs.indexOf("<group_invites"), notifs.indexOf("/>", notifs.indexOf("<group_invites")));
+ }
+
+ Vector<Long> groupsDatasAsLong = new Vector<Long>();
+ Vector<String> groupsDatas = new Vector<String>();
+
+ //Getting friends uid that ask for friends.
+ if(groupString.contains("<gid>"))
+ {
+ while(groupString.contains("<gid>"))
+ {
+ String friend = groupString.substring(
+ groupString.indexOf("<gid>") + "<gid>".length(),
+ groupString.indexOf("</gid>"));
+
+ groupString = groupString.replace("<gid>" + friend + "</gid>", "");
+
+ groupsDatasAsLong.add(Long.valueOf(friend).longValue());
+ }
+
+ groupsDatas.add(String.valueOf(groupsDatasAsLong.size()));
+
+ for(Long gid : groupsDatasAsLong)
+ {
+ try
+ {
+ connection.getClient().fql_query("Select name from group WHERE gid=" + gid.longValue());
+ String response = connection.getClient().getRawResponse();
+ if(response.contains("<group>") && response.contains("<name>"))
+ {
+ String groupName = response.substring(
+ response.indexOf("<name>") + "<name>".length(),
+ response.indexOf("</name>", response.indexOf("<name>")));
+ groupsDatas.add(groupName);
+ }
+ }
+ catch(Exception fqlError)
+ {
+ groupsDatas.add("Unknown group");
+ }
+ }
+
+ //Only if they have some group invites.
+ if(groupsDatasAsLong.size() > 0)
+ {
+ notifications.put("group_invites", groupsDatas);
+ }
+ }
+ }
+
+ /**
+ * Getting new events invitations.
+ */
+ if(notifs.contains("<event_invites"))
+ {
+ String eventString = "";
+ try
+ {
+ eventString = notifs.substring(notifs.indexOf("<event_invites"), notifs.indexOf("/>", notifs.indexOf("<event_invites")));
+ }
+ catch(IndexOutOfBoundsException indexError)
+ {
+ eventString = notifs.substring(notifs.indexOf("<event_invites"), notifs.indexOf("</event_invites>"));
+ }
+
+ Vector<Long> eventsDatasAsLong = new Vector<Long>();
+ Vector<String> eventsDatas = new Vector<String>();
+
+ //Getting friends uid that ask for friends.
+ if(eventString.contains("<eid>"))
+ {
+ while(eventString.contains("<eid>"))
+ {
+ String friend = eventString.substring(
+ eventString.indexOf("<eid>") + "<eid>".length(),
+ eventString.indexOf("</eid>"));
+
+ eventString = eventString.replace("<eid>" + friend + "</eid>", "");
+
+ eventsDatasAsLong.add(Long.valueOf(friend).longValue());
+ }
+
+ //Getting events names.
+ connection.getClient().events_get(connection.getFacebookUserId(), eventsDatasAsLong, Long.valueOf(0), Long.valueOf(0));
+ EventsGetResponse response = (EventsGetResponse) connection.getClient().getResponsePOJO();
+ List<Event> events = response.getEvent();
+
+ //Adding the number of event invites.
+ eventsDatas.add(String.valueOf(eventsDatasAsLong.size()));
+
+ for(Event event : events)
+ {
+ if(eventsDatasAsLong.contains(event.getEid()))
+ {
+ eventsDatas.add(event.getName());
+ }
+ }
+
+ if(eventsDatasAsLong.size() > 0)
+ {
+ notifications.put("event_invites", eventsDatas);
+ }
+ }
+ }
+ }
+ catch (FacebookException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ return notifications;
+ }
}
Modified: software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookGadget.java
===================================================================
--- software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookGadget.java 2009-05-25 12:00:06 UTC (rev 4662)
+++ software_suite_v2/software/gadgets/tuxdroid-gadget-facebook/trunk/tuxdroid-gadget-facebook/src/FacebookGadget.java 2009-05-25 12:45:53 UTC (rev 4663)
@@ -41,6 +41,11 @@
*/
public static class Configuration extends SimpleGadgetConfiguration{
+ private boolean showFriendRequests = true;
+ private boolean showGroupsInvites = true;
+ private boolean showEventsInvites = true;
+ private boolean showPokes = true;
+ private boolean notifyEmail = true;
}
/**
|