示例#1
0
  private void changeSubreddit(
      final ISubredditChangedListener subredditChangedListener, String subredditName) {
    if (subredditName.equals(DEFAULT_SUBREDDIT)) {
      subredditName = "";
    } else {
      subredditName = SUBREDDIT_PREFIX + subredditName;
    }

    LogMe.e("Subreddit selected: " + subredditName);
    subredditChangedListener.subredditChanged(subredditName);
  }
示例#2
0
  public void reloadSubreddits(final ISubredditChangedListener subredditChangedListener) {
    DownloadTask downloadTask =
        new DownloadTask(sessionManager) {
          @Override
          protected void onDownloadComplete(List<RedditPost> results) {
            LogMe.e("Downloaded " + results.size() + " subreddit categories");

            subredditList.clear();
            subredditList.add(DEFAULT_SUBREDDIT);
            for (RedditPost redditPost : results) {
              String subredditUrl = redditPost.getUrl().toString();
              if (subredditUrl.startsWith(SUBREDDIT_PREFIX)) {
                subredditUrl = subredditUrl.substring(3);
              }
              subredditList.add(subredditUrl);
            }

            progressBar.setVisibility(View.INVISIBLE);

            subredditSpinnerView.setOnItemSelectedListener(
                new OnItemSelectedListener() {
                  public void onItemSelected(
                      AdapterView<?> parent, View view, int position, long id) {
                    String subredditName = subredditList.get(position);
                    changeSubreddit(subredditChangedListener, subredditName);
                  }

                  public void onNothingSelected(AdapterView<?> parent) {
                    subredditSpinnerView.setSelection(0);
                  }
                });

            subredditSpinnerView.setOnLongClickListener(
                new OnLongClickListener() {
                  public boolean onLongClick(View view) {
                    final EditText editText = new EditText(SubredditController.this.activity);

                    new AlertDialog.Builder(SubredditController.this.activity)
                        //
                        .setTitle("Enter subreddit")
                        .setView(editText)
                        .setPositiveButton(
                            "Ok",
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton) {
                                String newSubreddit = editText.getText().toString();
                                addNewSubreddit(subredditChangedListener, newSubreddit);
                              }
                            })
                        .setNegativeButton(
                            "Cancel",
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton) {
                                // Do nothing.
                              }
                            })
                        .show();

                    return true;
                  }
                });

            subredditSpinnerView.setAdapter(createNewSubredditAdapter());
            subredditSpinnerView.setSelection(0);
          }
        };

    String subredditUrl = dataSourceUrl + REDDITS_URL;
    LogMe.e("Subreddits from: " + subredditUrl);
    downloadTask.execute(subredditUrl);
  }