Search in sources :

Example 16 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class ProfilePager method getUser.

public void getUser() {
    Thread getUser = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                thisUser = twitter.showUser(screenName);
            } catch (Exception e) {
                thisUser = null;
            }
            if (thisUser != null) {
                try {
                    FollowersDataSource.getInstance(context).createUser(thisUser, sharedPrefs.getInt("current_account", 1));
                } catch (Exception e) {
                // the user already exists. don't know if this is more efficient than querying the db or not.
                }
                final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(context, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
                suggestions.saveRecentQuery("@" + thisUser.getScreenName(), null);
            }
            new GetActionBarInfo().execute();
        }
    });
    getUser.setPriority(Thread.MAX_PRIORITY);
    getUser.start();
}
Also used : Twitter(twitter4j.Twitter) SearchRecentSuggestions(android.provider.SearchRecentSuggestions) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 17 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class TwitterSearchFragment method findStatus.

public void findStatus(final long statusid) {
    listView.setVisibility(View.GONE);
    spinner.setVisibility(View.VISIBLE);
    hasMore = false;
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                Status status = twitter.showStatus(statusid);
                final ArrayList<Status> statuses = new ArrayList<Status>();
                statuses.add(status);
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        TimelineArrayAdapter adapter = new TimelineArrayAdapter(context, statuses, onlyStatus);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
                hasMore = false;
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) Activity(android.app.Activity) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter)

Example 18 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class TwitterSearchFragment method onRefreshStarted.

public void onRefreshStarted() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            final long topId;
            if (tweets.size() > 0) {
                topId = tweets.get(0).getId();
            } else {
                topId = 0;
            }
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                query = new Query(searchQuery);
                if (topTweets) {
                    query.setResultType(Query.POPULAR);
                } else {
                    query.setResultType(null);
                }
                QueryResult result = twitter.search(query);
                tweets.clear();
                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }
                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        int top = 0;
                        for (int i = 0; i < tweets.size(); i++) {
                            if (tweets.get(i).getId() == topId) {
                                top = i;
                                break;
                            }
                        }
                        adapter = new TimelineArrayAdapter(context, tweets, onlyStatus);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        listView.setSelection(top);
                        spinner.setVisibility(View.GONE);
                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            }
        }
    }).start();
}
Also used : QueryResult(twitter4j.QueryResult) Query(twitter4j.Query) Status(twitter4j.Status) Twitter(twitter4j.Twitter) Activity(android.app.Activity) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter)

Example 19 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class UserSearchFragment method getMoreUsers.

public void getMoreUsers(final String mQuery) {
    if (hasMore) {
        canRefresh = false;
        mPullToRefreshLayout.setRefreshing(true);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Twitter twitter = Utils.getTwitter(context, settings);
                    ResponseList<User> result = twitter.searchUsers(mQuery, userPage);
                    userPage++;
                    for (User u : result) {
                        users.add(u);
                    }
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            if (peopleAdapter != null) {
                                peopleAdapter.notifyDataSetChanged();
                            }
                            mPullToRefreshLayout.setRefreshing(false);
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            mPullToRefreshLayout.setRefreshing(false);
                        }
                    });
                    hasMore = false;
                }
            }
        }).start();
    }
}
Also used : User(twitter4j.User) Twitter(twitter4j.Twitter) Activity(android.app.Activity)

Example 20 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class UserSearchFragment method doUserSearch.

public void doUserSearch(final String mQuery) {
    listView.setVisibility(View.GONE);
    spinner.setVisibility(View.VISIBLE);
    hasMore = true;
    canRefresh = false;
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                ResponseList<User> result = twitter.searchUsers(mQuery, userPage);
                userPage++;
                if (result.size() < 18) {
                    hasMore = false;
                    canRefresh = false;
                }
                users = new ArrayList<User>();
                for (User u : result) {
                    users.add(u);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        peopleAdapter = new PeopleArrayAdapter(context, users, onlyProfile);
                        listView.setAdapter(peopleAdapter);
                        listView.setVisibility(View.VISIBLE);
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
                hasMore = false;
                canRefresh = true;
            }
        }
    }).start();
}
Also used : PeopleArrayAdapter(com.klinker.android.twitter.adapters.PeopleArrayAdapter) User(twitter4j.User) Twitter(twitter4j.Twitter) Activity(android.app.Activity)

Aggregations

Twitter (twitter4j.Twitter)125 TwitterException (twitter4j.TwitterException)76 TwitterFactory (twitter4j.TwitterFactory)59 Status (twitter4j.Status)44 Activity (android.app.Activity)35 QueryResult (twitter4j.QueryResult)17 TimelineArrayAdapter (com.klinker.android.twitter.adapters.TimelineArrayAdapter)16 ArrayList (java.util.ArrayList)13 Intent (android.content.Intent)12 User (twitter4j.User)12 Query (twitter4j.Query)11 IDs (twitter4j.IDs)8 LinearLayout (android.widget.LinearLayout)7 IOException (java.io.IOException)7 Context (android.content.Context)6 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)6 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)5 GeoLocation (twitter4j.GeoLocation)5 Paging (twitter4j.Paging)5