Example usage for twitter4j Status isRetweet

List of usage examples for twitter4j Status isRetweet

Introduction

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

Prototype

boolean isRetweet();

Source Link

Usage

From source file:com.daiv.android.twitter.data.sq_lite.ListDataSource.java

License:Apache License

public synchronized void createTweet(Status status, long listId) {
    ContentValues values = new ContentValues();
    String originalName = "";
    long time = status.getCreatedAt().getTime();
    long id = status.getId();

    if (status.isRetweet()) {
        originalName = status.getUser().getScreenName();
        status = status.getRetweetedStatus();
    }/*  www.j  av  a2 s . com*/

    String[] html = TweetLinkUtils.getLinksInStatus(status);
    String text = html[0];
    String media = html[1];
    String url = html[2];
    String hashtags = html[3];
    String users = html[4];

    if (media.contains("/tweet_video/")) {
        media = media.replace("tweet_video", "tweet_video_thumb").replace(".mp4", ".png");
    }

    values.put(ListSQLiteHelper.COLUMN_TEXT, text);
    values.put(ListSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(ListSQLiteHelper.COLUMN_NAME, status.getUser().getName());
    values.put(ListSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL());
    values.put(ListSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName());
    values.put(ListSQLiteHelper.COLUMN_TIME, time);
    values.put(ListSQLiteHelper.COLUMN_RETWEETER, originalName);
    values.put(ListSQLiteHelper.COLUMN_PIC_URL, media);
    values.put(ListSQLiteHelper.COLUMN_URL, url);
    values.put(ListSQLiteHelper.COLUMN_USERS, users);
    values.put(ListSQLiteHelper.COLUMN_HASHTAGS, hashtags);
    values.put(ListSQLiteHelper.COLUMN_LIST_ID, listId);
    values.put(ListSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url));

    try {
        database.insert(ListSQLiteHelper.TABLE_HOME, null, values);
    } catch (Exception e) {
        open();
        database.insert(ListSQLiteHelper.TABLE_HOME, null, values);
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.ListDataSource.java

License:Apache License

public int insertTweets(List<Status> statuses, long listId) {

    ContentValues[] valueses = new ContentValues[statuses.size()];

    for (int i = 0; i < statuses.size(); i++) {
        Status status = statuses.get(i);

        ContentValues values = new ContentValues();
        String originalName = "";
        long time = status.getCreatedAt().getTime();
        long id = status.getId();

        if (status.isRetweet()) {
            originalName = status.getUser().getScreenName();
            status = status.getRetweetedStatus();
        }//from w  ww  .j  av  a  2  s  . c  o m

        String[] html = TweetLinkUtils.getLinksInStatus(status);
        String text = html[0];
        String media = html[1];
        String url = html[2];
        String hashtags = html[3];
        String users = html[4];

        if (media.contains("/tweet_video/")) {
            media = media.replace("tweet_video", "tweet_video_thumb").replace(".mp4", ".png");
        }

        values.put(ListSQLiteHelper.COLUMN_TEXT, text);
        values.put(ListSQLiteHelper.COLUMN_TWEET_ID, id);
        values.put(ListSQLiteHelper.COLUMN_NAME, status.getUser().getName());
        values.put(ListSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL());
        values.put(ListSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName());
        values.put(ListSQLiteHelper.COLUMN_TIME, time);
        values.put(ListSQLiteHelper.COLUMN_RETWEETER, originalName);
        values.put(ListSQLiteHelper.COLUMN_PIC_URL, media);
        values.put(ListSQLiteHelper.COLUMN_URL, url);
        values.put(ListSQLiteHelper.COLUMN_USERS, users);
        values.put(ListSQLiteHelper.COLUMN_HASHTAGS, hashtags);
        values.put(ListSQLiteHelper.COLUMN_LIST_ID, listId);
        values.put(ListSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url));

        valueses[i] = values;
    }

    return insertMultiple(valueses);
}

From source file:com.daiv.android.twitter.ui.tweet_viewer.fragments.TweetFragment.java

License:Apache License

public void getFavoriteCount(final TextView favs, final View favButton, final long tweetId) {
    new Thread(new Runnable() {
        @Override/*from w  ww  . ja  v a2  s  .c o m*/
        public void run() {
            try {
                Twitter twitter = getTwitter();
                twitter4j.Status status = twitter.showStatus(tweetId);
                if (status.isRetweet()) {
                    twitter4j.Status retweeted = status.getRetweetedStatus();
                    status = retweeted;
                }

                final twitter4j.Status fStatus = status;
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        favs.setText(" " + fStatus.getFavoriteCount());

                        if (fStatus.isFavorited()) {
                            TypedArray a = context.getTheme()
                                    .obtainStyledAttributes(new int[] { R.attr.favoritedButton });
                            int resource = a.getResourceId(0, 0);
                            a.recycle();

                            if (favButton instanceof ImageButton) {
                                if (!settings.addonTheme) {
                                    ((ImageButton) favButton)
                                            .setColorFilter(context.getResources().getColor(R.color.app_color));
                                } else {
                                    ((ImageButton) favButton).setColorFilter(settings.accentInt);
                                }

                                ((ImageButton) favButton)
                                        .setImageDrawable(context.getResources().getDrawable(resource));
                            } else if (favButton instanceof LinearLayout) {
                                if (!settings.addonTheme) {
                                    favButton.setBackgroundColor(
                                            context.getResources().getColor(R.color.app_color));
                                } else {
                                    favButton.setBackgroundColor(settings.accentInt);
                                }
                            }
                            isFavorited = true;
                        } else {
                            TypedArray a = context.getTheme()
                                    .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton });
                            int resource = a.getResourceId(0, 0);
                            a.recycle();

                            if (favButton instanceof ImageButton) {
                                ((ImageButton) favButton)
                                        .setImageDrawable(context.getResources().getDrawable(resource));
                                isFavorited = false;

                                ((ImageButton) favButton).clearColorFilter();
                            } else {
                                favButton.setBackgroundColor(
                                        getResources().getColor(android.R.color.transparent));
                            }
                        }
                    }
                });
            } catch (Exception e) {

            }
        }
    }).start();
}

