Search in sources :

Example 76 with Twitter

use of twitter4j.Twitter 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)

Example 77 with Twitter

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

the class ProfileFragment method getTimeline.

public void getTimeline(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);
                List<twitter4j.Status> statuses = twitter.getUserTimeline(user.getId(), timelinePaging);
                timelinePaging.setPage(timelinePaging.getPage() + 1);
                for (twitter4j.Status s : statuses) {
                    timelineStatuses.add(s);
                }
                if (statuses.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (timelineAdapter != null) {
                            timelineAdapter.notifyDataSetChanged();
                        } else {
                            timelineAdapter = new TimelineArrayAdapter(context, timelineStatuses, screenName);
                            listView.setItemManager(builder.build());
                            listView.setAdapter(timelineAdapter);
                        }
                        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);
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                    }
                });
            } 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) {
                        // not attached
                        }
                        canRefresh = false;
                        hasMore = false;
                    }
                });
            } catch (OutOfMemoryError x) {
                x.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Toast.makeText(context, context.getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show();
                            spinner.setVisibility(View.GONE);
                        } catch (Exception e) {
                        // not attached
                        }
                        canRefresh = false;
                        hasMore = false;
                    }
                });
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) PhotoViewerActivity(com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity) Activity(android.app.Activity) Status(twitter4j.Status) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter)

Example 78 with Twitter

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

the class ProfileFavoritesFragment method getMore.

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

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

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

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

Example 79 with Twitter

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

the class ProfileFavoritesFragment 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.getFavorites(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;
                }
                ((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;
                    }
                });
            } 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) Status(twitter4j.Status) Twitter(twitter4j.Twitter) Activity(android.app.Activity) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter)

Example 80 with Twitter

use of twitter4j.Twitter 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

Twitter (twitter4j.Twitter)127 TwitterException (twitter4j.TwitterException)76 TwitterFactory (twitter4j.TwitterFactory)60 Status (twitter4j.Status)44 Activity (android.app.Activity)35 QueryResult (twitter4j.QueryResult)17 TimelineArrayAdapter (com.klinker.android.twitter.adapters.TimelineArrayAdapter)16 Intent (android.content.Intent)13 ArrayList (java.util.ArrayList)13 User (twitter4j.User)12 Query (twitter4j.Query)11 IDs (twitter4j.IDs)8 LinearLayout (android.widget.LinearLayout)7 IOException (java.io.IOException)7 Context (android.content.Context)6 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)6 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)5 GeoLocation (twitter4j.GeoLocation)5 Paging (twitter4j.Paging)5