Example usage for twitter4j Status getCreatedAt

List of usage examples for twitter4j Status getCreatedAt

Introduction

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

Prototype

Date getCreatedAt();

Source Link

Document

Return the created_at

Usage

From source file:com.cloudera.flume.source.TwitterSource.java

License:Apache License

/**
 * Start processing events. This uses the Twitter Streaming API to sample
 * Twitter, and process tweets./*from   ww  w . j av a  2  s .  co  m*/
 */
@Override
public void start() {
    // The channel is the piece of Flume that sits between the Source and Sink,
    // and is used to process events.
    final ChannelProcessor channel = getChannelProcessor();

    final Map<String, String> headers = new HashMap<String, String>();

    // The StatusListener is a twitter4j API, which can be added to a Twitter
    // stream, and will execute methods every time a message comes in through
    // the stream.
    StatusListener listener = new StatusListener() {
        // The onStatus method is executed every time a new tweet comes in.
        public void onStatus(Status status) {
            // The EventBuilder is used to build an event using the headers and
            // the raw JSON of a tweet
            logger.debug(status.getUser().getScreenName() + ": " + status.getText());

            headers.put("timestamp", String.valueOf(status.getCreatedAt().getTime()));
            Event event = EventBuilder.withBody(DataObjectFactory.getRawJSON(status).getBytes(), headers);

            channel.processEvent(event);
        }

        // This listener will ignore everything except for new tweets
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onScrubGeo(long userId, long upToStatusId) {
        }

        public void onException(Exception ex) {
        }

        public void onStallWarning(StallWarning warning) {
        }
    };

    logger.debug("Setting up Twitter sample stream using consumer key {} and" + " access token {}",
            new String[] { consumerKey, accessToken });
    // Set up the stream's listener (defined above),
    twitterStream.addListener(listener);

    // Set up a filter to pull out industry-relevant tweets
    if (keywords.length == 0) {
        logger.debug("Starting up Twitter sampling...");
        twitterStream.sample();
    } else {
        logger.debug("Starting up Twitter filtering...");

        FilterQuery query = new FilterQuery().track(keywords);
        twitterStream.filter(query);
    }
    super.start();
}

From source file:com.controller.SearchController.java

License:Open Source License

public static String displayTweets(String query) {
    StringBuilder sb = new StringBuilder();
    sb.append(/*from  w  w  w . ja va  2  s . c o  m*/
            " <h3 class=\"text-center\"><i class=\"fa fa-twitter-square\"></i>&nbsp;Comments from Twitter</h3>");
    List<Status> tweet = TwitterSearch.configure(query);
    if (tweet.isEmpty()) {
        return "<span class=\"label label-info\">No Tweets results found.</span>";
    }

    if (tweet.size() > 5) {
        // Display a maximum of 5 tweets.
        tweet.subList(5, tweet.size()).clear();
    }

    for (Status status : tweet) {
        sb.append("<div class='thumbnail row'>");
        sb.append("<div class=\"text-center col-xs-2\">");
        sb.append("<img class=\"img-responsive\"' src=");
        sb.append(status.getUser().getBiggerProfileImageURL());
        sb.append(">");
        sb.append("</div>");
        sb.append("<div class=\"col-xs-10\">");
        sb.append(status.getCreatedAt());
        sb.append("<br />");
        sb.append("<strong>");
        sb.append(status.getUser().getScreenName());
        sb.append("&nbsp;</strong>said<br />");
        sb.append(status.getText());
        sb.append("</div>");
        sb.append("</div>");
    }

    return sb.toString();
}

From source file:com.daemon.database.Transactor.java

License:Open Source License

/**
 * Saves a given tweet in the DB if that tweet is not already saved. Only saves
 * the tweet no other information!//from www  .j  a  v a 2 s  .  c o m
 * 
 * @param tweet The tweet to be saved.
 * @throws SQLException
 */
