diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-09-21 18:30:32 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-09-21 18:30:32 +0900 |
commit | c0a2acb9bbcb4b97189b64d5b4bf1eb02723017f (patch) | |
tree | 9f4ca9d63ce07f01cda6e26da3984be2d151034d /app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java | |
parent | 85a3626036785148c75ee6453e17c7efc74bece7 (diff) | |
download | SmileEssence-c0a2acb9bbcb4b97189b64d5b4bf1eb02723017f.tar.gz |
[WIP] BackgroundTask を導入
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java')
-rw-r--r-- | app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java index 2c7f8205..6419d3f5 100644 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java +++ b/app/src/main/java/net/lacolaco/smileessence/twitter/task/GetTalkTask.java @@ -1,7 +1,9 @@ package net.lacolaco.smileessence.twitter.task; +import net.lacolaco.smileessence.entity.Account; import net.lacolaco.smileessence.entity.Tweet; import net.lacolaco.smileessence.logging.Logger; +import net.lacolaco.smileessence.util.BackgroundTask; import twitter4j.Status; import twitter4j.Twitter; import twitter4j.TwitterException; @@ -9,26 +11,32 @@ import twitter4j.TwitterException; import java.util.ArrayList; import java.util.List; -public class GetTalkTask extends TwitterTaskWithProgress<List<Tweet>, Tweet> { +public class GetTalkTask extends BackgroundTask<List<Tweet>, Tweet> { + private final Account account; private final long statusId; - public GetTalkTask(Twitter twitter, long statusId) { - super(twitter); + public GetTalkTask(Account account, long statusId) { + this.account = account; this.statusId = statusId; } @Override protected List<Tweet> doInBackground(Void... params) { ArrayList<Tweet> list = new ArrayList<>(); + long id = statusId; try { - long id = statusId; while (id != -1) { - Tweet tweet = Tweet.fromTwitter(twitter.showStatus(id)); - if (tweet != null) { - publishProgress(tweet); - list.add(tweet); - } else { + Tweet tweet = Tweet.fetch(id); + if (tweet == null) { + tweet = Tweet.fromTwitter(account.getTwitter().showStatus(id)); + } + + if (tweet == null) { break; + } else { + list.add(tweet); + publishProgress(tweet); + id = tweet.getInReplyTo(); } } } catch (TwitterException e) { |