Search in sources :

Example 1 with TimelineArrayAdapter

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

the class SearchedTrendsActivity method doSearch.

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

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                Log.v("talon_search", "search query: " + mQuery);
                query = new Query();
                if (mQuery.contains(" TOP")) {
                    query.setResultType(Query.ResultType.popular);
                }
                query.setQuery(mQuery.replace(" TOP", ""));
                QueryResult result;
                try {
                    result = twitter.search(query);
                } catch (OutOfMemoryError e) {
                    return;
                }
                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);
                    }
                });
            } catch (Exception 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) ComposeActivity(com.klinker.android.twitter.activities.compose.ComposeActivity) SettingsActivity(com.klinker.android.twitter.settings.SettingsActivity) Activity(android.app.Activity) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) TwitterException(twitter4j.TwitterException)

Example 2 with TimelineArrayAdapter

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

the class ProfileFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    mCache = App.getInstance(context).getBitmapCache();
    settings = AppSettings.getInstance(context);
    screenName = getArguments().getString("screen_name");
    isMyProfile = settings.myScreenName.equals(screenName);
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    inflater = LayoutInflater.from(context);
    layout = inflater.inflate(R.layout.list_fragment, null);
    LinearLayout spin = (LinearLayout) layout.findViewById(R.id.spinner);
    spin.setVisibility(View.GONE);
    AsyncListView listView = (AsyncListView) layout.findViewById(R.id.listView);
    listView.setVisibility(View.VISIBLE);
    BitmapLruCache cache = App.getInstance(context).getBitmapCache();
    ArrayListLoader loader = new ArrayListLoader(cache, context);
    builder = new ItemManager.Builder(loader);
    builder.setPreloadItemsEnabled(true).setPreloadItemsCount(50);
    builder.setThreadPoolSize(4);
    listView.setItemManager(builder.build());
    View header;
    boolean fromAddon = false;
    if (!settings.addonTheme) {
        header = inflater.inflate(R.layout.user_profile_header, null);
    } else {
        try {
            Context viewContext = null;
            Resources res = context.getPackageManager().getResourcesForApplication(settings.addonThemePackage);
            try {
                viewContext = context.createPackageContext(settings.addonThemePackage, Context.CONTEXT_IGNORE_SECURITY);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (res != null && viewContext != null) {
                int id = res.getIdentifier("user_profile_header", "layout", settings.addonThemePackage);
                header = LayoutInflater.from(viewContext).inflate(res.getLayout(id), null);
                fromAddon = true;
            } else {
                header = inflater.inflate(R.layout.user_profile_header, null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            header = inflater.inflate(R.layout.user_profile_header, null);
        }
    }
    listView.addHeaderView(header);
    listView.setAdapter(new TimelineArrayAdapter(context, new ArrayList<Status>(0)));
    followers = new ArrayList<User>();
    following = new ArrayList<User>();
    setUpUI(fromAddon, header, layout);
    return layout;
}
Also used : Context(android.content.Context) User(twitter4j.User) ArrayListLoader(com.klinker.android.twitter.adapters.ArrayListLoader) ItemManager(org.lucasr.smoothie.ItemManager) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) AsyncListView(org.lucasr.smoothie.AsyncListView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache) PackageManager(android.content.pm.PackageManager) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout) AsyncListView(org.lucasr.smoothie.AsyncListView)

Example 3 with TimelineArrayAdapter

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

the class TwitterSearchFragment method findStatus.

public void findStatus(final long statusid) {
    listView.setVisibility(View.GONE);
    spinner.setVisibility(View.VISIBLE);
    hasMore = false;
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                Status status = twitter.showStatus(statusid);
                final ArrayList<Status> statuses = new ArrayList<Status>();
                statuses.add(status);
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        TimelineArrayAdapter adapter = new TimelineArrayAdapter(context, statuses, 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);
                    }
                });
                hasMore = false;
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) Activity(android.app.Activity) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter)

Example 4 with TimelineArrayAdapter

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

the class TwitterSearchFragment method onRefreshStarted.

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

        @Override
        public void run() {
            final long topId;
            if (tweets.size() > 0) {
                topId = tweets.get(0).getId();
            } else {
                topId = 0;
            }
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                query = new Query(searchQuery);
                if (topTweets) {
                    query.setResultType(Query.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() {
                        int top = 0;
                        for (int i = 0; i < tweets.size(); i++) {
                            if (tweets.get(i).getId() == topId) {
                                top = i;
                                break;
                            }
                        }
                        adapter = new TimelineArrayAdapter(context, tweets, onlyStatus);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        listView.setSelection(top);
                        spinner.setVisibility(View.GONE);
                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            }
        }
    }).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 5 with TimelineArrayAdapter

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

the class ConversationFragment method getReplies.

public void getReplies(final ListView listView, final long tweetId, final LinearLayout progressSpinner, final HoloTextView none) {
    Thread getReplies = new Thread(new Runnable() {

        @Override
        public void run() {
            if (!isRunning) {
                return;
            }
            Twitter twitter = Utils.getTwitter(context, settings);
            replies = new ArrayList<twitter4j.Status>();
            try {
                status = twitter.showStatus(tweetId);
                if (status.isRetweet()) {
                    status = status.getRetweetedStatus();
                }
                twitter4j.Status replyStatus = twitter.showStatus(status.getInReplyToStatusId());
                try {
                    while (!replyStatus.getText().equals("")) {
                        if (!isRunning) {
                            return;
                        }
                        replies.add(replyStatus);
                        Log.v("reply_status", replyStatus.getText());
                        replyStatus = twitter.showStatus(replyStatus.getInReplyToStatusId());
                    }
                } catch (Exception e) {
                // the list of replies has ended, but we dont want to go to null
                }
            } catch (TwitterException e) {
                e.printStackTrace();
            }
            if (status != null && replies.size() > 0) {
                replies.add(0, status);
            }
            ((Activity) context).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        if (replies.size() > 0) {
                            ArrayList<twitter4j.Status> reversed = new ArrayList<twitter4j.Status>();
                            for (int i = replies.size() - 1; i >= 0; i--) {
                                reversed.add(replies.get(i));
                            }
                            replies = reversed;
                            adapter = new TimelineArrayAdapter(context, replies);
                            listView.setAdapter(adapter);
                            listView.setVisibility(View.VISIBLE);
                            progressSpinner.setVisibility(View.GONE);
                        } else {
                        }
                    } catch (Exception e) {
                    // none and it got the null object
                    }
                    if (status != null) {
                        // everything here worked, so get the discussion on the tweet
                        getDiscussion(listView, tweetId, progressSpinner, none, status);
                    }
                }
            });
        }
    });
    getReplies.setPriority(7);
    getReplies.start();
}
Also used : Status(twitter4j.Status) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) TwitterException(twitter4j.TwitterException) TwitterException(twitter4j.TwitterException)

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