From source file:com.dhamacher.tweetsentimentanalysis.Main.java

License:Open Source License

private static void persistTweet(QueryResult result, String token) {
    EntityTransaction tx = em.getTransaction();
    tx.begin();/*from w  w  w.  ja  v a  2 s  .co m*/
    for (Status status : result.getTweets()) {
        Tweet entity = new Tweet();
        entity.setTweetId(status.getId());
        entity.setSearchToken(token);
        entity.setCreatedOn(status.getCreatedAt());
        entity.setIsRetweet(status.isRetweet());
        entity.setSource(status.getSource());
        entity.setUser(status.getUser());
        entity.setText(status.getText());
        em.persist(entity);
    }
    tx.commit();
}

From source file:com.dwdesign.tweetings.model.ParcelableStatus.java

License:Open Source License

public ParcelableStatus(Status status, final long account_id, final boolean is_gap,
        final boolean large_inline_image_preview) {

    this.is_gap = is_gap;
    this.account_id = account_id;
    status_id = status.getId();//from  ww  w.  jav  a 2  s.  c  om
    is_retweet = status.isRetweet();
    final Status retweeted_status = is_retweet ? status.getRetweetedStatus() : null;
    final User retweet_user = retweeted_status != null ? status.getUser() : null;
    retweet_id = retweeted_status != null ? retweeted_status.getId() : -1;
    retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1;
    retweeted_by_name = retweet_user != null ? retweet_user.getName() : null;
    retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null;
    if (retweeted_status != null) {
        status = retweeted_status;
    }
    final User user = status.getUser();
    user_id = user != null ? user.getId() : -1;
    name = user != null ? user.getName() : null;
    screen_name = user != null ? user.getScreenName() : null;
    profile_image_url = user != null ? user.getProfileImageURL() : null;
    profile_image_url_string = profile_image_url != null ? profile_image_url.toString() : null;
    is_protected = user != null ? user.isProtected() : false;
    is_verified = user != null ? user.isVerified() : false;
    final MediaEntity[] medias = status.getMediaEntities();

    status_timestamp = getTime(status.getCreatedAt());
    text_html = formatStatusText(status);
    final PreviewImage preview = getPreviewImage(text_html,
            large_inline_image_preview ? INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE_HIGH
                    : INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_SMALL);
    text_plain = status.getText();
    retweet_count = status.getRetweetCount();
    in_reply_to_screen_name = status.getInReplyToScreenName();
    in_reply_to_status_id = status.getInReplyToStatusId();
    source = status.getSource();
    location = new ParcelableLocation(status.getGeoLocation());
    location_string = location.toString();
    is_favorite = status.isFavorited();
    has_media = medias != null && medias.length > 0 || preview.has_image;
    text = text_html != null ? Html.fromHtml(text_html) : null;
    image_preview_url_string = preview.matched_url;
    image_orig_url_string = preview.orig_url;
    image_preview_url = parseURL(image_preview_url_string);
    text_unescaped = unescape(text_html);
    String play = null;
    URLEntity[] urls = status.getURLEntities();
    if (urls != null) {
        for (final URLEntity url : urls) {
            final URL tco_url = url.getURL();
            final URL expanded_url = url.getExpandedURL();
            if (tco_url != null && expanded_url != null
                    && expanded_url.toString().contains("play.google.com/store/apps")) {
                play = expanded_url.toString();
                break;
            }

        }
    }
    play_package = play;
    is_possibly_sensitive = status.isPossiblySensitive();
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues makeStatusContentValues(Status status, final long account_id) {
    if (status == null || status.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, account_id);
    values.put(Statuses.STATUS_ID, status.getId());
    final boolean is_retweet = status.isRetweet();
    final Status retweeted_status = is_retweet ? status.getRetweetedStatus() : null;
    if (retweeted_status != null) {
        final User retweet_user = status.getUser();
        values.put(Statuses.RETWEET_ID, retweeted_status.getId());
        values.put(Statuses.RETWEETED_BY_ID, retweet_user.getId());
        values.put(Statuses.RETWEETED_BY_NAME, retweet_user.getName());
        values.put(Statuses.RETWEETED_BY_SCREEN_NAME, retweet_user.getScreenName());
        status = retweeted_status;//from   ww  w  .  ja v a 2  s . c  o m
    }
    final User user = status.getUser();
    if (user != null) {
        final long user_id = user.getId();
        final String profile_image_url = user.getProfileImageURL().toString();
        final String name = user.getName(), screen_name = user.getScreenName();
        values.put(Statuses.USER_ID, user_id);
        values.put(Statuses.NAME, name);
        values.put(Statuses.SCREEN_NAME, screen_name);
        values.put(Statuses.IS_PROTECTED, user.isProtected() ? 1 : 0);
        values.put(Statuses.IS_VERIFIED, user.isVerified() ? 1 : 0);
        values.put(Statuses.PROFILE_IMAGE_URL, profile_image_url);
    }
    if (status.getCreatedAt() != null) {
        values.put(Statuses.STATUS_TIMESTAMP, status.getCreatedAt().getTime());
    }
    values.put(Statuses.TEXT, formatStatusText(status));
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.IN_REPLY_TO_SCREEN_NAME, status.getInReplyToScreenName());
    values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    values.put(Statuses.SOURCE, status.getSource());
    values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    final GeoLocation location = status.getGeoLocation();
    if (location != null) {
        values.put(Statuses.LOCATION, location.getLatitude() + "," + location.getLongitude());
    }
    values.put(Statuses.IS_RETWEET, is_retweet ? 1 : 0);
    values.put(Statuses.IS_FAVORITE, status.isFavorited() ? 1 : 0);
    return values;
}

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

