Example usage for twitter4j User getId

List of usage examples for twitter4j User getId

Introduction

In this page you can find the example usage for twitter4j User getId.

Prototype

long getId();

Source Link

Document

Returns the id of the user

Usage

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

License:Apache License

public static void convert(User user, Struct struct) {
    struct.put("Id", user.getId()).put("Name", user.getName()).put("ScreenName", user.getScreenName())
            .put("Location", user.getLocation()).put("Description", user.getDescription())
            .put("ContributorsEnabled", user.isContributorsEnabled())
            .put("ProfileImageURL", user.getProfileImageURL())
            .put("BiggerProfileImageURL", user.getBiggerProfileImageURL())
            .put("MiniProfileImageURL", user.getMiniProfileImageURL())
            .put("OriginalProfileImageURL", user.getOriginalProfileImageURL())
            .put("ProfileImageURLHttps", user.getProfileImageURLHttps())
            .put("BiggerProfileImageURLHttps", user.getBiggerProfileImageURLHttps())
            .put("MiniProfileImageURLHttps", user.getMiniProfileImageURLHttps())
            .put("OriginalProfileImageURLHttps", user.getOriginalProfileImageURLHttps())
            .put("DefaultProfileImage", user.isDefaultProfileImage()).put("URL", user.getURL())
            .put("Protected", user.isProtected()).put("FollowersCount", user.getFollowersCount())
            .put("ProfileBackgroundColor", user.getProfileBackgroundColor())
            .put("ProfileTextColor", user.getProfileTextColor())
            .put("ProfileLinkColor", user.getProfileLinkColor())
            .put("ProfileSidebarFillColor", user.getProfileSidebarFillColor())
            .put("ProfileSidebarBorderColor", user.getProfileSidebarBorderColor())
            .put("ProfileUseBackgroundImage", user.isProfileUseBackgroundImage())
            .put("DefaultProfile", user.isDefaultProfile())
            .put("ShowAllInlineMedia", user.isShowAllInlineMedia()).put("FriendsCount", user.getFriendsCount())
            .put("CreatedAt", user.getCreatedAt()).put("FavouritesCount", user.getFavouritesCount())
            .put("UtcOffset", user.getUtcOffset()).put("TimeZone", user.getTimeZone())
            .put("ProfileBackgroundImageURL", user.getProfileBackgroundImageURL())
            .put("ProfileBackgroundImageUrlHttps", user.getProfileBackgroundImageUrlHttps())
            .put("ProfileBannerURL", user.getProfileBannerURL())
            .put("ProfileBannerRetinaURL", user.getProfileBannerRetinaURL())
            .put("ProfileBannerIPadURL", user.getProfileBannerIPadURL())
            .put("ProfileBannerIPadRetinaURL", user.getProfileBannerIPadRetinaURL())
            .put("ProfileBannerMobileURL", user.getProfileBannerMobileURL())
            .put("ProfileBannerMobileRetinaURL", user.getProfileBannerMobileRetinaURL())
            .put("ProfileBackgroundTiled", user.isProfileBackgroundTiled()).put("Lang", user.getLang())
            .put("StatusesCount", user.getStatusesCount()).put("GeoEnabled", user.isGeoEnabled())
            .put("Verified", user.isVerified()).put("Translator", user.isTranslator())
            .put("ListedCount", user.getListedCount()).put("FollowRequestSent", user.isFollowRequestSent());

    List<String> withheldInCountries = new ArrayList<>();
    if (null != user.getWithheldInCountries()) {
        for (String s : user.getWithheldInCountries()) {
            withheldInCountries.add(s);//from  w w w.  ja  v  a 2 s.c  o m
        }
    }
    struct.put("WithheldInCountries", withheldInCountries);

}

