示例#1
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View rowView = inflater.inflate(rowResourceId, null);

      TextView author = (TextView) rowView.findViewById(R.id.submitter);
      TextView body = (TextView) rowView.findViewById(R.id.body);

      SavedContent sc = data.get(position);

      author.setText(sc.getAuthor());
      body.setText(createSpanned(sc.getBody()));

      return rowView;
    }
示例#2
0
  @Override
  protected void onPrepareDialog(int id, Dialog dialog) {
    super.onPrepareDialog(id, dialog);

    switch (id) {
      case Constants.DIALOG_SAVED_COMMENTS:
        final TextView author = (TextView) dialog.findViewById(R.id.submitter);
        final TextView body = (TextView) dialog.findViewById(R.id.body);

        author.setText(currentSavedContent.getAuthor());

        StringBuilder bodyText = new StringBuilder();
        String[] pieces = currentSavedContent.getBody().split("[\\r\\n]+");
        int charCount = 0;
        for (int i = 0; i < pieces.length && i < 9; i++) {
          if (charCount > 200) {
            break;
          }
          bodyText.append(pieces[i]);
          charCount += pieces[i].length();
        }
        body.setText(createSpanned(bodyText.toString().trim()));

        final Button viewComment = (Button) dialog.findViewById(R.id.view_saved_comment);
        final Button unsaveComment = (Button) dialog.findViewById(R.id.unsave_comment);
        final Button linkButton = (Button) dialog.findViewById(R.id.thread_link_button);
        viewComment.setEnabled(true);
        unsaveComment.setEnabled(true);

        ThingInfo ti = new ThingInfo();
        new Markdown().getURLs(currentSavedContent.getBody(), ti.getUrls());
        linkToEmbeddedURLs(linkButton, ti.getUrls());

        unsaveComment.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                sdbh.deleteSavedContent(currentSavedContent);
                removeDialog(Constants.DIALOG_SAVED_COMMENTS);
                relaunchActivity();
              }
            });

        viewComment.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                ThingInfo commentThing = new ThingInfo();
                commentThing.setLink_id(currentSavedContent.getLinkId());
                commentThing.setId(currentSavedContent.getCommentId());

                removeDialog(Constants.DIALOG_SAVED_COMMENTS);

                Intent i = new Intent(SavedCommentsActivity.this, CommentsListActivity.class);
                i.setData(Util.createCommentUriNoContext(commentThing));
                i.putExtra(Constants.EXTRA_SUBREDDIT, currentSavedContent.getSubreddit());
                startActivity(i);
              }
            });
        break;
      default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
  }