Example usage for twitter4j Status isRetweeted

List of usage examples for twitter4j Status isRetweeted

Introduction

In this page you can find the example usage for twitter4j Status isRetweeted.

Prototype

boolean isRetweeted();

Source Link

Document

Test if the status is retweeted

Usage

From source file:collector.TwitterCollector.java

public LinkedHashSet<Tweet> userSearchData(String userName, int maxResults) {

    LinkedHashSet<Tweet> out = new LinkedHashSet<>();
    Paging paging = new Paging(1, 180);
    int numberOfTweets = maxResults;//512;
    long lastID = Long.MAX_VALUE;
    ArrayList<Status> status = new ArrayList<>();
    while (status.size() < numberOfTweets) {
        if (numberOfTweets - status.size() > 180) {//100) {
            paging.setCount(180);//100);
        } else {/*from ww w.  j  av  a  2 s. c  o m*/
            paging.setCount(numberOfTweets - status.size());
        }
        try {
            List<Status> timeLine = twitter.getUserTimeline(userName, paging);
            status.addAll(timeLine);
            for (Status t : status) {
                if (t.getId() < lastID) {
                    lastID = t.getId();
                }
            }
        } catch (TwitterException ex) {
            System.err.println(ex.getMessage());
        }
        paging.setMaxId(lastID - 1);
    }

    //armazenar os atributos interessantes a analise dos tweets
    int qtdretweet = 0;
    for (Status sta : status) {
        String text = sta.getText();
        if (!sta.isRetweet() && !sta.isRetweeted() && !text.startsWith("RT")) { //&& !TweetMediaDetect.detect(text)) {
            TwitterUser user;
            user = new TwitterUser().addID(sta.getUser().getId()).addName(sta.getUser().getName())
                    .addLocation(sta.getUser().getLocation()).addDateSignin(sta.getUser().getCreatedAt())
                    .addCountTweets(sta.getUser().getStatusesCount())
                    .addCountFavorites(sta.getUser().getFavouritesCount())
                    .addCountFriends(sta.getUser().getFriendsCount())
                    .addCountFollowers(sta.getUser().getFollowersCount());
            Tweet tweet = new Tweet().addUser(user).addText(sta.getText()).addID(sta.getId())
                    .addDate(sta.getCreatedAt())
                    .addLatitude(sta.getGeoLocation() != null ? sta.getGeoLocation().getLatitude()
                            : Double.MAX_VALUE)
                    .addLongitude(sta.getGeoLocation() != null ? sta.getGeoLocation().getLongitude()
                            : Double.MAX_VALUE);
            out.add(tweet);
        } else {
            qtdretweet++;
        }
    }

    return out;
}

From source file:com.freshdigitable.udonroad.datastore.StatusReactionImpl.java

License:Apache License

public StatusReactionImpl(Status status) {
    this.id = status.getId();
    this.favorited = status.isFavorited();
    this.retweeted = status.isRetweeted();
}

From source file:com.freshdigitable.udonroad.module.realm.StatusReactionRealm.java

License:Apache License

public StatusReactionRealm(Status status) {
    this.id = status.getId();
    this.retweeted = status.isRetweeted();
    this.favorited = status.isFavorited();
}

From source file:com.freshdigitable.udonroad.StatusDetailFragment.java

License:Apache License

