OSDN Git Service

自分宛のメッセージ,DMが到着した際に,タスクトレイの通知バーでメッセージ到着をお知らせする機能を追加
[nt-manager/nt-manager.git] / src / twitter / action / TweetMentionGetter.java
index 12db606..2e6a05f 100644 (file)
@@ -5,10 +5,12 @@
 
 package twitter.action;
 
+import java.awt.TrayIcon;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import twitter.manage.TweetManager;
+import twitter.manage.TweetNotifyManager;
 import twitter4j.Status;
 import twitter4j.TwitterException;
 
@@ -20,6 +22,10 @@ public class TweetMentionGetter implements TweetGetter{
 
     //tweet管理用
     private TweetManager tweetManager;
+    //通知
+    private TweetNotifyManager notifyManager = null;
+    //1回目の最初の呼び出しかどうか, 1回目の呼び出しの際は通知バーにメッセージを表示しない
+    private boolean isFirstTime = true;
 
     /**
      *
@@ -30,6 +36,16 @@ public class TweetMentionGetter implements TweetGetter{
     }
 
     /**
+     *
+     * @param tweetManager
+     * @param trayIcon タスクバーの通知用アイコン
+     */
+    public TweetMentionGetter(TweetManager tweetManager, TrayIcon trayIcon) {
+        this.tweetManager = tweetManager;
+        this.notifyManager = new TweetNotifyManager(trayIcon);
+    }
+
+    /**
      * Mentionツイートを指定した数だけ取得
      * @param num
      * @return
@@ -39,6 +55,10 @@ public class TweetMentionGetter implements TweetGetter{
         List<Status> status = null;
         try {
             status = tweetManager.getMentions(num);
+            if( notifyManager != null && isFirstTime == false) {
+                this.notifyManager.showNotifyMessage(status);
+            }
+            isFirstTime = false;
         } catch (TwitterException ex) {
             Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
         }
@@ -54,6 +74,10 @@ public class TweetMentionGetter implements TweetGetter{
         List<Status> status = null;
         try {
             status = tweetManager.getNewMentionData();
+            if( notifyManager != null && isFirstTime == false) {
+                this.notifyManager.showNotifyMessage(status);
+            }
+            isFirstTime = false;
         } catch (TwitterException ex) {
             Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
         }