use of twitter4j.ResponseList in project Talon-for-Twitter by klinker24.
the class SavedSearchArrayAdapter method bindView.
@Override
public void bindView(final View view, Context mContext, final String trend) {
final ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(trend);
holder.text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent search = new Intent(context, SearchedTrendsActivity.class);
search.setAction(Intent.ACTION_SEARCH);
search.putExtra(SearchManager.QUERY, trend);
context.startActivity(search);
}
});
holder.text.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final String search = trend;
new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.delete_saved_search)).setMessage(context.getResources().getString(R.string.cache_dialog_summary)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(context, context.getString(R.string.deleting_search), Toast.LENGTH_SHORT).show();
new Thread(new Runnable() {
@Override
public void run() {
long id = -1;
Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context));
try {
ResponseList<SavedSearch> searches = twitter.savedSearches().getSavedSearches();
for (int i = 0; i < searches.size(); i++) {
String name = searches.get(i).getName();
Log.v("talon_saved_searches", name);
if (name.equals(search)) {
id = searches.get(i).getId();
Log.v("talon_saved_searches", "id to delete: " + id);
}
}
if (id != -1) {
twitter.destroySavedSearch(id);
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, context.getString(R.string.success), Toast.LENGTH_SHORT).show();
SavedSearchesActivity.getSearches();
}
});
} else {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, context.getString(R.string.error), Toast.LENGTH_SHORT).show();
}
});
}
} catch (Exception e) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, context.getString(R.string.error), Toast.LENGTH_SHORT).show();
}
});
}
}
}).start();
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}).create().show();
return false;
}
});
}
Aggregations