@Override
public void onStart() {
    super.onStart();

    final long statusId = getStatusId();
    statusRequestWorker.open();//from  w  w w  .ja  v a 2 s. c  om
    final TypedCache<Status> statusCache = statusRequestWorker.getCache();
    final Status status = statusCache.find(statusId);
    if (status == null) {
        Toast.makeText(getContext(), "status is not found", Toast.LENGTH_SHORT).show();
        return;
    }

    final StatusDetailView statusView = binding.statusView;
    StatusViewImageHelper.load(status, statusView);
    final User user = StatusViewImageHelper.getBindingUser(status);

    final ImageView icon = statusView.getIcon();
    final OnUserIconClickedListener userIconClickedListener = createUserIconClickedListener();
    icon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            userIconClickedListener.onUserIconClicked(view, user);
        }
    });
    statusView.getUserName().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            userIconClickedListener.onUserIconClicked(icon, user);
        }
    });
    statusView.getMediaContainer().setOnMediaClickListener(new OnMediaClickListener() {
        @Override
        public void onMediaClicked(View view, int index) {
            MediaViewActivity.start(view.getContext(), status, index);
        }
    });

    setTintList(binding.sdFav.getDrawable(), R.color.selector_fav_icon);
    binding.sdFav.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (status.isFavorited()) {
                statusRequestWorker.destroyFavorite(statusId);
            } else {
                statusRequestWorker.createFavorite(statusId);
            }
        }
    });
    setTintList(binding.sdRetweet.getDrawable(), R.color.selector_rt_icon);
    binding.sdRetweet.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (status.isRetweeted()) {
                statusRequestWorker.destroyRetweet(statusId);
            } else {
                statusRequestWorker.retweetStatus(statusId);
            }
        }
    });
    DrawableCompat.setTint(binding.sdReply.getDrawable(),
            ContextCompat.getColor(getContext(), R.color.twitter_action_normal));
    binding.sdReply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setupInput(TweetInputFragment.TYPE_REPLY);
        }
    });
    setTintList(binding.sdQuote.getDrawable(), R.color.twitter_action_normal);
    binding.sdQuote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setupInput(TweetInputFragment.TYPE_QUOTE);
        }
    });

    subscription = statusCache.observeById(statusId).subscribe(new Action1<Status>() {
        @Override
        public void call(Status status) {
            binding.statusView.bindStatus(status);
            binding.sdFav.setActivated(status.isFavorited());
            binding.sdRetweet.setActivated(status.isRetweeted());
        }
    });

    final Status bindingStatus = StatusViewImageHelper.getBindingStatus(status);
    if (bindingStatus.getURLEntities().length < 1) {
        return;
    }
    if (twitterCard != null) {
        setupTwitterCard(twitterCard);
    } else {
        TwitterCardFetcher.observeFetch(bindingStatus.getURLEntities()[0].getExpandedURL())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<TwitterCard>() {
                    @Override
                    public void call(final TwitterCard twitterCard) {
                        setupTwitterCard(twitterCard);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.e(TAG, "card fetch: ", throwable);
                    }
                });
    }
}

From source file:com.freshdigitable.udonroad.StatusViewBase.java

License:Apache License

protected void bindRT(Status bindingStatus) {
    final int rtCount = bindingStatus.getRetweetCount();
    if (rtCount > 0) {
        this.setRtCountVisibility(VISIBLE);
        setTint(rtIcon,/*from   www .  j a v a2 s  .co m*/
                bindingStatus.isRetweeted() ? R.color.twitter_action_retweeted : R.color.twitter_action_normal);
        this.rtCount.setText(String.valueOf(rtCount));
    }
}

From source file:com.freshdigitable.udonroad.util.TwitterResponseMock.java

License:Apache License

public static Status createRtStatus(Status rtedStatus, long newStatusId, int rtCount, int favCount,
        boolean isFromRest) {
    final Status rtStatus = createStatus(rtedStatus.getId(), rtedStatus.getUser());
    if (isFromRest) {
        when(rtStatus.isRetweeted()).thenReturn(true);
        when(rtStatus.getRetweetCount()).thenReturn(rtCount);
        when(rtStatus.getFavoriteCount()).thenReturn(favCount);
    } else {//from www . j  a v a  2  s .c o  m
        when(rtStatus.isRetweeted()).thenReturn(false);
        when(rtStatus.getRetweetCount()).thenReturn(0);
        when(rtStatus.getFavoriteCount()).thenReturn(0);
    }

    final Status status = createStatus(newStatusId);
    final String rtText = rtStatus.getText();
    when(status.getText()).thenReturn(rtText);
    when(status.isRetweet()).thenReturn(true);
    when(status.isRetweeted()).thenReturn(isFromRest);
    when(status.getRetweetedStatus()).thenReturn(rtStatus);
    return status;
}

