use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.
the class NearbyTweets method getTweets.
public void getTweets() {
canRefresh = false;
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);
boolean manualLoc = sharedPrefs.getBoolean("manually_config_location", false);
int i = 0;
while (!connected && i < 5 && !manualLoc) {
try {
Thread.sleep(1500);
} catch (Exception e) {
}
i++;
}
double latitude = -1;
double longitude = -1;
if (manualLoc) {
// need to query yahoos api for the location...
double[] loc = getLocationFromYahoo(sharedPrefs.getInt("woeid", 2379574));
latitude = loc[0];
longitude = loc[1];
} else {
// set it from the location client
Location location = mLastLocation;
latitude = location.getLatitude();
longitude = location.getLongitude();
}
query = new Query();
query.setGeoCode(new GeoLocation(latitude, longitude), 10, Query.MILES);
QueryResult result = twitter.search(query);
if (result.hasNext()) {
hasMore = true;
query = result.nextQuery();
} else {
hasMore = false;
}
for (Status s : result.getTweets()) {
statuses.add(s);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
adapter = new TimelineArrayAdapter(context, statuses);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
spinner.setVisibility(View.GONE);
}
});
} catch (Throwable e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Toast.makeText(context, getString(R.string.error), Toast.LENGTH_SHORT).show();
} catch (IllegalStateException e) {
// not attached to activity
}
}
});
}
canRefresh = true;
}
}).start();
}
use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.
the class RetweetActivity method getRetweets.
public void getRetweets() {
if (!hasMore) {
return;
}
canRefresh = false;
final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
final ResponseList<twitter4j.Status> favs = twitter.getRetweetsOfMe(paging);
if (favs.size() < 17) {
hasMore = false;
}
paging.setPage(paging.getPage() + 1);
for (twitter4j.Status s : favs) {
statuses.add(s);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (adapter == null) {
if (statuses.size() > 0) {
adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.RETWEET);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
} else {
LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
try {
nothing.setVisibility(View.VISIBLE);
} catch (Exception e) {
}
listView.setVisibility(View.GONE);
}
} else {
adapter.notifyDataSetChanged();
}
spinner.setVisibility(View.GONE);
canRefresh = true;
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
canRefresh = false;
}
});
} catch (OutOfMemoryError e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
canRefresh = false;
}
});
}
}
}).start();
}
use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.
the class SearchedTrendsActivity 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);
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);
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();
}
use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.
the class FavoritesActivity method getFavorites.
public void getFavorites() {
if (!hasMore) {
return;
}
canRefresh = false;
final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
final ResponseList<twitter4j.Status> favs = twitter.getFavorites(paging);
if (favs.size() < 17) {
hasMore = false;
}
paging.setPage(paging.getPage() + 1);
for (twitter4j.Status s : favs) {
statuses.add(s);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (adapter == null) {
if (statuses.size() > 0) {
adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.FAVORITE);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
} else {
LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
nothing.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
hasMore = false;
}
} else {
adapter.notifyDataSetChanged();
}
spinner.setVisibility(View.GONE);
canRefresh = true;
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
canRefresh = false;
}
});
} catch (OutOfMemoryError e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
canRefresh = false;
}
});
}
}
}).start();
}
use of com.klinker.android.twitter.adapters.TimelineArrayAdapter in project Talon-for-Twitter by klinker24.
the class SavedSearchFragment 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() {
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(search);
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;
}
try {
((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);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
listView.setSelection(top);
spinner.setVisibility(View.GONE);
refreshLayout.setRefreshing(false);
}
});
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
try {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
refreshLayout.setRefreshing(false);
}
});
} catch (Exception x) {
e.printStackTrace();
}
}
}
}).start();
}
Aggregations