Esempio n. 1
0
 public GetCommentsTask(UUID postId, String commentToSelectId) {
   post = (Post) ServerWorker.Instance().getPostById(postId);
   this.commentToSelectId = commentToSelectId;
   isImagesEnabled = Utils.isImagesEnabled();
 }
Esempio n. 2
0
 public GetCommentsTask(UUID postId) {
   post = (Post) ServerWorker.Instance().getPostById(postId);
   isImagesEnabled = Utils.isImagesEnabled();
 }
Esempio n. 3
0
  private void parseRecord(String record) throws ExecutionException, InterruptedException {
    Element root = Jsoup.parse(record).getElementsByTag("div").first();

    Comment comment = new Comment();

    if (root.className().contains("new")) comment.setNew(true);

    String commentId = root.id();
    comment.setLepraId(commentId);

    if (commentId.equals(commentToSelectId)) commentToSelect = commentsCount;

    Matcher level = patternLevel.matcher(root.className());
    if (level.find()) comment.setLevel(Short.valueOf(level.group(1)));

    Element element = root.getElementsByClass("c_body").first();
    if (element.className().contains("hidden")) return;

    boolean containsImages = false;
    Elements images = element.getElementsByTag("img");
    for (Element image : images) {
      String src = image.attr("src");
      if (isImagesEnabled && !TextUtils.isEmpty(src)) {
        if (!image.parent().tag().getName().equalsIgnoreCase("a"))
          image.wrap("<a href=" + "\"" + src + "\"></a>");

        image.removeAttr("width");
        image.removeAttr("height");
        image.removeAttr("style");

        image.attr("style", "max-width:100%");

        containsImages = true;
      } else image.remove();
    }

    String html = Utils.wrapLepraTags(element);
    comment.setHtml(html);
    comment.setOnlyText(!containsImages && !html.contains("leprosorium.ru"));

    Element authorElement = root.getElementsByClass("ddi").first();
    if (authorElement != null) {
      Elements a = authorElement.getElementsByTag("a");
      String url = Commons.PREFIX_URL + a.first().attr("href");
      url = url.replace("\n", "");
      comment.setUrl(url);

      String author = a.size() > 1 ? a.get(1).text() : a.get(0).text();
      if (postAuthor.equals(author)) comment.setPostAuthor(true);

      String color = "black";
      if (comment.isPostAuthor()) color = "red";
      else if (author.equals(userName)) color = "#3270FF";

      comment.setAuthor(author);

      String signature =
          authorElement.text().split(author)[0]
              + "<b><font color=\""
              + color
              + "\">"
              + author
              + "</font></b>";

      String epochDate =
          authorElement.getElementsByClass("js-date").first().attr("data-epoch_date");
      Date date = new Date(Long.valueOf(epochDate) * 1000);

      signature =
          signature
              + " "
              + date
                  .toLocaleString(); // DateUtils.getRelativeTimeSpanString(date.getTime(), new
                                     // Date().getTime(), DateUtils.FORMAT_ABBREV_RELATIVE);

      comment.setSignature(signature);
    }

    if (!post.isInbox()) {
      Element vote = root.getElementsByClass("vote").first();
      if (vote != null) {
        if (!vote.select(".vote_button.vote_button_plus.vote_voted").isEmpty())
          comment.setPlusVoted(true);
        else if (!vote.select(".vote_button.vote_button_minus.vote_voted").isEmpty())
          comment.setMinusVoted(true);

        Element rating = vote.getElementsByClass("vote_result").first();
        comment.setRating(Short.valueOf(rating.text()));
      }
    }

    comment.setNum(commentsCount);

    ServerWorker.Instance().addNewComment(post.getId(), comment);

    commentsCount++;

    if (commentToSelectId != null) {
      if (commentToSelect != -1 && commentsCount >= 50 + commentToSelect) {
        notifyAboutFirstCommentsUpdate();

        commentToSelectId = null;
        commentToSelect = -1;
      }
    } else {
      if (commentsCount == 50) {
        notifyAboutFirstCommentsUpdate();
      } else if (commentsCount != 0 && commentsCount % 100 == 0) {
        notifyAboutCommentsUpdate();
      }
    }
  }