[tuxdroid-svn] r5753 - in software_suite_v3/software/plugin/plugin-facebook/branches/october_releas
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-10-20 15:16:47
|
Author: jerome
Date: 2009-10-20 17:16:34 +0200 (Tue, 20 Oct 2009)
New Revision: 5753
Modified:
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java
Log:
* Added an option.
* Refactored plugin main entry point.
* Make use of the new functions.
* Renamed two functions.
* Cleanup.
Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java
===================================================================
--- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java 2009-10-20 14:14:38 UTC (rev 5752)
+++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java 2009-10-20 15:16:34 UTC (rev 5753)
@@ -103,7 +103,7 @@
/**
* Prompt for plugin facebook authorizations.
*/
- public void promptAuthorizations()
+ public static void promptAuthorizations()
{
String url = "http://www.facebook.com/login.php?api_key=+" +
FacebookSessionUtils.api_key +
Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java
===================================================================
--- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java 2009-10-20 14:14:38 UTC (rev 5752)
+++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java 2009-10-20 15:16:34 UTC (rev 5753)
@@ -191,7 +191,7 @@
* Return availables group invites names.
* @return
*/
- public Vector<String> getGroupsInvites()
+ public Vector<String> getGroupInvites()
{
Vector<String> result = new Vector<String>();
@@ -237,7 +237,7 @@
* Return event invites names.
* @return
*/
- public Vector<String> getEventsInvites()
+ public Vector<String> getEventInvites()
{
Vector<String> result = new Vector<String>();
Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java
===================================================================
--- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java 2009-10-20 14:14:38 UTC (rev 5752)
+++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java 2009-10-20 15:16:34 UTC (rev 5753)
@@ -23,171 +23,256 @@
package com.kysoh.plugins.facebook;
+import java.util.Hashtable;
+import java.util.Vector;
+
import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin;
import com.kysoh.plugins.facebook.configuration.PluginFacebookConfiguration;
+import com.kysoh.plugins.facebook.FacebookConnection;
public class FacebookPlugin extends SimplePlugin<PluginFacebookConfiguration>{
private boolean check = false;
+ private boolean throwed = false;
+ private FacebookFunctions functions;
/**
+ * Throws the result in case of Check mode.
+ */
+ private void throwRes()
+ {
+ if(this.check && (!throwed))
+ {
+ throwed = true;
+ this.throwResult(true);
+ }
+ }
+
+ /**
* Gadget start method.
*/
@Override
protected void start() throws Throwable
- {
- boolean throwNotif = false;
- boolean news = false;
-
- if(getCommand().equals("check"))
+ {
+ if (this.getCommand().equalsIgnoreCase("configure"))
{
- this.check = true;
+ //Prompt web browser for facebook permissions.
+ FacebookConnection.promptAuthorizations();
+ //TODO check actual permissions.
}
+ else
+ {
+ this.RunOrCheck();
+ }
+ }
+
+
+ /**
+ * Start run or check command.
+ */
+ public void RunOrCheck()
+ {
FacebookConnection facebook = new FacebookConnection();
+
if ( facebook.Connect(this.configuration().getLogin(), this.configuration().getPassword()) )
{
- FacebookFunctions functions = new FacebookFunctions(facebook);
+ functions = new FacebookFunctions(facebook.getClient());
- //Get email informations.
+ //Updating user status.
+ if(this.configuration().getUpdateStatus())
+ {
+ this.updateStatus();
+ }
+
+ //Fetching email informations.
if(this.configuration().getNotifyEmail())
{
- if(functions.getEmailNotifications().intValue() > 0)
- {
- news = true;
- if(this.check && (!throwNotif))
- {
- throwNotif = true;
- this.throwResult(true);
- }
-
- if(functions.getEmailNotifications().intValue() == 1)
- {
- throwMessage("You have one new message");
- }
- else
- {
- throwMessage("You have {0} new messages", functions.getEmailNotifications().intValue());
- }
- }
+ this.throwEMails();
}
- //Get friend requests notification.
+ //Fetching friend requests notification.
if(this.configuration().getShowFriendRequests())
{
- if(functions.getFriendRequestsCount().intValue() > 0)
- {
- news = true;
- if(this.check && (!throwNotif))
- {
- throwNotif = true;
- this.throwResult(true);
- }
-
- if(functions.getFriendRequestsCount().intValue() == 1)
- {
- throwMessage("You have one friend request");
- }
- else
- {
- throwMessage("You have {0} friend requests", functions.getFriendRequestsCount());
- }
-
- for(String friendName : functions.getFriendRequestNames())
- {
- if(this.check && (!throwNotif))
- {
- throwNotif = true;
- this.throwResult(true);
- }
- throwMessage("From {0}", friendName);
- }
- }
+ this.throwFriendRequests();
}
//Get group invites notifications.
if(this.configuration().getShowGroupsInvites())
{
- news = true;
- if(functions.getGroupsInvitesCount().intValue() > 0)
- {
- if(this.check && (!throwNotif))
- {
- throwNotif = true;
- this.throwResult(true);
- }
-
- if(functions.getGroupsInvitesCount().intValue() == 1)
- {
- throwMessage("You have one group invite");
- }
- else
- {
- throwMessage("You have {0} group invites", functions.getGroupsInvitesCount().intValue());
- }
-
- for(String group : functions.getGroupInvitesNames())
- {
- if(this.check && (!throwNotif))
- {
- throwNotif = true;
- this.throwResult(true);
- }
- throwMessage("to {0}", group);
- }
- }
+ this.throwGroupInvites();
}
//Get pokes notification.
if(this.configuration().getShowEventsInvites())
{
- if(functions.getEventsInvitesCount().intValue() > 0)
- {
- news = true;
- if(this.check && (!throwNotif))
- {
- throwNotif = true;
- this.throwResult(true);
- }
-
- if(functions.getEventsInvitesCount().intValue() == 1)
- {
- throwMessage("You have one event invite");
- }
- else
- {
- throwMessage("You have {0} event invites", functions.getEventsInvitesCount().intValue());
- }
-
- for(String event : functions.getEventInvitesNames())
- {
- if(this.check && (!throwNotif))
- {
- throwNotif = true;
- this.throwResult(true);
- }
- throwMessage("to {0}", event);
- }
- }
+ this.throwEventInvites();
}
- if((!throwNotif) && this.check )
+ if(( !this.throwed ) && this.getCommand().equalsIgnoreCase("check") )
{
this.throwResult(false);
}
- else if((!this.check) && (!news))
+ }
+ else
+ {
+ this.throwMessage("I cannot get connected to your facebook account.");
+ }
+ }
+
+
+ /**
+ * Update user status.
+ */
+ private void updateStatus()
+ {
+ //Updating user status.
+ if(functions.publishFeed(this.configuration().getStatusText()))
+ {
+ this.throwMessage("Your new status was published");
+ }
+ else
+ {
+ this.throwMessage("An error occured trying to set your new status, please, try again later");
+ }
+ }
+
+
+ /**
+ * Throw all incommin emails.
+ */
+ private void throwEMails()
+ {
+ //Fetching mails.
+ Hashtable<String, Vector<String>> inbox = new Hashtable<String, Vector<String>>();
+ inbox = functions.getEmailNotifications();
+
+ if(functions.getEmailNotifications().size() == 1)
+ {
+ throwRes();
+ throwMessage("You have one new message");
+ }
+
+ else if(inbox.size() > 1)
+ {
+ throwRes();
+ this.throwMessage("You have {0} messages", inbox.size());
+ }
+ else
+ {
+ if (!this.getCommand().equalsIgnoreCase("check"))
{
- this.throwMessage("Nothing new on your account");
+ this.throwMessage("You don't have any messages");
}
}
+ //TODO throwing emails by sender.
+ }
+
+
+ /**
+ * Throw all friend requests.
+ */
+ private void throwFriendRequests()
+ {
+ Vector<String> f_requests = new Vector<String>();
+ f_requests = functions.getFriendRequests();
+
+ if (f_requests.size() > 1)
+ {
+ throwRes();
+ this.throwMessage("You have {0} friend requests", f_requests.size());
+ for(String request : f_requests)
+ {
+ this.throwMessage("From {0}", request);
+ }
+ }
+ else if(f_requests.size() == 1)
+ {
+ throwRes();
+ throwMessage("You have one friend request");
+ this.throwMessage("From {0}", f_requests.get(0));
+ }
else
{
- this.throwMessage("I cannot get connected to your facebook account.");
+ if (! this.getCommand().equalsIgnoreCase("check"))
+ {
+ this.throwMessage("You don't have any friend requests");
+ }
}
}
+
/**
+ * Throw all group invites.
+ */
+ private void throwGroupInvites()
+ {
+ //Fetching group invites.
+ Vector<String> g_invites = new Vector<String>();
+ g_invites = functions.getGroupInvites();
+
+ if (g_invites.size() > 1)
+ {
+ throwRes();
+ this.throwMessage("You have {0} group invites", g_invites.size());
+ for(String group : g_invites)
+ {
+ this.throwMessage("From {0}", group);
+ }
+ }
+ else if(g_invites.size() == 1)
+ {
+ throwRes();
+ throwMessage("You have one group invite");
+ this.throwMessage("From {0}", g_invites.get(0));
+ }
+ else
+ {
+ if (! this.getCommand().equalsIgnoreCase("check"))
+ {
+ this.throwMessage("You don't have any group invites");
+ }
+ }
+ }
+
+
+ /**
+ * Throw all event invites.
+ */
+ private void throwEventInvites()
+ {
+ //Fetching event invites.
+ Vector<String> e_invites = new Vector<String>();
+ e_invites = functions.getEventInvites();
+
+ if (e_invites.size() > 1)
+ {
+ throwRes();
+ this.throwMessage("You have {0} event invites", e_invites.size());
+ for(String group : e_invites)
+ {
+ this.throwMessage("To {0}", group);
+ }
+ }
+ else if(e_invites.size() == 1)
+ {
+ throwRes();
+ throwMessage("You have one event invite");
+ this.throwMessage("To {0}", e_invites.get(0));
+ }
+ else
+ {
+ if (! this.getCommand().equalsIgnoreCase("check"))
+ {
+ this.throwMessage("You don't have any event invites");
+ }
+ }
+ }
+
+
+
+ /**
* Main entry point.
* @param args
*/
Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java
===================================================================
--- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java 2009-10-20 14:14:38 UTC (rev 5752)
+++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/configuration/PluginFacebookConfiguration.java 2009-10-20 15:16:34 UTC (rev 5753)
@@ -35,9 +35,30 @@
private boolean notifyEmail = true;
private String statusText = "Hello all from my Tux Droid Facebook gadget";
+ private boolean updateStatus = false;
/**
+ * Return true if user want update his status.
+ * @return
+ */
+ public boolean getUpdateStatus()
+ {
+ return this.updateStatus;
+ }
+
+
+ /**
+ * Set the user feed update.
+ * @param aLogin
+ */
+ public void setUpdateStatus(boolean aUpdateStatus)
+ {
+ this.updateStatus = aUpdateStatus;
+ }
+
+
+ /**
* Return the user feed to update.
* @return
*/
|