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();
}
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);
}
}
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();
}
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();
}
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();
}
}
Aggregations