Search in sources :

Example 11 with QueryResult

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

the class SavedSearchFragment method getCursorAdapter.

@Override
public void getCursorAdapter(boolean showSpinner) {
    if (showSpinner) {
        listView.setVisibility(View.GONE);
        spinner.setVisibility(View.VISIBLE);
    }
    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(search);
                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;
                }
                try {
                    ((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);
                            listView.setAdapter(adapter);
                            listView.setVisibility(View.VISIBLE);
                            listView.setSelection(top);
                            spinner.setVisibility(View.GONE);
                            refreshLayout.setRefreshing(false);
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    ((Activity) context).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            spinner.setVisibility(View.GONE);
                            refreshLayout.setRefreshing(false);
                        }
                    });
                } catch (Exception x) {
                    e.printStackTrace();
                }
            }
        }
    }).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 12 with QueryResult

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

the class SavedSearchFragment method getMore.

public void getMore() {
    if (hasMore) {
        canRefresh = false;
        refreshLayout.setRefreshing(true);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Twitter twitter = Utils.getTwitter(context, settings);
                    QueryResult result = twitter.search(query);
                    for (twitter4j.Status status : result.getTweets()) {
                        tweets.add(status);
                    }
                    if (result.hasNext()) {
                        query = result.nextQuery();
                        hasMore = true;
                    } else {
                        hasMore = false;
                    }
                    try {
                        ((Activity) context).runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                adapter.notifyDataSetChanged();
                                refreshLayout.setRefreshing(false);
                                canRefresh = true;
                            }
                        });
                    } catch (Exception e) {
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        ((Activity) context).runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                refreshLayout.setRefreshing(false);
                                canRefresh = true;
                            }
                        });
                    } catch (Exception x) {
                    }
                }
            }
        }).start();
    }
}
Also used : QueryResult(twitter4j.QueryResult) Status(twitter4j.Status) Twitter(twitter4j.Twitter) Activity(android.app.Activity)

Example 13 with QueryResult

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

the class TwitterSearchFragment method doSearch.

public void doSearch(final String mQuery) {
    spinner.setVisibility(View.VISIBLE);
    if (listView.getVisibility() != View.GONE) {
        listView.setVisibility(View.GONE);
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                Log.v("talon_searching", "query in frag: " + mQuery);
                query = new Query(mQuery);
                if (topTweets) {
                    query.setResultType(Query.ResultType.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() {
                        adapter = new TimelineArrayAdapter(context, tweets, 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);
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
            }
        }
    }).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 14 with QueryResult

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

the class TwitterSearchFragment method getMore.

public void getMore() {
    if (hasMore) {
        canRefresh = false;
        mPullToRefreshLayout.setRefreshing(true);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Twitter twitter = Utils.getTwitter(context, settings);
                    QueryResult result = twitter.search(query);
                    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() {
                            adapter.notifyDataSetChanged();
                            mPullToRefreshLayout.setRefreshing(false);
                            canRefresh = true;
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    ((Activity) context).runOnUiThread(new Runnable() {

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

Example 15 with QueryResult

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

the class ProfileMentionsFragment method doSearch.

public void doSearch() {
    spinner.setVisibility(View.VISIBLE);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                query = new Query("@" + screenName + " -RT");
                query.sinceId(1);
                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() {
                        adapter = new TimelineArrayAdapter(context, tweets);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                        if (!hasMore) {
                            View footer = inflater.inflate(R.layout.mentions_footer, null);
                            listView.addFooterView(footer);
                            listView.setFooterDividersEnabled(false);
                        }
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                        if (!hasMore) {
                            View footer = inflater.inflate(R.layout.mentions_footer, null);
                            listView.addFooterView(footer);
                            listView.setFooterDividersEnabled(false);
                        }
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                        if (!hasMore) {
                            View footer = inflater.inflate(R.layout.mentions_footer, null);
                            listView.addFooterView(footer);
                            listView.setFooterDividersEnabled(false);
                        }
                    }
                });
            }
        }
    }).start();
}
Also used : Query(twitter4j.Query) Twitter(twitter4j.Twitter) Activity(android.app.Activity) AbsListView(android.widget.AbsListView) AsyncListView(org.lucasr.smoothie.AsyncListView) View(android.view.View) QueryResult(twitter4j.QueryResult) Status(twitter4j.Status) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter)

Aggregations

QueryResult (twitter4j.QueryResult)18 Twitter (twitter4j.Twitter)17 Status (twitter4j.Status)16 Activity (android.app.Activity)12 Query (twitter4j.Query)12 TimelineArrayAdapter (com.klinker.android.twitter.adapters.TimelineArrayAdapter)8 TwitterException (twitter4j.TwitterException)5 ComposeActivity (com.klinker.android.twitter.activities.compose.ComposeActivity)3 SettingsActivity (com.klinker.android.twitter.settings.SettingsActivity)3 GeoLocation (twitter4j.GeoLocation)3 View (android.view.View)2 AbsListView (android.widget.AbsListView)2 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)2 ArrayList (java.util.ArrayList)2 TwitterEndpoint (org.apache.camel.component.twitter.TwitterEndpoint)2 AsyncListView (org.lucasr.smoothie.AsyncListView)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 Location (android.location.Location)1 LinearLayout (android.widget.LinearLayout)1 Mastodon4jRequestException (com.sys1yagi.mastodon4j.api.exception.Mastodon4jRequestException)1