From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java

License:Apache License

public static void convert(Status status, Struct struct) {
    struct.put("CreatedAt", status.getCreatedAt()).put("Id", status.getId()).put("Text", status.getText())
            .put("Source", status.getSource()).put("Truncated", status.isTruncated())
            .put("InReplyToStatusId", status.getInReplyToStatusId())
            .put("InReplyToUserId", status.getInReplyToUserId())
            .put("InReplyToScreenName", status.getInReplyToScreenName()).put("Favorited", status.isFavorited())
            .put("Retweeted", status.isRetweeted()).put("FavoriteCount", status.getFavoriteCount())
            .put("Retweet", status.isRetweet()).put("RetweetCount", status.getRetweetCount())
            .put("RetweetedByMe", status.isRetweetedByMe())
            .put("CurrentUserRetweetId", status.getCurrentUserRetweetId())
            .put("PossiblySensitive", status.isPossiblySensitive()).put("Lang", status.getLang());

    Struct userStruct;/*from  w  w w .j a  v  a 2s. co  m*/
    if (null != status.getUser()) {
        userStruct = new Struct(USER_SCHEMA);
        convert(status.getUser(), userStruct);
    } else {
        userStruct = null;
    }
    struct.put("User", userStruct);

    Struct placeStruct;
    if (null != status.getPlace()) {
        placeStruct = new Struct(PLACE_SCHEMA);
        convert(status.getPlace(), placeStruct);
    } else {
        placeStruct = null;
    }
    struct.put("Place", placeStruct);

    Struct geoLocationStruct;
    if (null != status.getGeoLocation()) {
        geoLocationStruct = new Struct(GEO_LOCATION_SCHEMA);
        convert(status.getGeoLocation(), geoLocationStruct);
    } else {
        geoLocationStruct = null;
    }
    struct.put("GeoLocation", geoLocationStruct);
    List<Long> contributers = new ArrayList<>();

    if (null != status.getContributors()) {
        for (Long l : status.getContributors()) {
            contributers.add(l);
        }
    }
    struct.put("Contributors", contributers);

    List<String> withheldInCountries = new ArrayList<>();
    if (null != status.getWithheldInCountries()) {
        for (String s : status.getWithheldInCountries()) {
            withheldInCountries.add(s);
        }
    }
    struct.put("WithheldInCountries", withheldInCountries);

    struct.put("HashtagEntities", convert(status.getHashtagEntities()));
    struct.put("UserMentionEntities", convert(status.getUserMentionEntities()));
    struct.put("MediaEntities", convert(status.getMediaEntities()));
    struct.put("SymbolEntities", convert(status.getSymbolEntities()));
    struct.put("URLEntities", convert(status.getURLEntities()));
}

From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java

License:Apache License

