Author: jerome
Date: 2009-10-07 15:19:28 +0200 (Wed, 07 Oct 2009)
New Revision: 5608

Modified:
   
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/Configuration.java
   
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/TwitterPlugin.java
Log:
* Modified the way to advice user something changed on his Twitter account.
* Exclusive update status function.
* Refactored project.
* Removed / replaced some functions.
*...

Modified: 
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/Configuration.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/Configuration.java
     2009-10-07 12:04:00 UTC (rev 5607)
+++ 
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/Configuration.java
     2009-10-07 13:19:28 UTC (rev 5608)
@@ -27,10 +27,14 @@
 
        private String username = "";
        private String password = "";
+       
        private String myStatus = "Hello all from my tuxdroid Twitter gadget";
-       private boolean updateStatus = true;
+       private boolean updateStatus = false;
        
+       private boolean checkFriends = true;
+       private boolean checkMessages = true;
        
+       
        /**
         * Sets the username.
         * @param username
@@ -108,5 +112,45 @@
        {
                return this.updateStatus;
        }
+       
+       
+       /**
+        * Set or not the checkf friends updates check.
+        * @param updateStatus
+        */
+       public void setCheckFriends(boolean aCheckFriends)
+       {
+               this.checkFriends = aCheckFriends;
+       }
+       
+       
+       /**
+        * Return true if user want to check his new friends statuses.
+        * @return
+        */
+       public boolean getCheckFriends()
+       {
+               return this.checkFriends;
+       }
+       
+       
+       /**
+        * Set or not the check messages option.
+        * @param updateStatus
+        */
+       public void setCheckMessages(boolean aCheckMessages)
+       {
+               this.checkMessages = aCheckMessages;
+       }
+       
+       
+       /**
+        * Return true if user want to check his replies / messages.
+        * @return
+        */
+       public boolean getCheckMessages()
+       {
+               return this.checkMessages;
+       }
 
 }

Modified: 
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/TwitterPlugin.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/TwitterPlugin.java
     2009-10-07 12:04:00 UTC (rev 5607)
+++ 
software_suite_v3/software/plugin/plugin-twitter/branches/october_release/plugin-twitter/src/TwitterPlugin.java
     2009-10-07 13:19:28 UTC (rev 5608)
@@ -19,6 +19,10 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Hashtable;
 import java.util.List;
 import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin;
 import winterwell.jtwitter.Twitter;
@@ -31,15 +35,19 @@
 public class TwitterPlugin extends SimplePlugin<Configuration>{
 
        private static TwitterDatasStruct savedStruct;
+       private static byte REPLY = 0;
+       private static byte MESSAGE = 1;
        
+       private List<String> messagesList = new ArrayList<String>();
+       private List<String> repliesList = new ArrayList<String>();
        
+       
        /***
          This function set the new user status.
          Préconditions :
            - To be in run mode
            - Activate targeted option. 
        ***/
-       @SuppressWarnings("unused")
        private boolean setUserStatus(Twitter twitter)
        {
                if(this.getCommand().equalsIgnoreCase("run"))
@@ -70,7 +78,6 @@
         ***/
        private int getNewFriendStatusesCount(Twitter twitter)
        {
-               
                int statusesCount = 0;
                List<User> friend = twitter.getFriends();
                        
@@ -82,6 +89,7 @@
                                
                            String statusText = status.getText();
                            String username = status.getUser().getName();
+                           
                                
                            //if a new status was set for this user text.
                            boolean said = 
savedStruct.isRegistered(TwitterDatasStruct.FRIENDS_STATUSES, username, 
statusText); 
@@ -118,7 +126,6 @@
         ***/
        private int getPrivateMessagesCount(Twitter twitter)
        {
-               int messagesCount = 0;
                List<Message> messages = twitter.getDirectMessages();
                if(messages.size() > 0)
                {
@@ -133,7 +140,7 @@
                                
                                    if((message.getText() != "null") && !said)
                                    {           
-                                           messagesCount += 1;
+                                           messagesList.add(username);
                                            savedStruct.addMessage(username, 
message.getText());
                                    }
                            }
@@ -144,7 +151,7 @@
                        }
                }
                
-               return messagesCount;
+               return messagesList.size();
        }
        
        
@@ -155,7 +162,6 @@
         ***/
        private int getPublicMessagesCount(Twitter twitter)
        {
-               int repliesCount = 0;
                List<Message> replies = twitter.getReplies();
 
                if(replies.size() > 0)
@@ -170,7 +176,7 @@
                                        
                                    if((reply.getText() != "null") && !said)
                                    {   
-                                       repliesCount += 1;
+                                       repliesList.add(username);
                                        savedStruct.addReply(username, 
reply.getText());
                                    }
                                        
@@ -181,7 +187,7 @@
                        ;
                    }
                }