From source file:com.javielinux.api.loaders.LoadMoreTweetDownLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {/*w  ww .j a  v  a 2s  .co  m*/

        LoadMoreTweetDownResponse response = new LoadMoreTweetDownResponse();

        PreferenceManager.setDefaultValues(getContext(), R.xml.preferences, false);
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getContext());
        int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60"));
        if (maxDownloadTweet <= 0)
            maxDownloadTweet = 60;

        ConnectionManager.getInstance().open(getContext());

        Twitter twitter = ConnectionManager.getInstance().getTwitter(request.getUserId());

        Paging p = new Paging();
        p.setCount(maxDownloadTweet);
        p.setSinceId(request.getSinceId());
        p.setMaxId(request.getMaxId());

        ResponseList<Status> statii = null;

        try {
            statii = twitter.getHomeTimeline(p);
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
        }

        boolean breakTimeline = false;

        if (statii != null && statii.size() >= maxDownloadTweet - 10) {
            p = new Paging(1, 10);
            p.setSinceId(request.getSinceId());
            p.setMaxId(statii.get(statii.size() - 1).getId());
            if (twitter.getHomeTimeline().size() > 0) {
                breakTimeline = true;
                response.setHasMoreTweets(true);
            }
        }

        if (statii != null) {

            if (statii.size() > 0) {

                try {
                    DataFramework.getInstance().open(getContext(), Utils.packageName);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                List<InfoTweet> tweets = new ArrayList<InfoTweet>();
                for (Status status : statii) {
                    tweets.add(new InfoTweet(status));
                }
                response.setTweets(tweets);

                long nextId = 1;
                Cursor c = DataFramework.getInstance().getCursor("tweets_user",
                        new String[] { DataFramework.KEY_ID }, null, null, null, null,
                        DataFramework.KEY_ID + " desc", "1");
                if (!c.moveToFirst()) {
                    c.close();
                    nextId = 1;
                } else {
                    long Id = c.getInt(0) + 1;
                    c.close();
                    nextId = Id;
                }

                try {
                    boolean isFirst = true;
                    for (int i = statii.size() - 1; i >= 0; i--) {
                        User u = statii.get(i).getUser();
                        if (u != null) {
                            ContentValues args = new ContentValues();
                            args.put(DataFramework.KEY_ID, "" + nextId);
                            args.put("type_id", TweetTopicsUtils.TWEET_TYPE_TIMELINE);
                            args.put("user_tt_id", "" + request.getUserId());
                            if (u.getProfileImageURL() != null) {
                                args.put("url_avatar", u.getProfileImageURL().toString());
                            } else {
                                args.put("url_avatar", "");
                            }
                            args.put("username", u.getScreenName());
                            args.put("fullname", u.getName());
                            args.put("user_id", "" + u.getId());
                            args.put("tweet_id", Utils.fillZeros("" + statii.get(i).getId()));
                            args.put("source", statii.get(i).getSource());
                            args.put("to_username", statii.get(i).getInReplyToScreenName());
                            args.put("to_user_id", "" + statii.get(i).getInReplyToUserId());
                            args.put("date", String.valueOf(statii.get(i).getCreatedAt().getTime()));
                            if (statii.get(i).getRetweetedStatus() != null) {
                                args.put("is_retweet", 1);
                                args.put("retweet_url_avatar", statii.get(i).getRetweetedStatus().getUser()
                                        .getProfileImageURL().toString());
                                args.put("retweet_username",
                                        statii.get(i).getRetweetedStatus().getUser().getScreenName());
                                args.put("retweet_source", statii.get(i).getRetweetedStatus().getSource());
                                String t = Utils.getTwitLoger(statii.get(i).getRetweetedStatus());
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getRetweetedStatus().getText());
                                    args.put("text_urls",
                                            Utils.getTextURLs(statii.get(i).getRetweetedStatus()));
                                } else {
                                    args.put("text", t);
                                }
                                args.put("is_favorite", 0);
                            } else {
                                String t = Utils.getTwitLoger(statii.get(i));
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getText());
                                    args.put("text_urls", Utils.getTextURLs(statii.get(i)));
                                } else {
                                    args.put("text", t);
                                }

                                if (statii.get(i).isFavorited()) {
                                    args.put("is_favorite", 1);
                                }
                            }

                            if (statii.get(i).getGeoLocation() != null) {
                                args.put("latitude", statii.get(i).getGeoLocation().getLatitude());
                                args.put("longitude", statii.get(i).getGeoLocation().getLongitude());
                            }
                            args.put("reply_tweet_id", statii.get(i).getInReplyToStatusId());

                            if (breakTimeline && isFirst)
                                args.put("has_more_tweets_down", 1);

                            DataFramework.getInstance().getDB().insert("tweets_user", null, args);

                            nextId++;

                            if (isFirst)
                                isFirst = false;
                        }

                    }

                } catch (SQLException e) {
                    e.printStackTrace();
                }

                DataFramework.getInstance().close();

            }

        }

        return response;

    } catch (TwitterException twitterException) {
        twitterException.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(twitterException, twitterException.getMessage());
        return errorResponse;
    } catch (Exception exception) {
        exception.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(exception, exception.getMessage());
        return errorResponse;
    }

}

