Search in sources :

Example 1 with PeopleArrayAdapter

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

the class PeopleSearch method getPeople.

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

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                ResponseList<User> usersResponse = twitter.getUserSuggestions(slug);
                users.clear();
                for (User i : usersResponse) {
                    users.add(i);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        adapter = new PeopleArrayAdapter(context, users);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : PeopleArrayAdapter(com.klinker.android.twitter.adapters.PeopleArrayAdapter) User(twitter4j.User) Twitter(twitter4j.Twitter) LoginActivity(com.klinker.android.twitter.activities.setup.LoginActivity) Activity(android.app.Activity)

Example 2 with PeopleArrayAdapter

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

the class ProfileFragment method getFollowing.

public void getFollowing(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);
                PagableResponseList<User> friendsPaging;
                try {
                    friendsPaging = twitter.getFriendsList(user.getId(), currentFollowing, 100);
                } catch (OutOfMemoryError e) {
                    return;
                }
                for (int i = 0; i < friendsPaging.size(); i++) {
                    following.add(friendsPaging.get(i));
                    Log.v("friends_list", friendsPaging.get(i).getName());
                }
                if (friendsPaging.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }
                currentFollowing = friendsPaging.getNextCursor();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (followingAdapter == null) {
                            followingAdapter = new PeopleArrayAdapter(context, following);
                            listView.setAdapter(followingAdapter);
                        } else {
                            followingAdapter.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() {
                        try {
                            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);
                        } catch (Exception e) {
                        // fragment not attached
                        }
                        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)

Example 3 with PeopleArrayAdapter

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

Example 4 with PeopleArrayAdapter

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

the class ProfileFragment method setUpUI.

public void setUpUI(boolean fromAddon, View listHeader, View layout) {
    TextView mstatement;
    TextView mscreenname;
    AsyncListView mlistView;
    ImageView mheader;
    if (fromAddon) {
        try {
            Resources res = context.getPackageManager().getResourcesForApplication(settings.addonThemePackage);
            spinner = (ProgressBar) listHeader.findViewById(res.getIdentifier("progress_bar", "id", settings.addonThemePackage));
            verified = (TextView) listHeader.findViewById(res.getIdentifier("verified_text", "id", settings.addonThemePackage));
            tweetsBtn = (Button) listHeader.findViewById(res.getIdentifier("tweets", "id", settings.addonThemePackage));
            followersBtn = (Button) listHeader.findViewById(res.getIdentifier("followers", "id", settings.addonThemePackage));
            followingBtn = (Button) listHeader.findViewById(res.getIdentifier("following", "id", settings.addonThemePackage));
            background = (ImageView) listHeader.findViewById(res.getIdentifier("background_image", "id", settings.addonThemePackage));
            profilePicture = (ImageView) listHeader.findViewById(res.getIdentifier("profile_pic", "id", settings.addonThemePackage));
            mstatement = (TextView) listHeader.findViewById(res.getIdentifier("user_statement", "id", settings.addonThemePackage));
            mscreenname = (TextView) listHeader.findViewById(res.getIdentifier("username", "id", settings.addonThemePackage));
            mlistView = (AsyncListView) layout.findViewById(R.id.listView);
            mheader = (ImageView) listHeader.findViewById(res.getIdentifier("background_image", "id", settings.addonThemePackage));
        } catch (Exception e) {
            spinner = (ProgressBar) listHeader.findViewById(R.id.progress_bar);
            verified = (TextView) listHeader.findViewById(R.id.verified_text);
            tweetsBtn = (Button) listHeader.findViewById(R.id.tweets);
            followersBtn = (Button) listHeader.findViewById(R.id.followers);
            followingBtn = (Button) listHeader.findViewById(R.id.following);
            background = (ImageView) listHeader.findViewById(R.id.background_image);
            profilePicture = (ImageView) listHeader.findViewById(R.id.profile_pic);
            mstatement = (TextView) listHeader.findViewById(R.id.user_statement);
            mscreenname = (TextView) listHeader.findViewById(R.id.username);
            mlistView = (AsyncListView) layout.findViewById(R.id.listView);
            mheader = (ImageView) listHeader.findViewById(R.id.background_image);
        }
    } else {
        spinner = (ProgressBar) listHeader.findViewById(R.id.progress_bar);
        verified = (TextView) listHeader.findViewById(R.id.verified_text);
        tweetsBtn = (Button) listHeader.findViewById(R.id.tweets);
        followersBtn = (Button) listHeader.findViewById(R.id.followers);
        followingBtn = (Button) listHeader.findViewById(R.id.following);
        background = (ImageView) listHeader.findViewById(R.id.background_image);
        profilePicture = (ImageView) listHeader.findViewById(R.id.profile_pic);
        mstatement = (TextView) listHeader.findViewById(R.id.user_statement);
        mscreenname = (TextView) listHeader.findViewById(R.id.username);
        mlistView = (AsyncListView) layout.findViewById(R.id.listView);
        mheader = (ImageView) listHeader.findViewById(R.id.background_image);
    }
    final TextView statement = mstatement;
    final TextView screenname = mscreenname;
    final AsyncListView listView = mlistView;
    final ImageView header = mheader;
    spinner.setVisibility(View.VISIBLE);
    statement.setTextSize(settings.textSize);
    screenname.setTextSize(settings.textSize + 1);
    getData(statement, listView);
    screenname.setText("@" + screenName);
    tweetsBtn.setText(getResources().getString(R.string.tweets));
    tweetsBtn.setTextSize(settings.textSize - 1);
    tweetsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (current != BTN_TWEET) {
                current = BTN_TWEET;
                currentFollowing = -1;
                currentFollowers = -1;
                hasMore = true;
                listView.setItemManager(builder.build());
                listView.setAdapter(timelineAdapter);
                getTimeline(thisUser, listView);
            }
        }
    });
    followersBtn.setText(getResources().getString(R.string.followers));
    followersBtn.setTextSize(settings.textSize - 1);
    followersBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (current != BTN_FOLLOWERS) {
                current = BTN_FOLLOWERS;
                hasMore = false;
                listView.setItemManager(null);
                listView.setAdapter(followersAdapter);
                getFollowers(thisUser, listView);
            }
        }
    });
    followingBtn.setText(getResources().getString(R.string.following));
    followingBtn.setTextSize(settings.textSize - 1);
    followingBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (current != BTN_FOLLOWING) {
                current = BTN_FOLLOWING;
                hasMore = false;
                listView.setItemManager(null);
                listView.setAdapter(new PeopleArrayAdapter(context, following));
                getFollowing(thisUser, listView);
            }
        }
    });
    background.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (spinner.getVisibility() == View.GONE && thisUser != null) {
                startActivity(new Intent(context, PhotoViewerActivity.class).putExtra("url", thisUser.getProfileBannerURL()));
            } else {
            // it isn't ready to be opened just yet
            }
        }
    });
    profilePicture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (spinner.getVisibility() == View.GONE) {
                try {
                    startActivity(new Intent(context, PhotoViewerActivity.class).putExtra("url", thisUser.getOriginalProfileImageURL()).putExtra("from_cache", false));
                } catch (Exception e) {
                // this user doesn't exist...
                }
            } else {
            // it isn't ready to be opened just yet
            }
        }
    });
    canRefresh = false;
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            final int lastItem = firstVisibleItem + visibleItemCount;
            if (lastItem == totalItemCount && hasMore) {
                // Last item is fully visible.
                if (current == BTN_FOLLOWING && canRefresh) {
                    getFollowing(thisUser, listView);
                } else if (current == BTN_FOLLOWERS && canRefresh) {
                    getFollowers(thisUser, listView);
                } else if (current == BTN_TWEET && canRefresh) {
                    getTimeline(thisUser, listView);
                }
                canRefresh = false;
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        canRefresh = true;
                    }
                }, 4000);
            }
            if (visibleItemCount == 0)
                return;
            if (firstVisibleItem != 0)
                return;
            if (settings.translateProfileHeader) {
                header.setTranslationY(-listView.getChildAt(0).getTop() / 2);
            }
        }
    });
}
Also used : PeopleArrayAdapter(com.klinker.android.twitter.adapters.PeopleArrayAdapter) AbsListView(android.widget.AbsListView) Handler(android.os.Handler) Intent(android.content.Intent) ImageView(android.widget.ImageView) AsyncListView(org.lucasr.smoothie.AsyncListView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) PhotoViewerActivity(com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity) Button(android.widget.Button) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) ProgressBar(android.widget.ProgressBar) AsyncListView(org.lucasr.smoothie.AsyncListView)

Example 5 with PeopleArrayAdapter

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

PeopleArrayAdapter (com.klinker.android.twitter.adapters.PeopleArrayAdapter)5 Activity (android.app.Activity)4 Twitter (twitter4j.Twitter)4 User (twitter4j.User)4 PhotoViewerActivity (com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity)3 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Handler (android.os.Handler)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)1 FollowersArrayAdapter (com.klinker.android.twitter.adapters.FollowersArrayAdapter)1 AsyncListView (org.lucasr.smoothie.AsyncListView)1 IDs (twitter4j.IDs)1