-               return repliesCount;
+               return repliesList.size();
        }
        
        
@@ -202,9 +208,65 @@
                //Getting Twitter informations.
                try
                {
-                   throwMessage("New Friend updates: " + 
String.valueOf(getNewFriendStatusesCount(twitter)));
-                   throwMessage("New Replies: " + 
String.valueOf(getPublicMessagesCount(twitter)));
-                   throwMessage("New Messages: " + 
String.valueOf(getPrivateMessagesCount(twitter)));
+                       if (! this.configuration().getUpdateStatus())
+                       {
+                               //Getting new friend statuses count.
+                               int updateCount = 
getNewFriendStatusesCount(twitter);
+                               if ( updateCount == 1 )
+                               {
+                                       throwMessage("You have a new friend 
update");
+                               }
+                               else if ( updateCount > 1 )
+                               {
+                                       throwMessage("Yo have {0} friend 
updates", String.valueOf(updateCount));
+                               }
+                               else
+                               {
+                                       if ( ! 
this.getCommand().equalsIgnoreCase("check") )
+                                       {
+                                           throwMessage("You don't have any 
friend updates.");
+                                       }
+                               }
+                           
+                           //Getting and sorting new user replies.
+                           if ( getPublicMessagesCount(twitter) > 0 )
+                           {
+                               this.sort(this.repliesList);
+                               //Counting by name and throwing messages.
+                               this.getByNames(this.repliesList, REPLY);
+                           }
+                           else
+                           {
+                               if ( ! 
this.getCommand().equalsIgnoreCase("check") )
+                               {
+                                           throwMessage("You don't have any 
replies");
+                               }
+                           }
+                           
+                           //Getting and sorting new user private messages.
+                           if ( getPrivateMessagesCount(twitter) > 0 )
+                           {
+                               this.sort(this.messagesList);
+                       //Counting by name and throwing messages.
+                               this.getByNames(this.messagesList, MESSAGE);
+                           }
+                           else
+                           {
+                               if ( ! 
this.getCommand().equalsIgnoreCase("check") )
+                               {
+                                   throwMessage("You don't have any messages");
+                               }
+                           }
+                           
+                           //Registering couted messages.
+                               savedStruct.registerStruct();
+                               
+                       }
+                       else
+                       {
+                               //Updating user status.
+                               this.setUserStatus(twitter);
+                       }
                }
                catch(TwitterException badRequest)
                {
@@ -212,12 +274,86 @@
                        {
                                throwMessage("Twitter is busy for now, please, 
try later.");
                        }
-                       
+                               
                        this.quitGadget();
                }
+                       
+       }
+       
+       
+       /***
+        * Sort a typ string list.
+        * @param list
+        */
+       private void sort(List<String> list)
+       {
+               Collections.sort(list);
+       }
+       
+       
+       /***
+        * Throw messages by user names.
+        * @param list
+        */
+       private void getByNames(List<String> list, byte type)
+       {
+               Hashtable<String, Integer> dtUsers = new Hashtable<String, 
Integer>();
+               int count = 1;
                
-               //Registering couted messages.
-               //savedStruct.registerStruct();
+               //Handling no replies / no messages.
+               if (list.size() == 0)
+               {
+                       return;
+               }
+               else
+               {
+                       throwMessage("You have");
+               }
+                               
+               
+               //Counting by names.
+               for( int i = 0 ; i != list.size() - 1 ; i ++)
+               {
+                       if ( list.get( i ).equals(list.get( i + 1 )))
+                       {
+                               count += 1;
+                       }
+                       else
+                       {
+                               dtUsers.put(list.get(i), 
Integer.valueOf(count));
+                               count = 1;
+                       }
+               }
+               
+               Enumeration<String> enu = dtUsers.keys();
+               while( enu.hasMoreElements())
+               {
+                       String it = enu.nextElement();
+                       count = dtUsers.get(it).intValue();
+                       
+                       if ( type == REPLY )
+                       {
+                               if ( count == 1 )
+                               {
+                               throwMessage("One reply from {0}", it);
+                               }
+                               else
+                               {
+                                       throwMessage ("{0} replies from {1}", 
count, it);
+                               }
+                       }
+                       else
+                       {
+                               if ( count == 1 )
+                               {
+                               throwMessage("One message from {0}", it);
+                               }
+                               else
+                               {
+                                       throwMessage("{0} messages from {1}", 
count, it);
+                               }
+                       }
+               }
        }
 
 
@@ -303,10 +439,10 @@
         */
        public void quitGadget()
        {
-               if(this.getCommand().equalsIgnoreCase("check") && this.throwed)
-               {
-                       this.throwResult(false);
-               }
+               //if(this.getCommand().equalsIgnoreCase("check") && 
this.throwed)
+               //{
+                       //this.throwResult(false);
+               //}
                System.exit(0);
        }
        


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to