From source file:com.javielinux.database.EntitySearch.java

License:Apache License

public InfoSaveTweets saveTweets(Context cnt, boolean saveNotifications, long since_id) {
    ConnectionManager.getInstance().open(cnt);
    Twitter twitter = ConnectionManager.getInstance().getUserForSearchesTwitter();
    InfoSaveTweets out = new InfoSaveTweets();
    try {/*  w  ww  . j av  a2s .  com*/
        int nResult = DataFramework.getInstance().getEntityListCount("tweets",
                "favorite=0 and search_id=" + getId());

        Query query = getQuery(cnt);
        if (since_id != -1)
            query.setSinceId(since_id);

        QueryResult result = twitter.search(query);
        ArrayList<Status> tweets = (ArrayList<Status>) result.getTweets();

        if (tweets.size() > 0) {

            out.setNewMessages(tweets.size());
            out.setNewerId(tweets.get(0).getId());
            out.setOlderId(tweets.get(tweets.size() - 1).getId());
            if (saveNotifications) {
                setValue("new_tweets_count", getInt("new_tweets_count") + tweets.size());
                save();
            }

            Log.d(Utils.TAG, tweets.size() + " mensajes nuevos en " + getString("name"));

            long fisrtId = 1;
            Cursor c = DataFramework.getInstance().getCursor("tweets", new String[] { DataFramework.KEY_ID },
                    null, null, null, null, DataFramework.KEY_ID + " desc", "1");
            if (!c.moveToFirst()) {
                c.close();
                fisrtId = 1;
            } else {
                long Id = c.getInt(0) + 1;
                c.close();
                fisrtId = Id;
            }

            for (int i = tweets.size() - 1; i >= 0; i--) {

                /*String sql = "INSERT INTO 'tweets' ("  + DataFramework.KEY_ID + ", search_id, url_avatar, username, user_id, tweet_id,"
                      + "text, source, to_username, to_user_id, date, favorite) VALUES (" + fisrtId + "," + getId()
                      + ",'" +tweets.get(i).getProfileImageUrl() + "','"+tweets.get(i).getFromUser()+"','"
                      + tweets.get(i).getFromUserId() + "','" + tweets.get(i).getId() + "','" + tweets.get(i).getText() 
                      + "','" + tweets.get(i).getSource()   + "','"+tweets.get(i).getToUser()
                      +"','"+tweets.get(i).getToUserId()+"','"+String.valueOf(tweets.get(i).getCreatedAt().getTime())
                      + "',0);\n";*/
                User u = tweets.get(i).getUser();
                ContentValues args = new ContentValues();
                args.put(DataFramework.KEY_ID, "" + fisrtId);
                args.put("search_id", "" + getId());
                if (u.getProfileImageURL() != null) {
                    args.put("url_avatar", u.getProfileImageURL().toString());
                } else {
                    args.put("url_avatar", "");
                }
                args.put("username", u.getScreenName());
                args.put("fullname", u.getName());
                args.put("user_id", "" + u.getId());
                args.put("tweet_id", Utils.fillZeros("" + tweets.get(i).getId()));
                args.put("text", tweets.get(i).getText());
                args.put("source", tweets.get(i).getSource());
                args.put("to_username", tweets.get(i).getInReplyToScreenName());
                args.put("to_user_id", "" + tweets.get(i).getInReplyToUserId());
                args.put("date", String.valueOf(tweets.get(i).getCreatedAt().getTime()));
                if (tweets.get(i).getGeoLocation() != null) {
                    args.put("latitude", tweets.get(i).getGeoLocation().getLatitude());
                    args.put("longitude", tweets.get(i).getGeoLocation().getLongitude());
                }
                args.put("favorite", "0");

                DataFramework.getInstance().getDB().insert("tweets", null, args);

                fisrtId++;

            }

            if (saveNotifications) {
                setValue("last_tweet_id_notifications", tweets.get(0).getId() + "");
                save();
            }

            int total = nResult + tweets.size();
            if (total > Utils.MAX_ROW_BYSEARCH) {
                Log.d(Utils.TAG, "Limpiando base de datos");
                String date = DataFramework.getInstance()
                        .getEntityList("tweets", "favorite=0 and search_id=" + getId(), "date desc")
                        .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                String sqldelete = "DELETE FROM tweets WHERE favorite=0 AND search_id=" + getId()
                        + " AND date  < '" + date + "'";
                DataFramework.getInstance().getDB().execSQL(sqldelete);
            }

        }

    } catch (TwitterException e) {
        e.printStackTrace();
        RateLimitStatus rate = e.getRateLimitStatus();
        if (rate != null) {
            out.setError(Utils.LIMIT_ERROR);
            out.setRate(rate);
        } else {
            out.setError(Utils.UNKNOWN_ERROR);
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.setError(Utils.UNKNOWN_ERROR);
    }
    return out;
}

From source file:com.javielinux.database.EntityTweetUser.java

License:Apache License

public InfoSaveTweets saveTweets(Context context, Twitter twitter) {

    InfoSaveTweets out = new InfoSaveTweets();

    try {//from  w  w  w  . j a  v a 2 s  . c o  m
        String where = "type_id = " + tweet_type + " AND user_tt_id=" + getId();

        int nResult = DataFramework.getInstance().getEntityListCount("tweets_user", where);
        if (nResult > 0)
            mLastIdNotification = DataFramework.getInstance().getTopEntity("tweets_user", where, "date desc")
                    .getLong("tweet_id");

        boolean breakTimeline = false;

        PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);

        int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60"));
        if (maxDownloadTweet <= 0)
            maxDownloadTweet = 60;

        ResponseList<twitter4j.Status> statii = null;
        ResponseList<twitter4j.DirectMessage> directs = null;

        if (mLastIdNotification > 0) {
            if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) {

                Paging p = new Paging(1, maxDownloadTweet);
                p.setSinceId(mLastIdNotification);

                try {
                    statii = twitter.getHomeTimeline(p);
                } catch (OutOfMemoryError e) {
                    e.printStackTrace();
                }

                if (statii != null && statii.size() >= maxDownloadTweet - 10) {
                    p = new Paging(1, 10);
                    p.setSinceId(mLastIdNotification);
                    p.setMaxId(statii.get(statii.size() - 1).getId());
                    if (twitter.getHomeTimeline().size() > 0) {
                        breakTimeline = true;
                    }
                }

            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                statii = twitter.getMentionsTimeline(p);
            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                directs = twitter.getDirectMessages(p);
            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                directs = twitter.getSentDirectMessages(p);
            }
        } else {
            try {
                Log.d(Utils.TAG, "Primera carga de " + getTypeText());
                if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) {
                    statii = twitter.getHomeTimeline(new Paging(1, 40));
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) {
                    statii = twitter.getMentionsTimeline(new Paging(1, 40));
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) {
                    directs = twitter.getDirectMessages();
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) {
                    directs = twitter.getSentDirectMessages();
                }
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
            }
        }

        // guardar statii

        if (statii != null) {

            if (statii.size() > 0) {
                out.setNewMessages(statii.size());
                out.setNewerId(statii.get(0).getId());
                out.setOlderId(statii.get(statii.size() - 1).getId());

                Log.d(Utils.TAG,
                        statii.size() + " mensajes nuevos en " + getTypeText() + " de " + getString("name"));

                long nextId = 1;
                Cursor c = DataFramework.getInstance().getCursor("tweets_user",
                        new String[] { DataFramework.KEY_ID }, null, null, null, null,
                        DataFramework.KEY_ID + " desc", "1");
                if (!c.moveToFirst()) {
                    c.close();
                    nextId = 1;
                } else {
                    long Id = c.getInt(0) + 1;
                    c.close();
                    nextId = Id;
                }

                DataFramework.getInstance().getDB().beginTransaction();

                try {
                    boolean isFirst = true;
                    for (int i = statii.size() - 1; i >= 0; i--) {
                        User u = statii.get(i).getUser();
                        if (u != null) {
                            ContentValues args = new ContentValues();
                            args.put(DataFramework.KEY_ID, "" + nextId);
                            args.put("type_id", tweet_type);
                            args.put("user_tt_id", "" + getId());
                            if (u.getProfileImageURL() != null) {
                                args.put("url_avatar", u.getProfileImageURL().toString());
                            } else {
                                args.put("url_avatar", "");
                            }
                            args.put("username", u.getScreenName());
                            args.put("fullname", u.getName());
                            args.put("user_id", "" + u.getId());
                            args.put("tweet_id", Utils.fillZeros("" + statii.get(i).getId()));
                            args.put("source", statii.get(i).getSource());
                            args.put("to_username", statii.get(i).getInReplyToScreenName());
                            args.put("to_user_id", "" + statii.get(i).getInReplyToUserId());
                            args.put("date", String.valueOf(statii.get(i).getCreatedAt().getTime()));
                            if (statii.get(i).getRetweetedStatus() != null) {
                                args.put("is_retweet", 1);
                                args.put("retweet_url_avatar", statii.get(i).getRetweetedStatus().getUser()
                                        .getProfileImageURL().toString());
                                args.put("retweet_username",
                                        statii.get(i).getRetweetedStatus().getUser().getScreenName());
                                args.put("retweet_source", statii.get(i).getRetweetedStatus().getSource());
                                String t = Utils.getTwitLoger(statii.get(i).getRetweetedStatus());
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getRetweetedStatus().getText());
                                    args.put("text_urls",
                                            Utils.getTextURLs(statii.get(i).getRetweetedStatus()));
                                } else {
                                    args.put("text", t);
                                }
                                args.put("is_favorite", 0);
                            } else {
                                String t = Utils.getTwitLoger(statii.get(i));
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getText());
                                    args.put("text_urls", Utils.getTextURLs(statii.get(i)));
                                } else {
                                    args.put("text", t);
                                }

                                if (statii.get(i).isFavorited()) {
                                    args.put("is_favorite", 1);
                                }
                            }

                            if (statii.get(i).getGeoLocation() != null) {
                                args.put("latitude", statii.get(i).getGeoLocation().getLatitude());
                                args.put("longitude", statii.get(i).getGeoLocation().getLongitude());
                            }
                            args.put("reply_tweet_id", statii.get(i).getInReplyToStatusId());

                            if (breakTimeline && isFirst)
                                args.put("has_more_tweets_down", 1);

                            DataFramework.getInstance().getDB().insert("tweets_user", null, args);

                            out.addId(nextId);

                            nextId++;

                            if (isFirst)
                                isFirst = false;
                        }

                    }

                    // finalizar

                    int total = nResult + statii.size();

                    if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH
                            || total > Utils.MAX_ROW_BYSEARCH_FORCE) {
                        try {
                            Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente "
                                    + total + " registros");
                            String date = DataFramework.getInstance()
                                    .getEntityList("tweets_user",
                                            "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc")
                                    .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                            String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type
                                    + " and user_tt_id=" + getId() + " AND date  < '" + date + "'";
                            DataFramework.getInstance().getDB().execSQL(sqldelete);
                        } catch (OutOfMemoryError e) {
                        }
                    }

                    DataFramework.getInstance().getDB().setTransactionSuccessful();

                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DataFramework.getInstance().getDB().endTransaction();
                }

            }

        }

        // guardar directs

        if (directs != null) {
            if (directs.size() > 0) {
                out.setNewMessages(directs.size());
                out.setNewerId(directs.get(0).getId());
                out.setOlderId(directs.get(directs.size() - 1).getId());

                Log.d(Utils.TAG, directs.size() + " mensajes directos a " + getString("name"));

                long nextId = 1;
                Cursor c = DataFramework.getInstance().getCursor("tweets_user",
                        new String[] { DataFramework.KEY_ID }, null, null, null, null,
                        DataFramework.KEY_ID + " desc", "1");
                if (!c.moveToFirst()) {
                    c.close();
                    nextId = 1;
                } else {
                    long Id = c.getInt(0) + 1;
                    c.close();
                    nextId = Id;
                }

                DataFramework.getInstance().getDB().beginTransaction();

                try {
                    for (int i = directs.size() - 1; i >= 0; i--) {
                        User u = directs.get(i).getSender();
                        if (u != null) {
                            ContentValues args = new ContentValues();
                            args.put(DataFramework.KEY_ID, "" + nextId);
                            args.put("type_id", tweet_type);
                            args.put("user_tt_id", "" + getId());
                            if (u.getProfileImageURL() != null) {
                                args.put("url_avatar", u.getProfileImageURL().toString());
                            } else {
                                args.put("url_avatar", "");
                            }
                            args.put("username", u.getScreenName());
                            args.put("fullname", u.getName());
                            args.put("user_id", "" + u.getId());
                            args.put("tweet_id", Utils.fillZeros("" + directs.get(i).getId()));
                            args.put("source", "");
                            args.put("to_username", directs.get(i).getRecipientScreenName());
                            args.put("to_user_id", "" + directs.get(i).getRecipientId());
                            args.put("date", String.valueOf(directs.get(i).getCreatedAt().getTime()));
                            args.put("text", directs.get(i).getText());

                            DataFramework.getInstance().getDB().insert("tweets_user", null, args);

                            out.addId(nextId);

                            Log.d(Utils.TAG,
                                    "getRecipientScreenName: " + directs.get(i).getRecipientScreenName());

                            nextId++;
                        }

                    }

                    // finalizar

                    int total = nResult + directs.size();

                    if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH) {
                        Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente " + total
                                + " registros");
                        String date = DataFramework.getInstance()
                                .getEntityList("tweets_user",
                                        "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc")
                                .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                        String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type
                                + " and user_tt_id=" + getId() + " AND date  < '" + date + "'";
                        DataFramework.getInstance().getDB().execSQL(sqldelete);
                    }

                    DataFramework.getInstance().getDB().setTransactionSuccessful();

                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DataFramework.getInstance().getDB().endTransaction();
                }

            }

        }
    } catch (TwitterException e) {
        e.printStackTrace();
        RateLimitStatus rate = e.getRateLimitStatus();
        if (rate != null) {
            out.setError(Utils.LIMIT_ERROR);
            out.setRate(rate);
        } else {
            out.setError(Utils.UNKNOWN_ERROR);
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.setError(Utils.UNKNOWN_ERROR);
    }
    return out;
}

