diff options
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java')
-rw-r--r-- | app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java | 235 |
1 files changed, 0 insertions, 235 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java b/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java deleted file mode 100644 index acfb44be..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/twitter/UserStreamListener.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.twitter; - -import net.lacolaco.smileessence.R; -import net.lacolaco.smileessence.World; -import net.lacolaco.smileessence.entity.DirectMessage; -import net.lacolaco.smileessence.entity.Event; -import net.lacolaco.smileessence.entity.Tweet; -import net.lacolaco.smileessence.entity.User; -import net.lacolaco.smileessence.logging.Logger; -import twitter4j.ConnectionLifeCycleListener; -import twitter4j.Status; -import twitter4j.StatusDeletionNotice; - -public class UserStreamListener implements twitter4j.UserStreamListener, ConnectionLifeCycleListener { - private final World world; - private boolean connected = false; - - public UserStreamListener(World world) { - this.world = world; - } - - public boolean isConnected() { - return connected; - } - - @Override - public void onConnect() { - connected = true; - world.notify(R.string.notice_stream_connect); - } - - @Override - public void onDisconnect() { - connected = false; - world.notify(R.string.notice_stream_disconnect); - } - - @Override - public void onCleanUp() { - } - - // --------------------- Interface StatusListener --------------------- - - @Override - public void onStatus(Status status) { - User user = world.getAccount().getUser(); - Tweet tweet = Tweet.fromTwitter(status, user.getId()); - world.addTweet(tweet); - if (tweet.isRetweet()) { - if (tweet.getOriginalTweet().getUser().getId() == user.getId()) { - addToHistory(new Event(Event.EnumEvent.RETWEETED, tweet.getUser(), tweet)); - } - } else if (tweet.getMentions().contains(user.getScreenName())) { - Event mentioned = new Event(Event.EnumEvent.MENTIONED, tweet.getUser(), tweet); - world.notify(mentioned.getFormattedString()); - } - } - - @Override - public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { - // FIXME - // StatusFilter.getInstance().remove(StatusViewModel.class, statusDeletionNotice.getStatusId()); - // Tweet.remove(statusDeletionNotice.getStatusId()); - } - - @Override - public void onTrackLimitationNotice(int numberOfLimitedStatuses) { - } - - @Override - public void onScrubGeo(long userId, long upToStatusId) { - } - - @Override - public void onStallWarning(twitter4j.StallWarning warning) { - } - - // --------------------- Interface StreamListener --------------------- - - @Override - public void onException(Exception ex) { - Logger.error(ex.toString()); - } - - // --------------------- Interface UserStreamListener --------------------- - - @Override - public void onDeletionNotice(long directMessageId, long userId) { - // FIXME - // StatusFilter.getInstance().remove(MessageViewModel.class, directMessageId); - // DirectMessage.remove(directMessageId); - } - - @Override - public void onFriendList(long[] friendIds) { - } - - @Override - public void onFavorite(twitter4j.User source, twitter4j.User target, Status favoritedStatus) { - Tweet tweet = Tweet.fromTwitter(favoritedStatus, world.getAccount().getUserId()); - tweet.addFavoriter(source.getId()); - if (User.fromTwitter(target) == world.getAccount().getUser()) { - addToHistory(new Event(Event.EnumEvent.FAVORITED, User.fromTwitter(source), tweet)); - } - } - - @Override - public void onUnfavorite(twitter4j.User source, twitter4j.User target, twitter4j.Status unfavoritedStatus) { - Tweet tweet = Tweet.fromTwitter(unfavoritedStatus, world.getAccount().getUserId()); - tweet.removeFavoriter(source.getId()); - if (User.fromTwitter(target) == world.getAccount().getUser()) { - addToHistory(new Event(Event.EnumEvent.UNFAVORITED, User.fromTwitter(source), tweet)); - } - } - - @Override - public void onFollow(twitter4j.User source, twitter4j.User followedUser) { - if (User.fromTwitter(followedUser) == world.getAccount().getUser()) { - addToHistory(new Event(Event.EnumEvent.FOLLOWED, User.fromTwitter(source))); - } - } - - @Override - public void onUnfollow(twitter4j.User source, twitter4j.User unfollowedUser) { - } - - @Override - public void onDirectMessage(twitter4j.DirectMessage directMessage) { - DirectMessage message = DirectMessage.fromTwitter(directMessage); - world.addDirectMessage(message); - if (message.getRecipient() == world.getAccount().getUser()) { - addToHistory(new Event(Event.EnumEvent.RECEIVE_MESSAGE, message.getSender())); - } - } - - @Override - public void onUserListMemberAddition(twitter4j.User addedMember, twitter4j.User listOwner, twitter4j.UserList list) { - } - - @Override - public void onUserListMemberDeletion(twitter4j.User deletedMember, twitter4j.User listOwner, twitter4j.UserList list) { - } - - @Override - public void onUserListSubscription(twitter4j.User subscriber, twitter4j.User listOwner, twitter4j.UserList list) { - world.addListSubscription(list.getFullName()); - } - - @Override - public void onUserListUnsubscription(twitter4j.User subscriber, twitter4j.User listOwner, twitter4j.UserList list) { - world.removeListSubscription(list.getFullName()); - } - - @Override - public void onUserListCreation(twitter4j.User listOwner, twitter4j.UserList list) { - world.addListSubscription(list.getFullName()); - } - - @Override - public void onUserListUpdate(twitter4j.User listOwner, twitter4j.UserList list) { - } - - @Override - public void onUserListDeletion(twitter4j.User listOwner, twitter4j.UserList list) { - world.removeListSubscription(list.getFullName()); - } - - @Override - public void onUserProfileUpdate(twitter4j.User updatedUser) { - User.fromTwitter(updatedUser); - } - - @Override - public void onUserSuspension(long suspendedUser) { - } - - @Override - public void onUserDeletion(long deletedUser) { - } - - @Override - public void onBlock(twitter4j.User source, twitter4j.User blockedUser) { - if (User.fromTwitter(blockedUser) == world.getAccount().getUser()) { - addToHistory(new Event(Event.EnumEvent.BLOCKED, User.fromTwitter(source))); - } - } - - @Override - public void onUnblock(twitter4j.User source, twitter4j.User unblockedUser) { - if (User.fromTwitter(unblockedUser) == world.getAccount().getUser()) { - addToHistory(new Event(Event.EnumEvent.UNBLOCKED, User.fromTwitter(source))); - } - } - - @Override - public void onRetweetedRetweet(twitter4j.User source, twitter4j.User target, twitter4j.Status retweetedStatus) { - } - - @Override - public void onFavoritedRetweet(twitter4j.User source, twitter4j.User target, twitter4j.Status favoritedRetweeet) { - } - - @Override - public void onQuotedTweet(twitter4j.User source, twitter4j.User target, twitter4j.Status quotingTweet) { - } - - private void addToHistory(Event mentioned) { - world.addEvent(mentioned); - world.notify(mentioned.getFormattedString()); - } -} |