예제 #1
0
  private static void setViews(
      String rawHTML,
      String subredditName,
      SpoilerRobotoTextView firstTextView,
      CommentOverflow commentOverflow) {
    if (rawHTML.isEmpty()) {
      return;
    }

    List<String> blocks = SubmissionParser.getBlocks(rawHTML);

    int startIndex = 0;
    // the <div class="md"> case is when the body contains a table or code block first
    if (!blocks.get(0).equals("<div class=\"md\">")) {
      firstTextView.setVisibility(View.VISIBLE);
      firstTextView.setTextHtml(blocks.get(0), subredditName);
      firstTextView.setLinkTextColor(
          new ColorPreferences(firstTextView.getContext()).getColor(subredditName));
      startIndex = 1;
    } else {
      firstTextView.setText("");
      firstTextView.setVisibility(View.GONE);
    }

    if (blocks.size() > 1) {
      if (startIndex == 0) {
        commentOverflow.setViews(blocks, subredditName);
      } else {
        commentOverflow.setViews(blocks.subList(startIndex, blocks.size()), subredditName);
      }
    } else {
      commentOverflow.removeAllViews();
    }
  }
예제 #2
0
  public void ParseTextWithLinksTextView(
      String rawHTML, final SpoilerRobotoTextView comm, final Activity c, final String subreddit) {
    if (rawHTML.isEmpty()) {
      return;
    }

    this.c = c;

    rawHTML =
        rawHTML
            .replace("&lt;", "<")
            .replace("&gt;", ">")
            .replace("&quot;", "\"")
            .replace("&apos;", "'")
            .replace("&amp;", "&")
            .replace("<li><p>", "<p>• ")
            .replace("</li>", "<br>")
            .replaceAll("<li.*?>", "• ")
            .replace("<p>", "<div>")
            .replace("</p>", "</div>")
            .replace("</del>", "</strike>")
            .replace("<del>", "<strike>");
    rawHTML = rawHTML.substring(15, rawHTML.lastIndexOf("<!-- SC_ON -->"));

    CharSequence sequence = convertHtmlToCharSequence(rawHTML);
    comm.setText(sequence);
    comm.setMovementMethod(new TextViewLinkHandler(c, subreddit, null));

    comm.setLinkTextColor(new ColorPreferences(c).getColor(subreddit));
  }
예제 #3
0
  public void setOrRemoveSpoilerSpans(
      SpoilerRobotoTextView commentView, Spannable text, int endOfLink) {
    // add 2 to end of link since there is a white space between the link text and the spoiler
    ForegroundColorSpan[] foregroundColors =
        text.getSpans(endOfLink + 2, endOfLink + 2, ForegroundColorSpan.class);

    if (foregroundColors.length > 0) {
      text.removeSpan(foregroundColors[0]);
      commentView.setText(text);
    } else {
      for (int i = 0; i < storedSpoilerStarts.size(); i++) {
        if (storedSpoilerStarts.get(i) < endOfLink + 2
            && storedSpoilerEnds.get(i) > endOfLink + 2) {
          text.setSpan(
              storedSpoilerSpans.get(i),
              storedSpoilerStarts.get(i),
              storedSpoilerEnds.get(i),
              Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        }
      }
      commentView.setText(text);
    }
  }
예제 #4
0
  public void ParseTextWithLinksTextViewComment(
      String rawHTML, final SpoilerRobotoTextView comm, final Activity c, final String subreddit) {
    if (rawHTML.isEmpty()) {
      return;
    }

    this.c = c;

    Typeface typeface =
        RobotoTypefaceManager.obtainTypeface(
            c, new FontPreferences(c).getFontTypeComment().getTypeface());
    comm.setTypeface(typeface);

    rawHTML =
        rawHTML
            .replace("&lt;", "<")
            .replace("&gt;", ">")
            .replace("&quot;", "\"")
            .replace("&apos;", "'")
            .replace("&amp;", "&")
            .replace("<li><p>", "<p>• ")
            .replace("</li>", "<br>")
            .replaceAll("<li.*?>", "• ")
            .replace("<p>", "<div>")
            .replace("</p>", "</div>")
            .replace("</del>", "</strike>")
            .replace("<del>", "<strike>");
    if (rawHTML.contains("\n")) {
      rawHTML = rawHTML.substring(0, rawHTML.lastIndexOf("\n"));
    }

    final CharSequence sequence = convertHtmlToCharSequence(rawHTML);
    comm.setText(sequence, TextView.BufferType.SPANNABLE);

    comm.setMovementMethod(new TextViewLinkHandler(c, subreddit, sequence));
    comm.setLinkTextColor(new ColorPreferences(c).getColor(subreddit));
  }