Search in sources :

Example 11 with TimelineArrayAdapter

use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.

the class NearbyTweets method getTweets.

public void getTweets() {
    canRefresh = false;
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);
                boolean manualLoc = sharedPrefs.getBoolean("manually_config_location", false);
                int i = 0;
                while (!connected && i < 5 && !manualLoc) {
                    try {
                        Thread.sleep(1500);
                    } catch (Exception e) {
                    }
                    i++;
                }
                double latitude = -1;
                double longitude = -1;
                if (manualLoc) {
                    // need to query yahoos api for the location...
                    double[] loc = getLocationFromYahoo(sharedPrefs.getInt("woeid", 2379574));
                    latitude = loc[0];
                    longitude = loc[1];
                } else {
                    // set it from the location client
                    Location location = mLastLocation;
                    latitude = location.getLatitude();
                    longitude = location.getLongitude();
                }
                query = new Query();
                query.setGeoCode(new GeoLocation(latitude, longitude), 10, Query.MILES);
                QueryResult result = twitter.search(query);
                if (result.hasNext()) {
                    hasMore = true;
                    query = result.nextQuery();
                } else {
                    hasMore = false;
                }
                for (Status s : result.getTweets()) {
                    statuses.add(s);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        adapter = new TimelineArrayAdapter(context, statuses);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Throwable e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Toast.makeText(context, getString(R.string.error), Toast.LENGTH_SHORT).show();
                        } catch (IllegalStateException e) {
                        // not attached to activity
                        }
                    }
                });
            }
            canRefresh = true;
        }
    }).start();
}
Also used : Status(twitter4j.Status) Query(twitter4j.Query) Twitter(twitter4j.Twitter) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) Activity(android.app.Activity) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) QueryResult(twitter4j.QueryResult) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) GeoLocation(twitter4j.GeoLocation) LinearLayout(android.widget.LinearLayout) GeoLocation(twitter4j.GeoLocation) Location(android.location.Location)

Example 12 with TimelineArrayAdapter

use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.

the class RetweetActivity method getRetweets.

public void getRetweets() {
    if (!hasMore) {
        return;
    }
    canRefresh = false;
    final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                final ResponseList<twitter4j.Status> favs = twitter.getRetweetsOfMe(paging);
                if (favs.size() < 17) {
                    hasMore = false;
                }
                paging.setPage(paging.getPage() + 1);
                for (twitter4j.Status s : favs) {
                    statuses.add(s);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (adapter == null) {
                            if (statuses.size() > 0) {
                                adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.RETWEET);
                                listView.setAdapter(adapter);
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
                                try {
                                    nothing.setVisibility(View.VISIBLE);
                                } catch (Exception e) {
                                }
                                listView.setVisibility(View.GONE);
                            }
                        } else {
                            adapter.notifyDataSetChanged();
                        }
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) LoginActivity(com.klinker.android.twitter.activities.setup.LoginActivity) MainActivity(com.klinker.android.twitter.activities.MainActivity) Activity(android.app.Activity) Status(twitter4j.Status) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) LinearLayout(android.widget.LinearLayout)

Example 13 with TimelineArrayAdapter

use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.

the class SearchedTrendsActivity 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);
                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);
                        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) ComposeActivity(com.klinker.android.twitter.activities.compose.ComposeActivity) SettingsActivity(com.klinker.android.twitter.settings.SettingsActivity) Activity(android.app.Activity) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) TwitterException(twitter4j.TwitterException)

Example 14 with TimelineArrayAdapter

use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.

the class FavoritesActivity method getFavorites.

public void getFavorites() {
    if (!hasMore) {
        return;
    }
    canRefresh = false;
    final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                final ResponseList<twitter4j.Status> favs = twitter.getFavorites(paging);
                if (favs.size() < 17) {
                    hasMore = false;
                }
                paging.setPage(paging.getPage() + 1);
                for (twitter4j.Status s : favs) {
                    statuses.add(s);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (adapter == null) {
                            if (statuses.size() > 0) {
                                adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.FAVORITE);
                                listView.setAdapter(adapter);
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
                                nothing.setVisibility(View.VISIBLE);
                                listView.setVisibility(View.GONE);
                                hasMore = false;
                            }
                        } else {
                            adapter.notifyDataSetChanged();
                        }
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) LoginActivity(com.klinker.android.twitter.activities.setup.LoginActivity) MainActivity(com.klinker.android.twitter.activities.MainActivity) Activity(android.app.Activity) Status(twitter4j.Status) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) LinearLayout(android.widget.LinearLayout)

Example 15 with TimelineArrayAdapter

use of com.klinker.android.twitter.adapters.TimelineArrayAdapter 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)

Aggregations

TimelineArrayAdapter (com.klinker.android.twitter.adapters.TimelineArrayAdapter)17 Status (twitter4j.Status)16 Twitter (twitter4j.Twitter)16 Activity (android.app.Activity)14 Query (twitter4j.Query)8 QueryResult (twitter4j.QueryResult)8 LinearLayout (android.widget.LinearLayout)4 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)4 ArrayList (java.util.ArrayList)4 TwitterException (twitter4j.TwitterException)4 View (android.view.View)2 AbsListView (android.widget.AbsListView)2 MainActivity (com.klinker.android.twitter.activities.MainActivity)2 ComposeActivity (com.klinker.android.twitter.activities.compose.ComposeActivity)2 SettingsActivity (com.klinker.android.twitter.settings.SettingsActivity)2 AsyncListView (org.lucasr.smoothie.AsyncListView)2 Context (android.content.Context)1 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 Location (android.location.Location)1