Example usage for twitter4j Status getInReplyToStatusId

List of usage examples for twitter4j Status getInReplyToStatusId

Introduction

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

Prototype

long getInReplyToStatusId();

Source Link

Document

Returns the in_reply_tostatus_id

Usage

From source file:ac.simons.tweetarchive.tweets.TweetStorageService.java

License:Apache License

@Transactional
public TweetEntity store(final Status status, final String rawContent) {
    final Optional<TweetEntity> existingTweet = this.tweetRepository.findOne(status.getId());
    if (existingTweet.isPresent()) {
        final TweetEntity rv = existingTweet.get();
        log.warn("Tweet with status {} already existed...", rv.getId());
        return rv;
    }//from  w  ww .  j  av  a  2 s .  c om

    final TweetEntity tweet = new TweetEntity(status.getId(), status.getUser().getId(),
            status.getUser().getScreenName(), status.getCreatedAt().toInstant().atZone(ZoneId.of("UTC")),
            extractContent(status), extractSource(status), rawContent);
    tweet.setCountryCode(Optional.ofNullable(status.getPlace()).map(Place::getCountryCode).orElse(null));
    if (status.getInReplyToStatusId() != -1L && status.getInReplyToUserId() != -1L
            && status.getInReplyToScreenName() != null) {
        tweet.setInReplyTo(new InReplyTo(status.getInReplyToStatusId(), status.getInReplyToScreenName(),
                status.getInReplyToUserId()));
    }
    tweet.setLang(status.getLang());
    tweet.setLocation(Optional.ofNullable(status.getGeoLocation())
            .map(g -> new TweetEntity.Location(g.getLatitude(), g.getLongitude())).orElse(null));
    // TODO Handle quoted tweets
    return this.tweetRepository.save(tweet);
}

From source file:au.net.moon.tUtils.twitterFields.java

License:Open Source License

/**
 * Get a <CODE>HashMap</CODE> of tweet fields by parsing a twitter4j Status
 * /*from  w  w w  .  ja v  a2  s  .  com*/
 * @param status
 *            the twitter4j Status object
 * @return the tweet fields as name, value pairs in a <CODE>HashMap</CODE>.
 */
public static HashMap<String, String> parseStatusObj(Status status) {
    HashMap<String, String> splitFields = new HashMap<String, String>();

    splitFields.put("createdAt", status.getCreatedAt().toString());
    splitFields.put("id", Long.toString(status.getId()));
    splitFields.put("text", status.getText());
    splitFields.put("source", status.getSource());
    splitFields.put("isTruncated", status.isTruncated() ? "1" : "0");
    splitFields.put("inReplyToStatusId", Long.toString(status.getInReplyToStatusId()));
    splitFields.put("inReplyToUserId", Long.toString(status.getInReplyToUserId()));
    splitFields.put("isFavorited", status.isFavorited() ? "1" : "0");
    splitFields.put("inReplyToScreenName", status.getInReplyToScreenName());
    if (status.getGeoLocation() != null) {
        splitFields.put("geoLocation", status.getGeoLocation().toString());
    } else {
        splitFields.put("geoLocation", "");
    }
    if (status.getPlace() != null) {
        splitFields.put("place", status.getPlace().toString());
    } else {
        splitFields.put("place", "");
    }
    splitFields.put("retweetCount", Long.toString(status.getRetweetCount()));
    splitFields.put("wasRetweetedByMe", status.isRetweetedByMe() ? "1" : "0");
    String contributors = "";
    if (status.getContributors() != null) {
        long[] tempContributors = status.getContributors();
        for (int i = 0; i < tempContributors.length; i++) {
            contributors += Long.toString(tempContributors[i]);
            if (i != tempContributors.length - 1) {
                contributors += ", ";
            }
        }
    }
    splitFields.put("contributors", contributors);
    splitFields.put("annotations", "");
    if (status.getRetweetedStatus() != null) {
        splitFields.put("retweetedStatus", "1");
    } else {
        splitFields.put("retweetedStatus", "0");
    }
    splitFields.put("userMentionEntities", status.getUserMentionEntities().toString());
    splitFields.put("urlEntities", status.getURLEntities().toString());
    splitFields.put("hashtagEntities", status.getHashtagEntities().toString());
    splitFields.put("user", status.getUser().toString());
    return splitFields;
}

From source file:br.com.porcelli.hornetq.integration.twitter.support.TweetMessageConverterSupport.java

License:Apache License

