use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class ProfileFragment method getFollowing.
public void getFollowing(final User user, final AsyncListView listView) {
spinner.setVisibility(View.VISIBLE);
canRefresh = false;
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
PagableResponseList<User> friendsPaging;
try {
friendsPaging = twitter.getFriendsList(user.getId(), currentFollowing, 100);
} catch (OutOfMemoryError e) {
return;
}
for (int i = 0; i < friendsPaging.size(); i++) {
following.add(friendsPaging.get(i));
Log.v("friends_list", friendsPaging.get(i).getName());
}
if (friendsPaging.size() > 17) {
hasMore = true;
} else {
hasMore = false;
}
currentFollowing = friendsPaging.getNextCursor();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (followingAdapter == null) {
followingAdapter = new PeopleArrayAdapter(context, following);
listView.setAdapter(followingAdapter);
} else {
followingAdapter.notifyDataSetChanged();
}
if (settings.roundContactImages) {
ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96);
} else {
ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache);
}
String url = user.getProfileBannerURL();
ImageUtils.loadImage(context, background, url, mCache);
canRefresh = true;
spinner.setVisibility(View.GONE);
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (user != null && user.isProtected()) {
Toast.makeText(context, getResources().getString(R.string.protected_account), Toast.LENGTH_SHORT).show();
if (settings.roundContactImages) {
ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96);
} else {
ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(), mCache);
}
String url = user.getProfileBannerURL();
ImageUtils.loadImage(context, background, url, mCache);
} else {
Toast.makeText(context, getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show();
}
spinner.setVisibility(View.GONE);
} catch (Exception e) {
// fragment not attached
}
canRefresh = false;
hasMore = false;
}
});
}
}
}).start();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class ProfileMentionsFragment method getMore.
public void getMore() {
canRefresh = false;
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
QueryResult result = twitter.search(query);
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() {
adapter.notifyDataSetChanged();
canRefresh = true;
if (!hasMore) {
View footer = inflater.inflate(R.layout.mentions_footer, null);
listView.addFooterView(footer);
listView.setFooterDividersEnabled(false);
}
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
canRefresh = false;
hasMore = false;
}
});
}
}
}).start();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class ProfilePicturesFragment method getMore.
public void getMore() {
canRefresh = false;
spinner.setVisibility(View.VISIBLE);
if (destroyed) {
hasMore = false;
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
paging.setPage(paging.getPage() + 1);
ResponseList<Status> result = twitter.getUserTimeline(screenName, paging);
tweets.clear();
for (Status status : result) {
tweets.add(status);
}
if (result.size() > 17) {
hasMore = true;
} else {
hasMore = false;
}
boolean update = false;
for (Status s : tweets) {
String[] links = TweetLinkUtils.getLinksInStatus(s);
if (!links[1].equals("")) {
pics.add(links[1]);
tweetsWithPics.add(s);
update = true;
}
}
if (update) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
canRefresh = true;
spinner.setVisibility(View.GONE);
}
});
} else {
canRefresh = true;
}
try {
Thread.sleep(250);
} catch (Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
canRefresh = false;
hasMore = false;
try {
adapter.notifyDataSetChanged();
} catch (Exception e) {
}
spinner.setVisibility(View.GONE);
}
});
}
}
}).start();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class ConversationFragment method getDiscussion.
public void getDiscussion(final ListView listView, final long tweetId, final LinearLayout progressBar, final HoloTextView none, final Status status) {
Log.v("talon_replies", "getting discussion");
if (replies.size() == 0) {
replies.add(status);
}
Thread getReplies = new Thread(new Runnable() {
@Override
public void run() {
if (!isRunning) {
return;
}
ArrayList<twitter4j.Status> all = null;
Twitter twitter = Utils.getTwitter(context, settings);
try {
Log.v("talon_replies", "looking for discussion");
long id = status.getId();
String screenname = status.getUser().getScreenName();
query = new Query("@" + screenname + " since_id:" + id);
Log.v("talon_replies", "query string: " + query.getQuery());
try {
query.setCount(100);
} catch (Throwable e) {
// enlarge buffer error?
query.setCount(30);
}
QueryResult result = twitter.search(query);
Log.v("talon_replies", "result: " + result.getTweets().size());
all = new ArrayList<twitter4j.Status>();
do {
Log.v("talon_replies", "do loop repetition");
if (!isRunning) {
return;
}
List<Status> tweets = result.getTweets();
for (twitter4j.Status tweet : tweets) {
if (tweet.getInReplyToStatusId() == id) {
all.add(tweet);
Log.v("talon_replies", tweet.getText());
}
}
if (all.size() > 0) {
for (int i = all.size() - 1; i >= 0; i--) {
Log.v("talon_replies", "inserting into arraylist:" + all.get(i).getText());
replies.add(all.get(i));
}
all.clear();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.GONE);
try {
if (replies.size() > 0) {
if (adapter == null || adapter.getCount() == 0) {
adapter = new TimelineArrayAdapter(context, replies);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
} else {
Log.v("talon_replies", "notifying adapter change");
adapter.notifyDataSetChanged();
}
} else {
none.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
// none and it got the null object
e.printStackTrace();
listView.setVisibility(View.GONE);
none.setVisibility(View.VISIBLE);
}
}
});
}
try {
Thread.sleep(250);
} catch (Exception e) {
// since we are changing the arraylist for the adapter in the background, we need to make sure it
// gets updated before continuing
}
query = result.nextQuery();
if (query != null)
result = twitter.search(query);
} while (query != null);
} catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
if (replies.size() < 2) {
// nothing to show, so tell them that
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.GONE);
listView.setVisibility(View.GONE);
none.setVisibility(View.VISIBLE);
}
});
}
}
});
getReplies.setPriority(8);
getReplies.start();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class ConversationFragment method getReplies.
public void getReplies(final ListView listView, final long tweetId, final LinearLayout progressSpinner, final HoloTextView none) {
Thread getReplies = new Thread(new Runnable() {
@Override
public void run() {
if (!isRunning) {
return;
}
Twitter twitter = Utils.getTwitter(context, settings);
replies = new ArrayList<twitter4j.Status>();
try {
status = twitter.showStatus(tweetId);
if (status.isRetweet()) {
status = status.getRetweetedStatus();
}
twitter4j.Status replyStatus = twitter.showStatus(status.getInReplyToStatusId());
try {
while (!replyStatus.getText().equals("")) {
if (!isRunning) {
return;
}
replies.add(replyStatus);
Log.v("reply_status", replyStatus.getText());
replyStatus = twitter.showStatus(replyStatus.getInReplyToStatusId());
}
} catch (Exception e) {
// the list of replies has ended, but we dont want to go to null
}
} catch (TwitterException e) {
e.printStackTrace();
}
if (status != null && replies.size() > 0) {
replies.add(0, status);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (replies.size() > 0) {
ArrayList<twitter4j.Status> reversed = new ArrayList<twitter4j.Status>();
for (int i = replies.size() - 1; i >= 0; i--) {
reversed.add(replies.get(i));
}
replies = reversed;
adapter = new TimelineArrayAdapter(context, replies);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
progressSpinner.setVisibility(View.GONE);
} else {
}
} catch (Exception e) {
// none and it got the null object
}
if (status != null) {
// everything here worked, so get the discussion on the tweet
getDiscussion(listView, tweetId, progressSpinner, none, status);
}
}
});
}
});
getReplies.setPriority(7);
getReplies.start();
}
Aggregations