From source file:com.javielinux.infos.InfoTweet.java

License:Apache License

public InfoTweet(User user) {
    urls = new ArrayList<URLContent>();
    mTypeFrom = FROM_USER;/*from   w w w  .j a  v a 2 s.c  o m*/

    urlAvatar = user.getProfileImageURL().toString();
    userId = user.getId();
    username = user.getScreenName();
    fullname = user.getName();
    try {
        id = user.getStatus().getId();
        text = user.getStatus().getText();
        source = user.getStatus().getSource();
        toUsername = user.getStatus().getInReplyToScreenName();
        toUserId = user.getStatus().getInReplyToUserId();
        createAt = user.getStatus().getCreatedAt();
        toReplyId = user.getStatus().getInReplyToStatusId();
        if (user.getStatus().getGeoLocation() != null) {
            latitude = user.getStatus().getGeoLocation().getLatitude();
            longitude = user.getStatus().getGeoLocation().getLongitude();
        }
    } catch (Exception e) {
    }

    calculateLinks();
}

From source file:com.javielinux.infos.InfoUsers.java

License:Apache License

public InfoUsers(User user) {
    setId(user.getId());
    setName(user.getScreenName());//from w w w. j  av a2 s. co m
    setFullname(user.getName());
    setCreated(user.getCreatedAt());
    setLocation(user.getLocation());
    if (user.getURL() != null)
        setUrl(user.getURL().toString());
    setFollowers(user.getFollowersCount());
    setFollowing(user.getFriendsCount());
    setTweets(user.getStatusesCount());
    setBio(user.getDescription());
    if (user.getStatus() != null)
        setTextTweet(user.getStatus().getText());
    setUrlAvatar(user.getProfileImageURL().toString());

    ArrayList<Entity> ents = DataFramework.getInstance().getEntityList("users",
            "service is null or service = \"twitter.com\"");

    for (Entity ent : ents) {
        friendly.put(ent.getString("name"), new Friend(ent.getString("name")));
    }

}

