List of usage examples for twitter4j Status getRetweetedStatus
Status getRetweetedStatus();
From source file:com.klinker.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(); }//w w w . j ava 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); } 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(); }
From source file:com.klinker.android.twitter.data.sq_lite.InteractionsDataSource.java
License:Apache License
public synchronized void createInteraction(Context context, User source, Status status, int account, int type) { ContentValues values = new ContentValues(); long id;//from ww w . j a v a 2s .c o m if (status != null) { id = status.getId(); } else { id = 0; // 0 will be used for whenever it is just a follow } long time = new GregorianCalendar().getTime().getTime(); // current time String users = "@" + source.getScreenName() + " "; String text = ""; String title = ""; switch (type) { case TYPE_FAVORITE: title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.favorited); text = status.getText(); break; case TYPE_RETWEET: title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.retweeted); text = status.getRetweetedStatus().getText(); break; case TYPE_FOLLOWER: title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.followed); break; } values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account); values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text); values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id); values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, source.getOriginalProfileImageURL()); values.put(InteractionsSQLiteHelper.COLUMN_TIME, time); values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1); values.put(InteractionsSQLiteHelper.COLUMN_USERS, users); values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type); values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title); try { database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values); } catch (Exception e) { open(); database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values); } }
From source file:com.klinker.android.twitter.data.sq_lite.InteractionsDataSource.java
License:Apache License
public synchronized void updateInteraction(Context context, User source, Status status, int account, int type) { if (type == TYPE_RETWEET) { status = status.getRetweetedStatus(); }/*from www . ja v a2 s . co m*/ Cursor cursor = interactionExists(status.getId(), account); if (cursor.getCount() > 0) { // it does exist // i want to do the updating stuff if (cursor.moveToFirst()) { String users = cursor.getString(cursor.getColumnIndex(InteractionsSQLiteHelper.COLUMN_USERS)); String title = ""; users += "@" + source.getScreenName() + " "; String[] x = users.split(" "); if (type == TYPE_RETWEET) { // retweet title = x.length + " " + context.getResources().getString(R.string.new_retweets); } else { // favorite title = x.length + " " + context.getResources().getString(R.string.new_favorites); } ContentValues cv = new ContentValues(); cv.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1); cv.put(InteractionsSQLiteHelper.COLUMN_USERS, users); cv.put(InteractionsSQLiteHelper.COLUMN_TITLE, title); cv.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, source.getOriginalProfileImageURL()); cv.put(InteractionsSQLiteHelper.COLUMN_TIME, new GregorianCalendar().getTimeInMillis()); try { database.update(InteractionsSQLiteHelper.TABLE_INTERACTIONS, cv, InteractionsSQLiteHelper.COLUMN_TWEET_ID + " = ?", new String[] { status.getId() + "" }); } catch (Exception e) { open(); database.update(InteractionsSQLiteHelper.TABLE_INTERACTIONS, cv, InteractionsSQLiteHelper.COLUMN_TWEET_ID + " = ?", new String[] { status.getId() + "" }); } } } else { // this creates the entry createInteraction(context, source, status, account, type); } }
From source file:com.klinker.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(); }/*from w w w .j a v a 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]; 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); try { database.insert(ListSQLiteHelper.TABLE_HOME, null, values); } catch (Exception e) { open(); database.insert(ListSQLiteHelper.TABLE_HOME, null, values); } }
From source file:com.klinker.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 w w. java 2 s. c om*/ 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]; 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); valueses[i] = values; } return insertMultiple(valueses); }
From source file:com.klinker.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 .j a v a2s .com*/ public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); 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.klinker.android.twitter.ui.tweet_viewer.ViewRetweeters.java
License:Apache License
public void onRefreshStarted() { new Thread(new Runnable() { @Override// www . jav a2 s.c om public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); Status stat = twitter.showStatus(tweetId); if (stat.isRetweet()) { tweetId = stat.getRetweetedStatus().getId(); } // can get 100 retweeters is all ResponseList<twitter4j.Status> lists = twitter.getRetweets(tweetId); users.clear(); for (Status status : lists) { users.add(status.getUser()); } ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { adapter = new PeopleArrayAdapter(context, users); listView.setAdapter(adapter); listView.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); if (users.size() == 0) { noContent.setVisibility(View.VISIBLE); } mPullToRefreshLayout.setRefreshing(false); } }); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } } }).start(); }
From source file:com.marpies.ane.twitter.utils.StatusUtils.java
License:Apache License
public static JSONObject getJSON(Status status) throws JSONException { JSONObject statusJSON = new JSONObject(); statusJSON.put("id", status.getId()); statusJSON.put("idStr", String.valueOf(status.getId())); statusJSON.put("text", status.getText()); statusJSON.put("replyToUserID", status.getInReplyToUserId()); statusJSON.put("replyToStatusID", status.getInReplyToStatusId()); statusJSON.put("likesCount", status.getFavoriteCount()); statusJSON.put("retweetCount", status.getRetweetCount()); statusJSON.put("isRetweet", status.isRetweet()); statusJSON.put("isSensitive", status.isPossiblySensitive()); statusJSON.put("createdAt", status.getCreatedAt()); Status retweetedStatus = status.getRetweetedStatus(); if (retweetedStatus != null) { statusJSON.put("retweetedStatus", getJSON(retweetedStatus)); }/*from ww w .j a v a 2 s . c o m*/ User user = status.getUser(); if (user != null) { statusJSON.put("user", UserUtils.getJSON(user)); } return statusJSON; }
From source file:com.mothsoft.alexis.engine.retrieval.TwitterRetrievalTaskImpl.java
License:Apache License
private void handleSourceImpl(final TwitterSource twitterSource) { final SocialConnection socialConnection = twitterSource.getSocialConnection(); final AccessToken accessToken = new AccessToken(socialConnection.getOauthToken(), socialConnection.getOauthTokenSecret()); final List<Status> statuses = this.twitterService.getHomeTimeline(accessToken, twitterSource.getLastTweetId(), (short) 800); if (statuses != null && statuses.size() > 0) { logger.info("Twitter retrieval found " + statuses.size() + " Tweets for user: " + socialConnection.getRemoteUsername()); // the newest tweet in the timeline will be our starting point for // the next fetch twitterSource.setLastTweetId(statuses.get(0).getId()); // import these in reverse order to ensure newest ones have the // highest document IDs Collections.reverse(statuses); final Long userId = twitterSource.getUserId(); final User user = this.userDao.get(userId); for (final Status status : statuses) { final Long tweetId = status.getId(); Tweet tweet = this.tweetDao.getTweetByRemoteTweetId(tweetId); final boolean isAdd = (tweet == null); if (isAdd) { // TODO - is this right? // Twitter allows 2 different styles of retweets. The // ones that are actually retweets show as tweeted by the // original user. Others may show // "RT @original thing original said" tweeted // by the new person final boolean retweet = status.isRetweet(); final twitter4j.User tweeter; final String text; twitter4j.User retweeter = null; final List<TweetLink> links; final List<TweetMention> mentions; final List<TweetHashtag> hashtags; if (retweet) { tweeter = status.getRetweetedStatus().getUser(); text = status.getRetweetedStatus().getText(); retweeter = status.getUser(); links = readLinks(status.getRetweetedStatus()); mentions = readMentions(status.getRetweetedStatus()); hashtags = readHashtags(status.getRetweetedStatus()); } else { tweeter = status.getUser(); text = status.getText(); links = readLinks(status); mentions = readMentions(status); hashtags = readHashtags(status); }//from w ww. jav a2 s .co m final URL profileImageUrl = tweeter.getProfileImageUrlHttps(); final Date createdAt = status.getCreatedAt(); tweet = new Tweet(tweetId, createdAt, tweeter.getScreenName(), tweeter.getName(), profileImageUrl, text, links, mentions, hashtags, retweet, retweet ? retweeter.getScreenName() : null); this.documentDao.add(tweet); } final DocumentUser documentUser = new DocumentUser(tweet, user); if (isAdd || !tweet.getDocumentUsers().contains(documentUser)) { tweet.getDocumentUsers().add(new DocumentUser(tweet, user)); this.documentDao.update(tweet); } } } else { logger.info("Twitter retrieval found no Tweets for user: " + socialConnection.getRemoteUsername()); } twitterSource.setRetrievalDate(new Date()); this.sourceDao.update(twitterSource); }
From source file:com.mycompany.omnomtweets.Search.java
public static boolean writeToStdErr(Status tweet) { //System.out.println("Writing " + tweets.size() + " tweets"); boolean success = true; if (tweet != null) { String tweetText;//from w ww. j a v a2 s . c om String idOfRetweetee = ""; if (tweet.getRetweetedStatus() != null) { tweetText = "RT " + tweet.getRetweetedStatus().getText(); idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName(); //System.out.println("retweeted" + tweetText); } else { tweetText = tweet.getText(); } String urlText = ""; if (tweet.getURLEntities().length > 0) { for (URLEntity url : tweet.getURLEntities()) { if (url.getExpandedURL() != null) { urlText += url.getExpandedURL() + " "; tweetText = tweetText.replace(url.getURL(), url.getExpandedURL()); //System.out.println("Expanded URL " + url.getExpandedURL()); } else { urlText += url.getURL() + " "; //System.out.println("URL " + url.getURL()); } } } if (tweet.getMediaEntities().length > 0) { for (MediaEntity media : tweet.getMediaEntities()) { if (media.getExpandedURL() != null) { urlText += media.getExpandedURL() + " "; tweetText = tweetText.replace(media.getMediaURL(), media.getExpandedURL()); //System.out.println("Expanded URL " + media.getExpandedURL()); } else { urlText += media.getMediaURL() + " "; //System.out.println("URL " + media.getMediaURL()); } } } String encodedText = tweetText.replaceAll("\"", "\"\""); encodedText = encodedText.replaceAll("\\s", " "); String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + "," + tweet.getId() + "," + candidate.name + "," + sdf.format(tweet.getCreatedAt()) + "," + idOfRetweetee + "\n"; System.err.print(writeMe); //writeTweets.write(writeMe); } return success; }