public static Map getFieldsMapFromStatus(String queryOwner, String queryName, String queryString,
        Status status) {

    if (queryName != null)
        queryName = queryName.toLowerCase();
    if (queryOwner != null)
        queryOwner = queryOwner.toLowerCase();
    Map m = StatusArraysHelper.getUserMentionMap(status);
    Map newMap = new HashMap();
    for (Object key : m.keySet()) {
        newMap.put(key.toString(), (Long) m.get(key));
    }//from w w  w .  j  a  va 2  s. co m
    Double longitude = null;
    Double lattitude = null;
    if (status.getGeoLocation() != null) {
        longitude = status.getGeoLocation().getLongitude();
        lattitude = status.getGeoLocation().getLatitude();
    }
    String place = null;
    if (status.getPlace() != null) {
        place = status.getPlace().getFullName();
    }

    boolean isRetweet = status.getRetweetedStatus() != null;
    Long retweetedId = null;
    String retweetedText = null;
    if (isRetweet) {
        retweetedId = status.getRetweetedStatus().getId();
        retweetedText = status.getRetweetedStatus().getText();
    }

    Map<String, Object> result = new HashMap<>();
    result.put(QueryResultItemFieldNames.STATUS_ID, status.getId());
    result.put(QueryResultItemFieldNames.CREATED_AT, status.getCreatedAt());
    result.put(QueryResultItemFieldNames.CURRENT_USER_RETWEET_ID, status.getCurrentUserRetweetId());
    result.put(QueryResultItemFieldNames.FAVOURITE_COUNT, status.getFavoriteCount());
    result.put(QueryResultItemFieldNames.FAVOURITED, status.isFavorited());
    result.put(QueryResultItemFieldNames.HASHTAGS, StatusArraysHelper.getHashTagsList(status));
    result.put(QueryResultItemFieldNames.IN_REPLY_TO_SCREEN_NAME, (status.getInReplyToScreenName()));
    result.put(QueryResultItemFieldNames.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    result.put(QueryResultItemFieldNames.IN_REPLY_TO_USER_ID, status.getInReplyToUserId());
    result.put(QueryResultItemFieldNames.LATITUDE, lattitude);
    result.put(QueryResultItemFieldNames.LONGITUDE, longitude);
    result.put(QueryResultItemFieldNames.MENTIONS, newMap);
    result.put(QueryResultItemFieldNames.LANGUAGE, status.getLang());
    result.put(QueryResultItemFieldNames.PLACE, place);
    result.put(QueryResultItemFieldNames.POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    result.put(QueryResultItemFieldNames.QUERY_NAME, queryName);
    result.put(QueryResultItemFieldNames.QUERY_OWNER, queryOwner);
    result.put(QueryResultItemFieldNames.QUERY, queryString);
    result.put(QueryResultItemFieldNames.RELEVANT_QUERY_TERMS,
            TwitterUtils.relevantQueryTermsFromStatus(queryString, status));
    result.put(QueryResultItemFieldNames.RETWEET, isRetweet);
    result.put(QueryResultItemFieldNames.RETWEET_COUNT, status.getRetweetCount());
    result.put(QueryResultItemFieldNames.RETWEETED, status.isRetweeted());
    result.put(QueryResultItemFieldNames.RETWEETED_BY_ME, status.isRetweetedByMe());
    result.put(QueryResultItemFieldNames.RETWEET_STATUS_ID, retweetedId);
    result.put(QueryResultItemFieldNames.RETWEETED_TEXT, retweetedText);
    result.put(QueryResultItemFieldNames.SCOPES, StatusArraysHelper.getScopesList(status));
    result.put(QueryResultItemFieldNames.SCREEN_NAME, status.getUser().getScreenName());
    result.put(QueryResultItemFieldNames.SOURCE, (status.getSource()));
    result.put(QueryResultItemFieldNames.TEXT, (status.getText()));
    result.put(QueryResultItemFieldNames.TRUNCATED, status.isTruncated());
    result.put(QueryResultItemFieldNames.URLS, StatusArraysHelper.getUrlsList(status));
    result.put(QueryResultItemFieldNames.USER_ID, status.getUser().getId());
    result.put(QueryResultItemFieldNames.USER_NAME, (status.getUser().getName()));
    result.put(QueryResultItemFieldNames.USER_DESCRIPTION, (status.getUser().getDescription()));
    result.put(QueryResultItemFieldNames.USER_LOCATION, (status.getUser().getLocation()));
    result.put(QueryResultItemFieldNames.USER_URL, (status.getUser().getURL()));
    result.put(QueryResultItemFieldNames.USER_IS_PROTECTED, status.getUser().isProtected());
    result.put(QueryResultItemFieldNames.USER_FOLLOWERS_COUNT, status.getUser().getFollowersCount());
    result.put(QueryResultItemFieldNames.USER_CREATED_AT, status.getUser().getCreatedAt());
    result.put(QueryResultItemFieldNames.USER_FRIENDS_COUNT, status.getUser().getFriendsCount());
    result.put(QueryResultItemFieldNames.USER_LISTED_COUNT, status.getUser().getListedCount());
    result.put(QueryResultItemFieldNames.USER_STATUSES_COUNT, status.getUser().getStatusesCount());
    result.put(QueryResultItemFieldNames.USER_FAVOURITES_COUNT, status.getUser().getFavouritesCount());
    return result;
}

From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java

License:Apache License

public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString,
        Status status) {
    TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro();

    if (queryName != null)
        queryName = queryName.toLowerCase();
    if (queryOwner != null)
        queryOwner = queryOwner.toLowerCase();

    result.setQueryName(queryName);//from  ww w .  j  a v  a2s  .co  m
    result.setQueryOwner(queryOwner);
    result.setQuery(queryString);
    result.setStatusId(status.getId());
    result.setText(status.getText());

    result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status));
    result.setLang(status.getLang());

    result.setCreatedAt(status.getCreatedAt().getTime());

    User user = status.getUser();
    result.setUserId(user.getId());
    result.setScreenName(user.getScreenName());
    result.setUserLocation(user.getLocation());
    result.setUserName(user.getName());
    result.setUserDescription(user.getDescription());
    result.setUserIsProtected(user.isProtected());
    result.setUserFollowersCount(user.getFollowersCount());
    result.setUserCreatedAt(user.getCreatedAt().getTime());
    result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt()));
    result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt()));
    result.setUserFriendsCount(user.getFriendsCount());
    result.setUserListedCount(user.getListedCount());
    result.setUserStatusesCount(user.getStatusesCount());
    result.setUserFavoritesCount(user.getFavouritesCount());

    result.setCurrentUserRetweetId(status.getCurrentUserRetweetId());

    result.setInReplyToScreenName(status.getInReplyToScreenName());
    result.setInReplyToStatusId(status.getInReplyToStatusId());
    result.setInReplyToUserId(status.getInReplyToUserId());

    if (status.getGeoLocation() != null) {
        result.setLatitude(status.getGeoLocation().getLatitude());
        result.setLongitude(status.getGeoLocation().getLongitude());
    }

    result.setSource(status.getSource());
    result.setTrucated(status.isTruncated());
    result.setPossiblySensitive(status.isPossiblySensitive());

    result.setRetweet(status.getRetweetedStatus() != null);
    if (result.getRetweet()) {
        result.setRetweetStatusId(status.getRetweetedStatus().getId());
        result.setRetweetedText(status.getRetweetedStatus().getText());
    }
    result.setRetweeted(status.isRetweeted());
    result.setRetweetCount(status.getRetweetCount());
    result.setRetweetedByMe(status.isRetweetedByMe());

    result.setFavoriteCount(status.getFavoriteCount());
    result.setFavourited(status.isFavorited());

    if (status.getPlace() != null) {
        result.setPlace(status.getPlace().getFullName());
    }

    Scopes scopesObj = status.getScopes();
    if (scopesObj != null) {
        List scopes = Arrays.asList(scopesObj.getPlaceIds());
        result.setScopes(scopes);
    }
    return result;
}

From source file:info.maslowis.twitterripper.util.Util.java

License:Open Source License

/**
 * Returns a representation the status (tweet) as string
 *
 * @return a representation the status as string in format <em>Status{id=, text='', lang='', createdAt=, geoLocation=, isFavorited=, isRetweeted=, retweetCount=, isTruncated=}</em>
 *///from  www  .j a va2 s.c o  m
public static String toString(final Status status) {
    return "Status{id=" + status.getId() + ", text='" + status.getText() + "', lang='" + status.getLang()
            + "', createdAt=" + status.getCreatedAt() + ", geoLocation=" + status.getGeoLocation()
            + ", isFavorited=" + status.isFavorited() + ", isRetweeted=" + status.isRetweeted()
            + ", retweetCount=" + status.getRetweetCount() + ", isTruncated=" + status.isTruncated() + "}";
}