From source file:com.klinker.android.twitter.adapters.FollowersArrayAdapter.java

License:Apache License

@Override
public void setFollowingStatus(ViewHolder holder, User u) {
    if (holder.following != null) {
        Log.v("talon_followers", "checking follow status for: " + u.getName());
        Long l = u.getId();
        if (followingIds.contains(l)) {
            holder.following.setVisibility(View.VISIBLE);
            Log.v("talon_followers", "i am following this person");
        } else {/*from ww w.j  a  v a  2  s .  c  om*/
            holder.following.setVisibility(View.GONE);
            Log.v("talon_followers", "i am not following this person");
        }
    }
}

From source file:com.klinker.android.twitter.adapters.PeopleArrayAdapter.java

License:Apache License

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

    final long id = user.getId();
    holder.userId = id;//from  w ww .j  a  v  a 2 s . c  o  m

    holder.name.setText(user.getName());
    holder.screenName.setText("@" + user.getScreenName());

    //holder.picture.loadImage(user.getBiggerProfileImageURL(), true, null, NetworkedCacheableImageView.CIRCLE);
    final String url = user.getBiggerProfileImageURL();
    if (settings.roundContactImages) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadCircleImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    } else {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    }

    holder.background.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent viewProfile = new Intent(context, ProfilePager.class);
            viewProfile.putExtra("name", user.getName());
            viewProfile.putExtra("screenname", user.getScreenName());
            viewProfile.putExtra("proPic", user.getBiggerProfileImageURL());
            //viewProfile.putExtra("tweetid", holder.tweetId);
            viewProfile.putExtra("retweet", false);

            context.startActivity(viewProfile);
        }
    });

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

    setFollowingStatus(holder, user);
}