private void saveTweet(Status tweet, RegressionSentimentClassifier sentimentClassifier) throws SQLException {
    // for reweet, save the original tweet first
    if (tweet.getRetweetedStatus() != null) {
        saveAllTransactionSafe(tweet.getRetweetedStatus(), null, sentimentClassifier);
    }
    // then, save the current tweet

    // 1: Set Tweet ID
    prepStatementTweet.setLong(1, tweet.getId());

    // 2 / 3: Set GeoLocation
    if (tweet.getGeoLocation() != null) {
        prepStatementTweet.setFloat(2, (float) tweet.getGeoLocation().getLatitude());
        prepStatementTweet.setFloat(3, (float) tweet.getGeoLocation().getLongitude());
    } else {
        prepStatementTweet.setNull(2, java.sql.Types.NULL);
        prepStatementTweet.setNull(3, java.sql.Types.NULL);
    }

    // 4: Set User ID
    prepStatementTweet.setLong(4, tweet.getUser().getId());

    // 5: Set Reply-Tweet ID
    if (tweet.getInReplyToStatusId() == -1) {
        prepStatementTweet.setNull(5, java.sql.Types.NULL);
    } else {
        prepStatementTweet.setLong(5, tweet.getInReplyToStatusId());
    }

    // 6: Set Retweet-ID
    if (tweet.getRetweetedStatus() != null) {
        prepStatementTweet.setLong(6, tweet.getRetweetedStatus().getId());
    } else {
        prepStatementTweet.setNull(6, java.sql.Types.NULL);
    }

    // 7: Set Creation Date of Tweet
    java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(tweet.getCreatedAt().getTime());
    prepStatementTweet.setTimestamp(7, sqlTimestamp);

    // 8-11: Other attributes:
    prepStatementTweet.setString(8, tweet.getSource());
    prepStatementTweet.setString(9, tweet.getText());
    prepStatementTweet.setString(10, tweet.getIsoLanguageCode());
    prepStatementTweet.setInt(11, tweet.getRetweetCount());

    // 12: Sentiment
    Float sentiment = sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode());
    if (sentiment == null) {
        prepStatementTweet.setNull(12, java.sql.Types.NULL);
    } else {
        prepStatementTweet.setFloat(12,
                sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode()));
    }

    // execute statement
    prepStatementTweet.addBatch();
}

From source file:com.daemon.database.Transactor.java

License:Open Source License

/**
 * Adds the relation between the given tweet and the search term-id (DB
 * specific) the tweet was found with to the SQL Batched executed by 
 * the saveAllTransactionSafe Function// w  ww.  j  a v  a 2s.c  o m
 * 
 * @param tweet  The tweet related to the search term-id.
 * @param term   The search term related to the tweet.
 * @throws SQLException
 */
private void saveTweetWithTerm(Status tweet, SearchTerm term, RegressionSentimentClassifier sentimentClassifier)
        throws SQLException {
    try {
        prepStatementTweetWithTerm.setLong(1, tweet.getId()); // tweet_id
        prepStatementTweetWithTerm.setInt(2, term.getId()); // search_term_id
        prepStatementTweetWithTerm.setString(3, tweet.getIsoLanguageCode()); // iso__language_code
        // sentiment
        Float sentiment = sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode());
        if (sentiment == null) {
            prepStatementTweetWithTerm.setNull(4, java.sql.Types.NULL);
        } else {
            prepStatementTweetWithTerm.setFloat(4,
                    sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode()));
        }

        // created_at
        java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(tweet.getCreatedAt().getTime());
        prepStatementTweetWithTerm.setTimestamp(5, sqlTimestamp);
        // is_retweet_of_id
        if (tweet.getRetweetedStatus() != null) {
            prepStatementTweetWithTerm.setLong(6, tweet.getRetweetedStatus().getId());
        } else {
            prepStatementTweetWithTerm.setNull(6, java.sql.Types.NULL);
        }
        // retweet_count
        prepStatementTweetWithTerm.setInt(7, tweet.getRetweetCount());

        prepStatementTweetWithTerm.addBatch();
    } catch (Exception e) {
        // Doesn't make sense. we wouldn't find the tweet for the
        // search term if the search term was not in the database
        throw new SQLException(
                "Cannot save tweet with search term. The term has no Id (it was not inserted, yet).");
    }
}

From source file:com.daiv.android.twitter.adapters.PicturesArrayAdapter.java

License:Apache License

public void bindView(final View view, Context mContext, final String url, final Status status) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    Log.v("Test_picture", "text: " + status.getText());

    Status thisStatus;/*from  w w  w  . j  a v a2s  .  co  m*/

    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;

    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();

        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";

        thisStatus = status;
    }
    final String fRetweeter = retweeter;

    final long fOriginalTime = originalTime;

    User user = thisStatus.getUser();

    final long id = thisStatus.getId();
    final String profilePic = user.getBiggerProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();

    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);
    final String tweetText = html[0];
    final String picUrl = html[1];
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];

    holder.url = url;

    holder.iv.loadImage(url, false, new NetworkedCacheableImageView.OnImageLoadedListener() {
        @Override
        public void onImageLoaded(CacheableBitmapDrawable result) {
            holder.iv.setBackgroundDrawable(null);
        }
    });

    holder.iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String link;

            boolean displayPic = !picUrl.equals("");
            if (displayPic) {
                link = picUrl;
            } else {
                link = otherUrl.split("  ")[0];
            }

            Log.v("tweet_page", "clicked");
        }
    });

}