public static ServerMessage buildMessage(final String queueName, final Status status) {
    final ServerMessage msg = new ServerMessageImpl(status.getId(),
            InternalTwitterConstants.INITIAL_MESSAGE_BUFFER_SIZE);
    msg.setAddress(new SimpleString(queueName));
    msg.setDurable(true);//from   w  w w  .j av a2  s  . c  o m

    msg.putStringProperty(TwitterConstants.KEY_MSG_TYPE, MessageType.TWEET.toString());
    msg.putStringProperty(TwitterConstants.KEY_CREATED_AT, read(status.getCreatedAt()));
    msg.putStringProperty(TwitterConstants.KEY_ID, read(status.getId()));

    msg.putStringProperty(TwitterConstants.KEY_TEXT, read(status.getText()));
    msg.putStringProperty(TwitterConstants.KEY_SOURCE, read(status.getSource()));
    msg.putStringProperty(TwitterConstants.KEY_TRUNCATED, read(status.isTruncated()));
    msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_STATUS_ID, read(status.getInReplyToStatusId()));
    msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_USER_ID, read(status.getInReplyToUserId()));
    msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_SCREEN_NAME, read(status.getInReplyToScreenName()));

    msg.putStringProperty(TwitterConstants.KEY_RETWEET, read(status.isRetweet()));
    msg.putStringProperty(TwitterConstants.KEY_FAVORITED, read(status.isFavorited()));

    msg.putStringProperty(TwitterConstants.KEY_ENTITIES_URLS_JSON, read(status.getURLEntities()));
    msg.putStringProperty(TwitterConstants.KEY_ENTITIES_HASHTAGS_JSON, read(status.getHashtagEntities()));
    msg.putStringProperty(TwitterConstants.KEY_ENTITIES_MENTIONS_JSON, read(status.getUserMentionEntities()));

    msg.putStringProperty(TwitterConstants.KEY_CONTRIBUTORS_JSON, read(status.getContributors()));

    if (status.getUser() != null) {
        buildUserData("", status.getUser(), msg);
    }

    GeoLocation gl;
    if ((gl = status.getGeoLocation()) != null) {
        msg.putStringProperty(TwitterConstants.KEY_GEO_LATITUDE, read(gl.getLatitude()));
        msg.putStringProperty(TwitterConstants.KEY_GEO_LONGITUDE, read(gl.getLongitude()));
    }

    Place place;
    if ((place = status.getPlace()) != null) {
        msg.putStringProperty(TwitterConstants.KEY_PLACE_ID, read(place.getId()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_URL, read(place.getURL()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_NAME, read(place.getName()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_FULL_NAME, read(place.getFullName()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_COUNTRY_CODE, read(place.getCountryCode()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_COUNTRY, read(place.getCountry()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_STREET_ADDRESS, read(place.getStreetAddress()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_TYPE, read(place.getPlaceType()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_GEO_TYPE, read(place.getGeometryType()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_TYPE, read(place.getBoundingBoxType()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_COORDINATES_JSON,
                read(place.getBoundingBoxCoordinates().toString()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_GEOMETRY_COORDINATES_JSON,
                read(place.getGeometryCoordinates().toString()));
    }

    msg.putStringProperty(TwitterConstants.KEY_RAW_JSON, status.toString());

    return msg;
}

From source file:com.alainesp.fan.sanderson.SummaryFragment.java

License:Open Source License

protected int doWork() {
    int state = DownloadParseSaveTask.STATE_SUCCESS;

    try {/*w  ww .ja  v  a  2 s  .  c o m*/
        List<twitter4j.Status> tweets;

        // Twitter client configuration
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TwitterAPISecrets.CONSUMER_KEY)
                .setOAuthConsumerSecret(TwitterAPISecrets.CONSUMER_SECRET);
        // TODO: Use guest authentication instead of application
        builder.setApplicationOnlyAuthEnabled(true).setDebugEnabled(false).setGZIPEnabled(true);

        Twitter twitter = new TwitterFactory(builder.build()).getInstance();
        twitter.getOAuth2Token();

        // Get the tweets
        long lastTweetID = DB.Tweet.getLastTweetID();
        if (lastTweetID <= 0)
            tweets = twitter.getUserTimeline("BrandSanderson");
        else
            tweets = twitter.getUserTimeline("BrandSanderson", new Paging(lastTweetID));

        if (tweets != null) {
            long brandonID = 28187205;
            Hashtable<Long, DB.Tweet> findTweet = new Hashtable<>(tweets.size() * 16, 0.25f);
            List<DB.Tweet> dbTweets = new ArrayList<>(tweets.size());
            for (twitter4j.Status tweet : tweets) {
                // Create the tweet
                if (tweet.isRetweet())
                    tweet = tweet.getRetweetedStatus();

                long tweetID = tweet.getId();
                // TODO: Include the tweets in the DB
                if (findTweet.get(tweetID) == null)// This eliminate tweets already in the replies tree
                {
                    DB.Tweet dbTweet = new DB.Tweet(tweetID, getTweetText(tweet), tweet.getCreatedAt(), false,
                            tweet.getUser().getName(), tweet.getUser().getBiggerProfileImageURLHttps());
                    InternetHelper.getRemoteFile(tweet.getUser().getBiggerProfileImageURLHttps());
                    dbTweets.add(dbTweet);
                    findTweet.put(tweetID, dbTweet);

                    // Traverse the tree of the replies tweets
                    twitter4j.Status treeTweet = tweet;
                    while (treeTweet != null && treeTweet.getInReplyToStatusId() >= 0) {
                        try {
                            long id = treeTweet.getInReplyToStatusId();
                            long userID = treeTweet.getUser().getId();
                            treeTweet = null;
                            if (findTweet.get(id) == null || brandonID == userID)
                                treeTweet = twitter.showStatus(id);
                            else// Remove duplicates. Not sure why they appear, but the difference of the text is a dot at the end.
                                dbTweets.remove(dbTweets.size() - 1);
                        } catch (Exception ignore) {
                        }

                        if (treeTweet != null) {
                            findTweet.put(treeTweet.getId(), dbTweet);
                            StringBuilder replyBuilder = new StringBuilder();

                            replyBuilder.append("<blockquote>");

                            // Profile image
                            replyBuilder.append("<img src=\"");
                            InternetHelper.getRemoteFile(treeTweet.getUser().getBiggerProfileImageURLHttps());
                            replyBuilder.append(treeTweet.getUser().getBiggerProfileImageURLHttps());
                            replyBuilder.append("\"/>&nbsp;<b>");

                            // Username - date
                            replyBuilder.append(treeTweet.getUser().getName());
                            replyBuilder.append("</b> @");
                            replyBuilder.append(treeTweet.getUser().getScreenName());
                            replyBuilder.append(" - ");
                            replyBuilder
                                    .append(TwitterFragment.showDateFormat.format(treeTweet.getCreatedAt()));

                            // Tweet text
                            replyBuilder.append("<br/>");
                            replyBuilder.append(getTweetText(treeTweet));

                            // Remaining
                            replyBuilder.append(dbTweet.htmlReply);
                            replyBuilder.append("</blockquote>");

                            dbTweet.htmlReply = replyBuilder.toString();
                        }
                    }
                }
            }
            DB.Tweet.updateTwitter(dbTweets);
        }
    } catch (Exception e) {
        Logger.reportError(e.toString());
        state = DownloadParseSaveTask.STATE_ERROR_PARSING;
    }

    return state;
}

From source file:com.appspot.socialinquirer.server.service.impl.UserServiceImpl.java

License:Apache License

@Override
public void aggregateQuotes() {
    EntityManager entityManager = createEntityManager();
    try {//w  w w. ja  v a 2 s .  c o m
        DataAccessObject dao = getDao(entityManager);
        Version version = getCurrentVersion();
        Twitter twitter = getTwitterClient();
        List<Status> homeTimeline = twitter.getUserTimeline(ApplicationConstants.TWITTER_SCREEN_NAME,
                new Paging(version.getLastHomeTweetId()));
        long lastTweetId = 0L;
        for (Status status : homeTimeline) {
            if (status.getId() > lastTweetId) {
                lastTweetId = status.getId();
            }
            if (!status.isRetweet() && status.getInReplyToStatusId() == -1) {
                Quote quote = new Quote();
                quote.setPublishedDate(status.getCreatedAt());
                quote.setText(new Text(status.getText()));
                quote.setTweetId(status.getId());
                dao.saveOrUpdate(quote);
            }
        }
        if (lastTweetId > version.getLastHomeTweetId()) {
            version.setLastHomeTweetId(lastTweetId);
            dao.saveOrUpdate(version);
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    } finally {
        closeEntityManager(entityManager);
    }
}

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  .  ja  va2s  .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.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);
    }//from ww w.j  a va2  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.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();
    }/*  w ww . j ava  2  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];

    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();
    }// w  w w. j av  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();
    }

    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);
    }
}

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

License:Apache License

public synchronized int insertTweets(List<Status> statuses, int currentAccount, long[] lastIds) {

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

    for (int i = 0; i < statuses.size(); i++) {
        Status status = statuses.get(i);
        Long id = status.getId();
        ContentValues values = new ContentValues();

        if (id > lastIds[0]) {
            String originalName = "";
            long mId = status.getId();
            long time = status.getCreatedAt().getTime();

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

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

            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);
            values.put(HomeSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url));
            values.put(HomeSQLiteHelper.COLUMN_CONVERSATION, status.getInReplyToStatusId() == -1 ? 0 : 1);

        } else {
            values = null;
        }

        valueses[i] = values;
    }

    ArrayList<ContentValues> vals = new ArrayList<ContentValues>();

    for (ContentValues v : valueses) {
        if (v != null) {
            vals.add(v);
        }
    }

    insertMultiple(valueses);

    return vals.size();
}