Search in sources :

Example 1 with FollowersArrayAdapter

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

the class ProfileFragment method getFollowers.

public void getFollowers(final User user, final AsyncListView listView) {
    spinner.setVisibility(View.VISIBLE);
    canRefresh = false;
    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, 100);
                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();
}
Also used : PeopleArrayAdapter(com.klinker.android.twitter.adapters.PeopleArrayAdapter) User(twitter4j.User) Twitter(twitter4j.Twitter) PhotoViewerActivity(com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity) Activity(android.app.Activity) FollowersArrayAdapter(com.klinker.android.twitter.adapters.FollowersArrayAdapter) IDs(twitter4j.IDs)

Aggregations

Activity (android.app.Activity)1 PhotoViewerActivity (com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity)1 FollowersArrayAdapter (com.klinker.android.twitter.adapters.FollowersArrayAdapter)1 PeopleArrayAdapter (com.klinker.android.twitter.adapters.PeopleArrayAdapter)1 IDs (twitter4j.IDs)1 Twitter (twitter4j.Twitter)1 User (twitter4j.User)1