From source file:com.klinker.android.twitter.adapters.UserListMembersArrayAdapter.java

License:Apache License

@Override
public void bindView(final View view, int position, final User user) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    final long id = user.getId();
    holder.userId = id;//from  w w  w .ja v a2  s . c  o m

    holder.name.setText(user.getName());
    holder.screenName.setText("@" + user.getScreenName());

    final String url = user.getBiggerProfileImageURL();
    if (settings.roundContactImages) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadCircleImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    } else {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    }

    holder.picture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent viewProfile = new Intent(context, ProfilePager.class);
            viewProfile.putExtra("name", user.getName());
            viewProfile.putExtra("screenname", user.getScreenName());
            viewProfile.putExtra("proPic", user.getBiggerProfileImageURL());
            //viewProfile.putExtra("tweetid", holder.tweetId);
            viewProfile.putExtra("retweet", false);

            context.startActivity(viewProfile);
        }
    });

    holder.background.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.remove_user))
                    .setMessage(context.getResources().getString(R.string.remove) + " " + user.getName() + " "
                            + context.getResources().getString(R.string.from_list) + "?")
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            try {
                                new RemoveUser().execute(user.getId() + "");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    }).create().show();
        }
    });
}

From source file:com.klinker.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java

License:Apache License

public void getFollowers(final User user, final AsyncListView listView) {
    spinner.setVisibility(View.VISIBLE);
    canRefresh = false;/*from  w  w  w  .j a v a2 s.  co  m*/

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                try {
                    if (followingIds == null && user.getId() == settings.myId) {
                        long currCursor = -1;
                        IDs idObject;
                        int rep = 0;

                        do {
                            // gets 5000 ids at a time
                            idObject = twitter.getFriendsIDs(settings.myId, currCursor);

                            long[] lIds = idObject.getIDs();
                            followingIds = new ArrayList<Long>();
                            for (int i = 0; i < lIds.length; i++) {
                                followingIds.add(lIds[i]);
                            }

                            rep++;
                        } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3);
                    }
                } catch (Throwable t) {
                    followingIds = null;
                }

                PagableResponseList<User> friendsPaging = twitter.getFollowersList(user.getId(),
                        currentFollowers);

                for (int i = 0; i < friendsPaging.size(); i++) {
                    followers.add(friendsPaging.get(i));
                }

                if (friendsPaging.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                currentFollowers = friendsPaging.getNextCursor();

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (followersAdapter == null) {
                            if (followingIds == null) {
                                // we will do a normal array adapter
                                followersAdapter = new PeopleArrayAdapter(context, followers);
                            } else {
                                followersAdapter = new FollowersArrayAdapter(context, followers, followingIds);
                            }
                            listView.setAdapter(followersAdapter);
                        } else {
                            followersAdapter.notifyDataSetChanged();
                        }

                        if (settings.roundContactImages) {
                            ImageUtils.loadSizedCircleImage(context, profilePicture,
                                    thisUser.getOriginalProfileImageURL(), mCache, 96);
                        } else {
                            ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(),
                                    mCache);
                        }

                        String url = user.getProfileBannerURL();
                        ImageUtils.loadImage(context, background, url, mCache);

                        canRefresh = true;
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (user != null && user.isProtected()) {
                            Toast.makeText(context, getResources().getString(R.string.protected_account),
                                    Toast.LENGTH_SHORT).show();
                            if (settings.roundContactImages) {
                                ImageUtils.loadSizedCircleImage(context, profilePicture,
                                        thisUser.getOriginalProfileImageURL(), mCache, 96);
                            } else {
                                ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(),
                                        mCache);
                            }

                            String url = user.getProfileBannerURL();
                            ImageUtils.loadImage(context, background, url, mCache);
                        } else {
                            Toast.makeText(context, getResources().getString(R.string.error_loading_timeline),
                                    Toast.LENGTH_SHORT).show();
                        }
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                        hasMore = false;
                    }
                });
            }
        }
    }).start();
}