Example usage for twitter4j Twitter savedSearches

List of usage examples for twitter4j Twitter savedSearches

Introduction

In this page you can find the example usage for twitter4j Twitter savedSearches.

Prototype

SavedSearchesResources savedSearches();

Source Link

Usage

From source file:com.daiv.android.twitter.adapters.SavedSearchArrayAdapter.java

License:Apache License

@Override
public void bindView(final View view, Context mContext, final String trend) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    holder.text.setText(trend);/*from w ww . ja v a2 s  .co m*/

    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("Test_saved_searches", name);
                                            if (name.equals(search)) {
                                                id = searches.get(i).getId();
                                                Log.v("Test_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();
                                                }
                                            });
                                        } 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;
        }
    });

}

From source file:com.klinker.android.twitter.adapters.SavedSearchArrayAdapter.java

License:Apache License

@Override
public void bindView(final View view, Context mContext, final String trend) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    holder.text.setText(trend);/*from   w w w.j  a v  a  2 s.  co m*/

    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() {

                                    int 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;
        }
    });

}