From source file:com.daiv.android.twitter.adapters.TimelineArrayAdapter.java

License:Apache License

public void bindView(final View view, Status status, int position) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    if (holder.expandArea.getVisibility() == View.VISIBLE) {
        removeExpansionNoAnimation(holder);
    }/* www.j  av a 2  s  . co  m*/

    Status thisStatus;

    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;

    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();

        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";

        thisStatus = status;
    }

    final long fOriginalTime = originalTime;

    User user = thisStatus.getUser();

    holder.tweetId = thisStatus.getId();
    final long id = holder.tweetId;
    final String profilePic = user.getOriginalProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();

    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);

    final String tweetText = html[0];
    final String picUrl = html[1];
    holder.picUrl = picUrl;
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];

    final boolean inAConversation = thisStatus.getInReplyToStatusId() != -1;

    holder.gifUrl = TweetLinkUtils.getGIFUrl(status, otherUrl);

    if (holder.isAConversation != null) {
        if (inAConversation) {
            if (holder.isAConversation.getVisibility() != View.VISIBLE) {
                holder.isAConversation.setVisibility(View.VISIBLE);
            }
        } else {
            if (holder.isAConversation.getVisibility() != View.GONE) {
                holder.isAConversation.setVisibility(View.GONE);
            }
        }
    }

    if (!settings.reverseClickActions) {
        final String fRetweeter = retweeter;
        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                String link;

                boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                        && !(hasGif);
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");

                return true;
            }
        });

        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }
            }
        });

    } else {
        final String fRetweeter = retweeter;
        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }

                String link;

                boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                        && !(hasGif);
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");
            }
        });

        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }

                return true;
            }
        });
    }

    if (!screenname.equals(username)) {

    } else {
        // need to clear the click listener so it isn't left over from another profile
        holder.profilePic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

        holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                return true;
            }
        });
    }

    if (TestLayout == AppSettings.LAYOUT_FULL_SCREEN
            || (settings.nameAndHandleOnTweet && settings.addonTheme)) {
        if (holder.screenTV.getVisibility() == View.GONE) {
            holder.screenTV.setVisibility(View.VISIBLE);
        }
        holder.screenTV.setText("@" + screenname);
        holder.name.setText(name);
    } else {
        if (!settings.showBoth) {
            holder.name.setText(settings.displayScreenName ? "@" + screenname : name);
        } else {
            if (holder.screenTV.getVisibility() == View.GONE) {
                holder.screenTV.setVisibility(View.VISIBLE);
            }
            holder.name.setText(name);
            holder.screenTV.setText("@" + screenname);
        }
    }

    if (!settings.absoluteDate) {
        holder.time.setText(Utils.getTimeAgo(time, context));
    } else {
        Date date = new Date(time);
        holder.time
                .setText(timeFormatter.format(date).replace("24:", "00:") + ", " + dateFormatter.format(date));
    }

    holder.tweet.setText(tweetText);

    boolean picture = false;

    if (settings.inlinePics) {
        if (holder.picUrl.equals("")) {
            if (holder.image.getVisibility() != View.GONE) {
                holder.image.setVisibility(View.GONE);
            }

            if (holder.playButton.getVisibility() == View.VISIBLE) {
                holder.playButton.setVisibility(View.GONE);
            }
        } else {
            if (holder.picUrl.contains("youtube")
                    || (holder.gifUrl != null && !android.text.TextUtils.isEmpty(holder.gifUrl))) {

                if (holder.playButton.getVisibility() == View.GONE) {
                    holder.playButton.setVisibility(View.VISIBLE);
                }

                final String fRetweeter = retweeter;

                holder.image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String link;

                        boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                        boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                                && !(hasGif);
                        if (displayPic) {
                            link = holder.picUrl;
                        } else {
                            link = otherUrl.split("  ")[0];
                        }
                    }
                });

                holder.image.setImageDrawable(transparent);

                picture = true;

            } else {
                holder.image.setImageDrawable(transparent);

                picture = true;

                if (holder.playButton.getVisibility() == View.VISIBLE) {
                    holder.playButton.setVisibility(View.GONE);
                }
            }

            if (holder.image.getVisibility() == View.GONE) {
                holder.image.setVisibility(View.VISIBLE);
            }
        }
    }

    if (type == NORMAL) {
        if (retweeter.length() > 0) {
            holder.retweeter.setText(context.getResources().getString(R.string.retweeter) + retweeter);
            holder.retweeterName = retweeter;
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (holder.retweeter.getVisibility() == View.VISIBLE) {
            holder.retweeter.setVisibility(View.GONE);
        }
    } else if (type == RETWEET) {

        int count = status.getRetweetCount();

        if (count > 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweets_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (count == 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweet_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        }
    }

    if (picture) {
        CacheableBitmapDrawable wrapper = mCache.getFromMemoryCache(holder.picUrl);
        if (wrapper != null) {
            holder.image.setImageDrawable(wrapper);
            picture = false;
        }
    }

    final boolean hasPicture = picture;
    mHandler[currHandler].removeCallbacksAndMessages(null);
    mHandler[currHandler].postDelayed(new Runnable() {
        @Override
        public void run() {
            if (holder.tweetId == id) {
                if (hasPicture) {
                    loadImage(context, holder, holder.picUrl, mCache, id);
                }

                if (settings.useEmoji
                        && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
                    String text = holder.tweet.getText().toString();
                    if (EmojiUtils.emojiPattern.matcher(text).find()) {
                        final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweetText));
                        holder.tweet.setText(span);
                    }
                }

                holder.tweet.setSoundEffectsEnabled(false);
                holder.tweet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            // we need to manually set the background for click feedback because the spannable
                            // absorbs the click on the background
                            if (!holder.preventNextClick) {
                                holder.background.getBackground()
                                        .setState(new int[] { android.R.attr.state_pressed });
                                new Handler().postDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        holder.background.getBackground()
                                                .setState(new int[] { android.R.attr.state_empty });
                                    }
                                }, 25);
                            }

                            holder.background.performClick();
                        }
                    }
                });

                holder.tweet.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            holder.background.performLongClick();
                            holder.preventNextClick = true;
                        }
                        return false;
                    }
                });

                if (holder.retweeter.getVisibility() == View.VISIBLE) {
                    holder.retweeter.setSoundEffectsEnabled(false);
                    holder.retweeter.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                if (!holder.preventNextClick) {
                                    holder.background.getBackground()
                                            .setState(new int[] { android.R.attr.state_pressed });
                                    new Handler().postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            holder.background.getBackground()
                                                    .setState(new int[] { android.R.attr.state_empty });
                                        }
                                    }, 25);
                                }

                                holder.background.performClick();
                            }
                        }
                    });

                    holder.retweeter.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                holder.background.performLongClick();
                                holder.preventNextClick = true;
                            }
                            return false;
                        }
                    });
                }

                TextUtils.linkifyText(context, holder.tweet, holder.background, true, otherUrl, false);
                TextUtils.linkifyText(context, holder.retweeter, holder.background, true, "", false);
            }
        }
    }, 400);
    currHandler++;

    if (currHandler == 10) {
        currHandler = 0;
    }

    if (openFirst && position == 0) {
        holder.background.performClick();
    }
}

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

