Search in sources :

Example 1 with PicturesGridAdapter

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

the class ProfilePicturesFragment method doSearch.

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

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                ResponseList<Status> result;
                try {
                    result = twitter.getUserTimeline(screenName, paging);
                } catch (OutOfMemoryError e) {
                    return;
                }
                tweets.clear();
                for (twitter4j.Status status : result) {
                    tweets.add(status);
                }
                if (result.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }
                for (Status s : tweets) {
                    String[] links = TweetLinkUtils.getLinksInStatus(s);
                    if (!links[1].equals("")) {
                        pics.add(links[1]);
                        tweetsWithPics.add(s);
                    }
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
                        Point size = new Point();
                        display.getSize(size);
                        int width = size.x;
                        int numColumns;
                        int currentOrientation = getResources().getConfiguration().orientation;
                        if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
                            numColumns = 5;
                        } else {
                            numColumns = 3;
                        }
                        adapter = new PicturesGridAdapter(context, pics, tweetsWithPics, width / numColumns);
                        listView.setAdapter(adapter);
                        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);
                        canRefresh = false;
                    }
                });
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) PicturesGridAdapter(com.klinker.android.twitter.adapters.PicturesGridAdapter) Twitter(twitter4j.Twitter) Activity(android.app.Activity) Point(android.graphics.Point) Status(twitter4j.Status) Display(android.view.Display)

Aggregations

Activity (android.app.Activity)1 Point (android.graphics.Point)1 Display (android.view.Display)1 PicturesGridAdapter (com.klinker.android.twitter.adapters.PicturesGridAdapter)1 Status (twitter4j.Status)1 Twitter (twitter4j.Twitter)1