use of twitter4j.QueryResult 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();
}
use of twitter4j.QueryResult in project Talon-for-Twitter by klinker24.
the class SavedSearchFragment method getMore.
public void getMore() {
if (hasMore) {
canRefresh = false;
refreshLayout.setRefreshing(true);
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;
}
try {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
refreshLayout.setRefreshing(false);
canRefresh = true;
}
});
} catch (Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
try {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
refreshLayout.setRefreshing(false);
canRefresh = true;
}
});
} catch (Exception x) {
}
}
}
}).start();
}
}
use of twitter4j.QueryResult in project Talon-for-Twitter by klinker24.
the class TwitterSearchFragment method doSearch.
public void doSearch(final String mQuery) {
spinner.setVisibility(View.VISIBLE);
if (listView.getVisibility() != View.GONE) {
listView.setVisibility(View.GONE);
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
Log.v("talon_searching", "query in frag: " + mQuery);
query = new Query(mQuery);
if (topTweets) {
query.setResultType(Query.ResultType.popular);
} else {
query.setResultType(null);
}
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() {
adapter = new TimelineArrayAdapter(context, tweets, onlyStatus);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
}
});
} catch (OutOfMemoryError e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
}
});
}
}
}).start();
}
use of twitter4j.QueryResult in project Talon-for-Twitter by klinker24.
the class TwitterSearchFragment method getMore.
public void getMore() {
if (hasMore) {
canRefresh = false;
mPullToRefreshLayout.setRefreshing(true);
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();
mPullToRefreshLayout.setRefreshing(false);
canRefresh = true;
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
mPullToRefreshLayout.setRefreshing(false);
canRefresh = true;
}
});
}
}
}).start();
}
}
use of twitter4j.QueryResult in project Talon-for-Twitter by klinker24.
the class ProfileMentionsFragment method doSearch.
public void doSearch() {
spinner.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
query = new Query("@" + screenName + " -RT");
query.sinceId(1);
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() {
adapter = new TimelineArrayAdapter(context, tweets);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
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() {
spinner.setVisibility(View.GONE);
canRefresh = false;
if (!hasMore) {
View footer = inflater.inflate(R.layout.mentions_footer, null);
listView.addFooterView(footer);
listView.setFooterDividersEnabled(false);
}
}
});
} catch (OutOfMemoryError e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
canRefresh = false;
if (!hasMore) {
View footer = inflater.inflate(R.layout.mentions_footer, null);
listView.addFooterView(footer);
listView.setFooterDividersEnabled(false);
}
}
});
}
}
}).start();
}
Aggregations