Search in sources :

Example 6 with TimelineArrayAdapter

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

the class ConversationFragment method getDiscussion.

public void getDiscussion(final ListView listView, final long tweetId, final LinearLayout progressBar, final HoloTextView none, final Status status) {
    Log.v("talon_replies", "getting discussion");
    if (replies.size() == 0) {
        replies.add(status);
    }
    Thread getReplies = new Thread(new Runnable() {

        @Override
        public void run() {
            if (!isRunning) {
                return;
            }
            ArrayList<twitter4j.Status> all = null;
            Twitter twitter = Utils.getTwitter(context, settings);
            try {
                Log.v("talon_replies", "looking for discussion");
                long id = status.getId();
                String screenname = status.getUser().getScreenName();
                query = new Query("@" + screenname + " since_id:" + id);
                Log.v("talon_replies", "query string: " + query.getQuery());
                try {
                    query.setCount(100);
                } catch (Throwable e) {
                    // enlarge buffer error?
                    query.setCount(30);
                }
                QueryResult result = twitter.search(query);
                Log.v("talon_replies", "result: " + result.getTweets().size());
                all = new ArrayList<twitter4j.Status>();
                do {
                    Log.v("talon_replies", "do loop repetition");
                    if (!isRunning) {
                        return;
                    }
                    List<Status> tweets = result.getTweets();
                    for (twitter4j.Status tweet : tweets) {
                        if (tweet.getInReplyToStatusId() == id) {
                            all.add(tweet);
                            Log.v("talon_replies", tweet.getText());
                        }
                    }
                    if (all.size() > 0) {
                        for (int i = all.size() - 1; i >= 0; i--) {
                            Log.v("talon_replies", "inserting into arraylist:" + all.get(i).getText());
                            replies.add(all.get(i));
                        }
                        all.clear();
                        ((Activity) context).runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                progressBar.setVisibility(View.GONE);
                                try {
                                    if (replies.size() > 0) {
                                        if (adapter == null || adapter.getCount() == 0) {
                                            adapter = new TimelineArrayAdapter(context, replies);
                                            listView.setAdapter(adapter);
                                            listView.setVisibility(View.VISIBLE);
                                        } else {
                                            Log.v("talon_replies", "notifying adapter change");
                                            adapter.notifyDataSetChanged();
                                        }
                                    } else {
                                        none.setVisibility(View.VISIBLE);
                                    }
                                } catch (Exception e) {
                                    // none and it got the null object
                                    e.printStackTrace();
                                    listView.setVisibility(View.GONE);
                                    none.setVisibility(View.VISIBLE);
                                }
                            }
                        });
                    }
                    try {
                        Thread.sleep(250);
                    } catch (Exception e) {
                    // since we are changing the arraylist for the adapter in the background, we need to make sure it
                    // gets updated before continuing
                    }
                    query = result.nextQuery();
                    if (query != null)
                        result = twitter.search(query);
                } while (query != null);
            } catch (Exception e) {
                e.printStackTrace();
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
            }
            if (replies.size() < 2) {
                // nothing to show, so tell them that
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        progressBar.setVisibility(View.GONE);
                        listView.setVisibility(View.GONE);
                        none.setVisibility(View.VISIBLE);
                    }
                });
            }
        }
    });
    getReplies.setPriority(8);
    getReplies.start();
}
Also used : Status(twitter4j.Status) Query(twitter4j.Query) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) TwitterException(twitter4j.TwitterException) QueryResult(twitter4j.QueryResult) ArrayList(java.util.ArrayList) List(java.util.List) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter)

Example 7 with TimelineArrayAdapter

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

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

the class TwitterSearchFragment method doSearch.

public void doSearch(final String mQuery) {
    spinner.setVisibility(View.VISIBLE);
    if (listView.getVisibility() != View.GONE) {
        listView.setVisibility(View.GONE);
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                Log.v("talon_searching", "query in frag: " + mQuery);
                query = new Query(mQuery);
                if (topTweets) {
                    query.setResultType(Query.ResultType.popular);
                } else {
                    query.setResultType(null);
                }
                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, onlyStatus);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

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

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
            }
        }
    }).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)

Example 9 with TimelineArrayAdapter

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

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

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