Search in sources :

Example 1 with HashtagDataSource

use of com.klinker.android.twitter.data.sq_lite.HashtagDataSource 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 2 with HashtagDataSource

use of com.klinker.android.twitter.data.sq_lite.HashtagDataSource in project Talon-for-Twitter by klinker24.

the class SearchedTrendsActivity method handleIntent.

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        searchQuery = intent.getStringExtra(SearchManager.QUERY);
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
        if (searchQuery.contains("#")) {
            suggestions.saveRecentQuery(searchQuery.replaceAll("\"", ""), null);
        } else {
            suggestions.saveRecentQuery(searchQuery, null);
        }
        if (searchQuery.contains("#")) {
            // we want to add it to the userAutoComplete
            HashtagDataSource source = HashtagDataSource.getInstance(context);
            if (source != null) {
                source.deleteTag(searchQuery.replaceAll("\"", ""));
                source.createTag(searchQuery.replaceAll("\"", ""));
            }
        }
        if (!searchQuery.contains("-RT")) {
            searchQuery += " -RT";
        }
        String query = searchQuery;
        doSearch(query);
    }
}
Also used : HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) SearchRecentSuggestions(android.provider.SearchRecentSuggestions)

Example 3 with HashtagDataSource

use of com.klinker.android.twitter.data.sq_lite.HashtagDataSource 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 4 with HashtagDataSource

use of com.klinker.android.twitter.data.sq_lite.HashtagDataSource 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)

Example 5 with HashtagDataSource

use of com.klinker.android.twitter.data.sq_lite.HashtagDataSource in project Talon-for-Twitter by klinker24.

the class TweetPager method getFromIntent.

public void getFromIntent() {
    Intent from = getIntent();
    name = from.getStringExtra("name");
    screenName = from.getStringExtra("screenname");
    tweet = from.getStringExtra("tweet");
    time = from.getLongExtra("time", 0);
    retweeter = from.getStringExtra("retweeter");
    webpage = from.getStringExtra("webpage");
    tweetId = from.getLongExtra("tweetid", 0);
    picture = from.getBooleanExtra("picture", false);
    proPic = from.getStringExtra("proPic");
    secondAcc = from.getBooleanExtra("second_account", false);
    animatedGif = from.getStringExtra("animated_gif");
    try {
        users = from.getStringExtra("users").split("  ");
    } catch (Exception e) {
        users = null;
    }
    try {
        hashtags = from.getStringExtra("hashtags").split("  ");
    } catch (Exception e) {
        hashtags = null;
    }
    try {
        linkString = from.getStringExtra("other_links");
        otherLinks = linkString.split("  ");
    } catch (Exception e) {
        otherLinks = null;
    }
    if (screenName.equals(settings.myScreenName)) {
        isMyTweet = true;
    } else if (screenName.equals(retweeter)) {
        isMyRetweet = true;
    }
    tweet = restoreLinks(tweet);
    if (hashtags != null) {
        // we will add them to the auto complete
        new Thread(new Runnable() {

            @Override
            public void run() {
                ArrayList<String> tags = new ArrayList<String>();
                if (hashtags != null) {
                    for (String s : hashtags) {
                        if (!s.equals("")) {
                            tags.add("#" + s);
                        }
                    }
                }
                HashtagDataSource source = HashtagDataSource.getInstance(context);
                for (String s : tags) {
                    Log.v("talon_hashtag", "trend: " + s);
                    if (s.contains("#")) {
                        // we want to add it to the auto complete
                        Log.v("talon_hashtag", "adding: " + s);
                        source.deleteTag(s);
                        source.createTag(s);
                    }
                }
            }
        }).start();
    }
}
Also used : HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent)

Aggregations

HashtagDataSource (com.klinker.android.twitter.data.sq_lite.HashtagDataSource)6 ArrayList (java.util.ArrayList)4 TrendsArrayAdapter (com.klinker.android.twitter.adapters.TrendsArrayAdapter)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 PendingIntent (android.app.PendingIntent)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Location (android.location.Location)1 SearchRecentSuggestions (android.provider.SearchRecentSuggestions)1 ActivityDataSource (com.klinker.android.twitter.data.sq_lite.ActivityDataSource)1 DMDataSource (com.klinker.android.twitter.data.sq_lite.DMDataSource)1 FavoriteTweetsDataSource (com.klinker.android.twitter.data.sq_lite.FavoriteTweetsDataSource)1 HomeDataSource (com.klinker.android.twitter.data.sq_lite.HomeDataSource)1 InteractionsDataSource (com.klinker.android.twitter.data.sq_lite.InteractionsDataSource)1 ListDataSource (com.klinker.android.twitter.data.sq_lite.ListDataSource)1 MentionsDataSource (com.klinker.android.twitter.data.sq_lite.MentionsDataSource)1