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