License:Apache License

@Override
public void bindStatus(final Status status) {
    super.bindStatus(status);
    if (status.isRetweet()) {
        bindRtUser(status.getUser());//from   w  ww  . ja v a2s  .  c  om
    }

    final Status quotedBindingStatus = getBindingStatus(status).getQuotedStatus();
    if (quotedBindingStatus != null) {
        quotedStatus.bindStatus(quotedBindingStatus);
        quotedStatus.setVisibility(VISIBLE);
    }
}

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

License:Apache License

StatusRealm(Status status) {
    this.id = status.getId();
    this.createdAt = status.getCreatedAt();
    this.retweetedStatus = status.getRetweetedStatus();
    this.retweet = status.isRetweet();
    if (status.isRetweet()) {
        this.retweetedStatusId = this.retweetedStatus.getId();
    }/* www.ja v  a2s  . co  m*/
    this.text = status.getText();
    this.source = status.getSource();
    this.retweetCount = status.getRetweetCount();
    this.favoriteCount = status.getFavoriteCount();
    this.reaction = new StatusReactionImpl(status);
    this.user = status.getUser();
    this.userId = user.getId();
    this.urlEntities = URLEntityRealm.createList(status.getURLEntities());

    this.mediaEntities = new RealmList<>();
    final ExtendedMediaEntity[] me = status.getExtendedMediaEntities();
    for (ExtendedMediaEntity m : me) {
        mediaEntities.add(new ExtendedMediaEntityRealm(m));
    }
    final UserMentionEntity[] userMentionEntities = status.getUserMentionEntities();
    this.userMentionEntities = new RealmList<>();
    for (UserMentionEntity u : userMentionEntities) {
        this.userMentionEntities.add(new UserMentionEntityRealm(u));
    }

    this.quotedStatus = status.getQuotedStatus();
    this.quotedStatusId = status.getQuotedStatusId();
}

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

