Search in sources :

Example 1 with TrendsArrayAdapter

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

the class TrendsFragment method getCursorAdapter.

@Override
public void getCursorAdapter(boolean showSpinner) {
    if (showSpinner) {
        listView.setVisibility(View.GONE);
        spinner.setVisibility(View.VISIBLE);
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            Trends trends = getTrends();
            if (trends == null) {
                try {
                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            listView.setVisibility(View.GONE);
                            spinner.setVisibility(View.GONE);
                        }
                    });
                } catch (Exception e) {
                }
                return;
            }
            final ArrayList<String> currentTrends = new ArrayList<String>();
            for (Trend t : trends.getTrends()) {
                String name = t.getName();
                currentTrends.add(name);
            }
            try {
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            if (currentTrends != null) {
                                listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                                listView.setVisibility(View.VISIBLE);
                            }
                            spinner.setVisibility(View.GONE);
                            refreshLayout.setRefreshing(false);
                        } catch (Exception e) {
                        // not attached to activity
                        }
                    }
                });
            } catch (Exception e) {
            }
            HashtagDataSource source = HashtagDataSource.getInstance(context);
            for (String s : currentTrends) {
                Log.v("talon_hashtag", "trend: " + s);
                if (s.contains("#")) {
                    // we want to add it to the auto complete
                    Log.v("talon_hashtag", "adding: " + s);
                    // could be much more efficient by querying and checking first, but I
                    // just didn't feel like it when there is only ever 10 of them here
                    source.deleteTag(s);
                    // add it to the userAutoComplete database
                    source.createTag(s);
                }
            }
        }
    }).start();
}
Also used : TrendsArrayAdapter(com.klinker.android.twitter.adapters.TrendsArrayAdapter) HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) ArrayList(java.util.ArrayList) Trend(twitter4j.Trend) Trends(twitter4j.Trends)

Example 2 with TrendsArrayAdapter

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

the class LocalTrends method getTrends.

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

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);
                int i = 0;
                while (!connected && i < 5) {
                    try {
                        Thread.sleep(1500);
                    } catch (Exception e) {
                    }
                    i++;
                }
                twitter4j.Trends trends;
                if (sharedPrefs.getBoolean("manually_config_location", false)) {
                    // chicago to default
                    trends = twitter.getPlaceTrends(sharedPrefs.getInt("woeid", 2379574));
                } else {
                    Location location = mLastLocation;
                    ResponseList<twitter4j.Location> locations = twitter.getClosestTrends(new GeoLocation(location.getLatitude(), location.getLongitude()));
                    trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
                }
                final ArrayList<String> currentTrends = new ArrayList<String>();
                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            if (currentTrends != null) {
                                listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                Toast.makeText(context, getResources().getString(R.string.no_location), Toast.LENGTH_SHORT).show();
                            }
                            LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                            spinner.setVisibility(View.GONE);
                        } catch (Exception e) {
                        // not attached to activity
                        }
                    }
                });
                HashtagDataSource source = HashtagDataSource.getInstance(context);
                for (String s : currentTrends) {
                    Log.v("talon_hashtag", "trend: " + s);
                    if (s.contains("#")) {
                        // we want to add it to the auto complete
                        Log.v("talon_hashtag", "adding: " + s);
                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);
                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Toast.makeText(context, getResources().getString(R.string.no_location), Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                        // not attached to activity
                        }
                    }
                });
            }
        }
    }).start();
}
Also used : HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) ArrayList(java.util.ArrayList) Trend(twitter4j.Trend) Twitter(twitter4j.Twitter) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) Activity(android.app.Activity) TrendsArrayAdapter(com.klinker.android.twitter.adapters.TrendsArrayAdapter) GeoLocation(twitter4j.GeoLocation) LinearLayout(android.widget.LinearLayout) GeoLocation(twitter4j.GeoLocation) Location(android.location.Location)

Example 3 with TrendsArrayAdapter

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

the class WorldTrends method getTrends.

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

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                twitter4j.Trends trends = twitter.getPlaceTrends(1);
                final ArrayList<String> currentTrends = new ArrayList<String>();
                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (currentTrends != null) {
                            listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                        }
                        listView.setVisibility(View.VISIBLE);
                        LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                        spinner.setVisibility(View.GONE);
                    }
                });
                HashtagDataSource source = HashtagDataSource.getInstance(context);
                for (String s : currentTrends) {
                    if (s.contains("#")) {
                        // we want to add it to the userAutoComplete
                        Log.v("talon_hashtag", "adding: " + s);
                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);
                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) ArrayList(java.util.ArrayList) Trend(twitter4j.Trend) Twitter(twitter4j.Twitter) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) Activity(android.app.Activity) TrendsArrayAdapter(com.klinker.android.twitter.adapters.TrendsArrayAdapter) LinearLayout(android.widget.LinearLayout)

Aggregations

TrendsArrayAdapter (com.klinker.android.twitter.adapters.TrendsArrayAdapter)3 HashtagDataSource (com.klinker.android.twitter.data.sq_lite.HashtagDataSource)3 ArrayList (java.util.ArrayList)3 Trend (twitter4j.Trend)3 Activity (android.app.Activity)2 LinearLayout (android.widget.LinearLayout)2 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)2 Twitter (twitter4j.Twitter)2 Location (android.location.Location)1 GeoLocation (twitter4j.GeoLocation)1 Trends (twitter4j.Trends)1