License:Apache License

public static void insertTweet(Status status, int currentAccount, Context context) {
    ContentValues values = new ContentValues();
    String originalName = "";
    long id = status.getId();
    long time = status.getCreatedAt().getTime();

    if (status.isRetweet()) {
        originalName = status.getUser().getScreenName();
        status = status.getRetweetedStatus();
    }/*from   w  ww. jav a  2s.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];

    String source;
    if (status.isRetweet()) {
        source = android.text.Html.fromHtml(status.getRetweetedStatus().getSource()).toString();
    } else {
        source = android.text.Html.fromHtml(status.getSource()).toString();
    }

    values.put(HomeSQLiteHelper.COLUMN_ACCOUNT, currentAccount);
    values.put(HomeSQLiteHelper.COLUMN_TEXT, text);
    values.put(HomeSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(HomeSQLiteHelper.COLUMN_NAME, status.getUser().getName());
    values.put(HomeSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL());
    values.put(HomeSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName());
    values.put(HomeSQLiteHelper.COLUMN_TIME, time);
    values.put(HomeSQLiteHelper.COLUMN_RETWEETER, originalName);
    values.put(HomeSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(HomeSQLiteHelper.COLUMN_PIC_URL, media);
    values.put(HomeSQLiteHelper.COLUMN_URL, url);
    values.put(HomeSQLiteHelper.COLUMN_USERS, users);
    values.put(HomeSQLiteHelper.COLUMN_HASHTAGS, hashtags);
    values.put(HomeSQLiteHelper.COLUMN_CLIENT_SOURCE, source);

    context.getContentResolver().insert(HomeContentProvider.CONTENT_URI, values);
}

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

License:Apache License

public static int insertTweets(List<Status> statuses, int currentAccount, Context context) {
    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 mId = status.getId();
        long time = status.getCreatedAt().getTime();

        if (status.isRetweet()) {
            originalName = status.getUser().getScreenName();
            status = status.getRetweetedStatus();
        }//from ww w.ja  v  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];

        String source;
        if (status.isRetweet()) {
            source = android.text.Html.fromHtml(status.getRetweetedStatus().getSource()).toString();
        } else {
            source = android.text.Html.fromHtml(status.getSource()).toString();
        }

        values.put(HomeSQLiteHelper.COLUMN_ACCOUNT, currentAccount);
        values.put(HomeSQLiteHelper.COLUMN_TEXT, text);
        values.put(HomeSQLiteHelper.COLUMN_TWEET_ID, mId);
        values.put(HomeSQLiteHelper.COLUMN_NAME, status.getUser().getName());
        values.put(HomeSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL());
        values.put(HomeSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName());
        values.put(HomeSQLiteHelper.COLUMN_TIME, time);
        values.put(HomeSQLiteHelper.COLUMN_RETWEETER, originalName);
        values.put(HomeSQLiteHelper.COLUMN_UNREAD, 1);
        values.put(HomeSQLiteHelper.COLUMN_PIC_URL, media);
        values.put(HomeSQLiteHelper.COLUMN_URL, url);
        values.put(HomeSQLiteHelper.COLUMN_USERS, users);
        values.put(HomeSQLiteHelper.COLUMN_HASHTAGS, hashtags);
        values.put(HomeSQLiteHelper.COLUMN_CLIENT_SOURCE, source);

        valueses[i] = values;
    }

    return context.getContentResolver().bulkInsert(HomeContentProvider.CONTENT_URI, valueses);
}

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

License:Apache License

public synchronized void createTweet(Status status, int account) {
    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();
    }/*ww  w  . 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];

    String source;
    if (status.isRetweet()) {
        source = android.text.Html.fromHtml(status.getRetweetedStatus().getSource()).toString();
    } else {
        source = android.text.Html.fromHtml(status.getSource()).toString();
    }

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

    values.put(HomeSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(HomeSQLiteHelper.COLUMN_TEXT, text);
    values.put(HomeSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(HomeSQLiteHelper.COLUMN_NAME, status.getUser().getName());
    values.put(HomeSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL());
    values.put(HomeSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName());
    values.put(HomeSQLiteHelper.COLUMN_TIME, time);
    values.put(HomeSQLiteHelper.COLUMN_RETWEETER, originalName);
    values.put(HomeSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(HomeSQLiteHelper.COLUMN_PIC_URL, media);
    values.put(HomeSQLiteHelper.COLUMN_URL, url);
    values.put(HomeSQLiteHelper.COLUMN_USERS, users);
    values.put(HomeSQLiteHelper.COLUMN_HASHTAGS, hashtags);
    values.put(HomeSQLiteHelper.COLUMN_CLIENT_SOURCE, source);
    values.put(HomeSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url));
    values.put(HomeSQLiteHelper.COLUMN_CONVERSATION, status.getInReplyToStatusId() == -1 ? 0 : 1);

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

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

License:Apache License

public synchronized void createTweet(Status status, int account, boolean initial) {
    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];

    String source;
    if (status.isRetweet()) {
        source = android.text.Html.fromHtml(status.getRetweetedStatus().getSource()).toString();
    } else {
        source = android.text.Html.fromHtml(status.getSource()).toString();
    }

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

    values.put(HomeSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(HomeSQLiteHelper.COLUMN_TEXT, text);
    values.put(HomeSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(HomeSQLiteHelper.COLUMN_NAME, status.getUser().getName());
    values.put(HomeSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL());
    values.put(HomeSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName());
    values.put(HomeSQLiteHelper.COLUMN_TIME, time);
    values.put(HomeSQLiteHelper.COLUMN_RETWEETER, originalName);
    values.put(HomeSQLiteHelper.COLUMN_UNREAD, 0);
    values.put(HomeSQLiteHelper.COLUMN_PIC_URL, media);
    values.put(HomeSQLiteHelper.COLUMN_URL, url);
    values.put(HomeSQLiteHelper.COLUMN_USERS, users);
    values.put(HomeSQLiteHelper.COLUMN_HASHTAGS, hashtags);
    values.put(HomeSQLiteHelper.COLUMN_CLIENT_SOURCE, source);
    values.put(HomeSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url));
    values.put(HomeSQLiteHelper.COLUMN_CONVERSATION, status.getInReplyToStatusId() == -1 ? 0 : 1);

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