[tuxdroid-svn] r5955 - software_suite_v3/software/plugin/plugin-twitter/trunk/src
Status: Beta
Brought to you by:
ks156
From: jerome <c2m...@c2...> - 2009-12-08 14:17:53
|
Author: jerome Date: 2009-12-08 15:17:40 +0100 (Tue, 08 Dec 2009) New Revision: 5955 Modified: software_suite_v3/software/plugin/plugin-twitter/trunk/src/Configuration.java software_suite_v3/software/plugin/plugin-twitter/trunk/src/TwitterPlugin.java Log: * Added 'read tweets' function. Modified: software_suite_v3/software/plugin/plugin-twitter/trunk/src/Configuration.java =================================================================== --- software_suite_v3/software/plugin/plugin-twitter/trunk/src/Configuration.java 2009-12-08 14:17:25 UTC (rev 5954) +++ software_suite_v3/software/plugin/plugin-twitter/trunk/src/Configuration.java 2009-12-08 14:17:40 UTC (rev 5955) @@ -33,6 +33,8 @@ private boolean checkFriends = true; private boolean checkMessages = true; + + private boolean readTweets = false; private String defaultUser = "your_user_name"; private String defaultPassword = "_secret_"; @@ -164,5 +166,25 @@ { return this.checkMessages; } + + + /** + * Set or not the read tweets option. + * @param. + */ + public void setReadTweets(boolean aReadTweets) + { + this.readTweets = aReadTweets; + } + + /** + * Return true if user want to read his tweets content. + * @return + */ + public boolean getReadTweets() + { + return this.readTweets; + } + } Modified: software_suite_v3/software/plugin/plugin-twitter/trunk/src/TwitterPlugin.java =================================================================== --- software_suite_v3/software/plugin/plugin-twitter/trunk/src/TwitterPlugin.java 2009-12-08 14:17:25 UTC (rev 5954) +++ software_suite_v3/software/plugin/plugin-twitter/trunk/src/TwitterPlugin.java 2009-12-08 14:17:40 UTC (rev 5955) @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.Hashtable; import java.util.List; import java.util.Vector; import java.util.Random; @@ -41,6 +42,11 @@ private List<String> messagesList = new ArrayList<String>(); private List<String> repliesList = new ArrayList<String>(); + + //Pre-formated messages in case of read tweets content option enabled. + private Vector<Hashtable<String, String>> privateMessages = new Vector<Hashtable<String, String>>(); + private Vector<Hashtable<String, String>> publicMessages = new Vector<Hashtable<String, String>>(); + private Vector<Hashtable<String, String>> friendUpdates = new Vector<Hashtable<String, String>>(); private boolean throwed = false; @@ -165,6 +171,13 @@ statusesCount += 1; //Saving last entry. savedStruct.addFriendStatus(username, statusText); + + //Registering pre formated message. + Hashtable<String, String> hash = new Hashtable<String, String>(); + hash.put("name", username); + hash.put("value", stat); + //adding message to the list of private messages. + this.friendUpdates.add(hash); } } } @@ -188,6 +201,7 @@ private int getPrivateMessagesCount(Twitter twitter) { List<Message> messages = twitter.getDirectMessages(); + if(messages.size() > 0) { try @@ -203,6 +217,13 @@ { messagesList.add(username); savedStruct.addMessage(username, message.getText()); + + //Registering pre formated message. + Hashtable<String, String> hash = new Hashtable<String, String>(); + hash.put("name", username); + hash.put("value", message.getText()); + //adding message to the list of private messages. + this.privateMessages.add(hash); } } } @@ -239,6 +260,13 @@ { repliesList.add(username); savedStruct.addReply(username, reply.getText()); + + //Registering pre formated message. + Hashtable<String, String> hash = new Hashtable<String, String>(); + hash.put("name", username); + hash.put("value", reply.getText()); + //adding message to the list of private messages. + this.publicMessages.add(hash); } } @@ -303,17 +331,31 @@ //First check insilent mode. if(this.getCommand().equalsIgnoreCase("run") || secondCycle) { - - if ( updateCount == 1 ) + + if ((updateCount == 1) && (!this.configuration().getReadTweets())) { throwRes(); throwMessage(pickSentence(newSingleTweetSentences)); } - else if ( updateCount > 1 ) + else if ((updateCount > 1) && (!this.configuration().getReadTweets())) { throwRes(); throwMessage(pickSentence(newMultipleTweetSentences), String.valueOf(updateCount)); } + + else if(this.configuration().getReadTweets()) + { + throwRes(); + int i = 0; + while( i != this.friendUpdates.size()) + { + Hashtable<String, String> hash = this.friendUpdates.get( i ); + throwMessage("Status update from {0}, {1}", hash.get("name"), hash.get("value")); + i++; + } + this.friendUpdates.clear(); + } + else { if ( ! this.getCommand().equalsIgnoreCase("check") ) @@ -336,9 +378,26 @@ //First check insilent mode. if(this.getCommand().equalsIgnoreCase("run") || secondCycle) { - this.sort(this.messagesList); - //Counting by name and throwing messages. - this.getByNames(this.messagesList, MESSAGE); + if(!this.configuration().getReadTweets()) + { + this.sort(this.messagesList); + //Counting by name and throwing messages. + this.getByNames(this.messagesList, MESSAGE); + } + else + { + //Readong tweet content. + this.throwRes(); + + int i = 0; + while( i != this.privateMessages.size()) + { + Hashtable<String, String> hash = this.privateMessages.get( i ); + throwMessage("Message from {0}, {1}", hash.get("name"), hash.get("value")); + i++; + } + this.privateMessages.clear(); + } } } else @@ -355,9 +414,26 @@ //First check insilent mode. if(this.getCommand().equalsIgnoreCase("run") || secondCycle) { - this.sort(this.repliesList); - //Counting by name and throwing messages. - this.getByNames(this.repliesList, REPLY); + if(!this.configuration().getReadTweets()) + { + this.sort(this.repliesList); + //Counting by name and throwing messages. + this.getByNames(this.repliesList, REPLY); + } + else + { + //Reading tweet content. + this.throwRes(); + + int i = 0; + while( i != this.publicMessages.size()) + { + Hashtable<String, String> hash = this.publicMessages.get( i ); + throwMessage("Reply from {0}, {1}", hash.get("name"), hash.get("value")); + i++; + } + this.publicMessages.clear(); + } } } else |