License:Apache License

private boolean isIgnorable(Status status) {
    return configStore.isIgnoredUser(status.getUser().getId())
            || (status.isRetweet() && configStore.isIgnoredUser(status.getRetweetedStatus().getUser().getId()));
}

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

License:Apache License

private List<StatusIDs> createUpdateList(List<Status> statuses) {
    if (!updateEvent.hasObservers()) {
        return Collections.emptyList();
    }//from  ww w . ja  va 2 s.  com

    final List<StatusIDs> updates = new ArrayList<>();
    for (Status s : statuses) {
        final StatusIDs update = findTimeline(s);
        if (update != null) {
            updates.add(update);
        }

        final RealmResults<StatusIDs> u = findReferringStatus(s.getId());
        if (!u.isEmpty()) {
            updates.addAll(u);
        }

        final long quotedStatusId = s.getQuotedStatusId();
        if (quotedStatusId > 0) {
            final Status quotedStatus = s.getQuotedStatus();

            final StatusIDs q = findTimeline(quotedStatus);
            if (q != null) {
                updates.add(q);
            }

            final RealmResults<StatusIDs> updatedQuotedStatus = findReferringStatus(quotedStatusId);
            if (!updatedQuotedStatus.isEmpty()) {
                updates.addAll(updatedQuotedStatus);
            }
        }

        if (!s.isRetweet()) {
            continue;
        }
        final Status retweetedStatus = s.getRetweetedStatus();

        final StatusIDs rs = findTimeline(retweetedStatus);
        if (rs != null) {
            updates.add(rs);
        }
        final RealmResults<StatusIDs> rtedUpdate = findReferringStatus(retweetedStatus.getId());
        if (!rtedUpdate.isEmpty()) {
            updates.addAll(rtedUpdate);
        }

        final long rtQuotedStatusId = retweetedStatus.getQuotedStatusId();
        if (rtQuotedStatusId > 0) {
            final RealmResults<StatusIDs> rtUpdatedQuotedStatus = findReferringStatus(rtQuotedStatusId);
            if (!rtUpdatedQuotedStatus.isEmpty()) {
                updates.addAll(rtUpdatedQuotedStatus);
            }
        }
    }
    return updates;
}