Пример #1
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));
  }
Пример #2
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();
    }
  }
Пример #3
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));
  }
Пример #4
0
 private void setStyle(SpoilerRobotoTextView textView, String subreddit) {
   textView.setTextColor(textColor);
   textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
   textView.setTypeface(typeface);
   textView.setLinkTextColor(colorPreferences.getColor(subreddit));
 }