OSDN Git Service

自分宛のメッセージ,DMが到着した際に,タスクトレイの通知バーでメッセージ到着をお知らせする機能を追加
[nt-manager/nt-manager.git] / src / twitter / action / TweetMentionGetter.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5
6 package twitter.action;
7
8 import java.awt.TrayIcon;
9 import java.util.List;
10 import java.util.logging.Level;
11 import java.util.logging.Logger;
12 import twitter.manage.TweetManager;
13 import twitter.manage.TweetNotifyManager;
14 import twitter4j.Status;
15 import twitter4j.TwitterException;
16
17 /**
18  * Mentionを取得するクラス
19  * @author nishio
20  */
21 public class TweetMentionGetter implements TweetGetter{
22
23     //tweet管理用
24     private TweetManager tweetManager;
25     //通知
26     private TweetNotifyManager notifyManager = null;
27     //1回目の最初の呼び出しかどうか, 1回目の呼び出しの際は通知バーにメッセージを表示しない
28     private boolean isFirstTime = true;
29
30     /**
31      *
32      * @param tweetManager
33      */
34     public TweetMentionGetter(TweetManager tweetManager) {
35         this.tweetManager = tweetManager;
36     }
37
38     /**
39      *
40      * @param tweetManager
41      * @param trayIcon タスクバーの通知用アイコン
42      */
43     public TweetMentionGetter(TweetManager tweetManager, TrayIcon trayIcon) {
44         this.tweetManager = tweetManager;
45         this.notifyManager = new TweetNotifyManager(trayIcon);
46     }
47
48     /**
49      * Mentionツイートを指定した数だけ取得
50      * @param num
51      * @return
52      */
53     @Override
54     public List<Status> getTweetData(int num) {
55         List<Status> status = null;
56         try {
57             status = tweetManager.getMentions(num);
58             if( notifyManager != null && isFirstTime == false) {
59                 this.notifyManager.showNotifyMessage(status);
60             }
61             isFirstTime = false;
62         } catch (TwitterException ex) {
63             Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
64         }
65         return status;
66     }
67
68     /**
69      * Mentionツイートの新しく投稿されたものだけを取得
70      * @return
71      */
72     @Override
73     public List<Status> getNewTweetData() {
74         List<Status> status = null;
75         try {
76             status = tweetManager.getNewMentionData();
77             if( notifyManager != null && isFirstTime == false) {
78                 this.notifyManager.showNotifyMessage(status);
79             }
80             isFirstTime = false;
81         } catch (TwitterException ex) {
82             Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
83         }
84         return status;
85     }
86
87 }