Search in sources :

Example 1 with ResponseList

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;
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Twitter(twitter4j.Twitter) SearchedTrendsActivity(com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity) SavedSearchesActivity(com.klinker.android.twitter.activities.drawer_activities.SavedSearchesActivity) Activity(android.app.Activity) Intent(android.content.Intent) View(android.view.View) SearchedTrendsActivity(com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity) ResponseList(twitter4j.ResponseList)

Aggregations

Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 View (android.view.View)1 SavedSearchesActivity (com.klinker.android.twitter.activities.drawer_activities.SavedSearchesActivity)1 SearchedTrendsActivity (com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity)1 ResponseList (twitter4j.ResponseList)1 Twitter (twitter4j.Twitter)1