Search in sources :

Example 1 with Comment

use of forpdateam.ru.forpda.api.news.models.Comment in project ForPDA by RadiationX.

the class NewsApi method parseComments.

public Comment parseComments(final SparseArray<Comment.Karma> karmaMap, String source) {
    long time = System.currentTimeMillis();
    Document document = Parser.parse(source);
    Comment comments = new Comment();
    recurseComments(karmaMap, document, comments, 0);
    return comments;
}
Also used : Comment(forpdateam.ru.forpda.api.news.models.Comment) Document(forpdateam.ru.forpda.api.regex.parser.Document)

Example 2 with Comment

use of forpdateam.ru.forpda.api.news.models.Comment in project ForPDA by RadiationX.

the class ArticleCommentsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ArticleCommentsAdapter.ViewHolder holder, int position) {
    Comment item = list.get(position);
    Comment.Karma karma = item.getKarma();
    holder.content.setText(item.getContent());
    if (item.isDeleted()) {
        holder.itemView.setClickable(false);
        if (holder.likeImage.getVisibility() != View.GONE) {
            holder.likeImage.setVisibility(View.GONE);
        }
        if (holder.likeCount.getVisibility() != View.GONE) {
            holder.likeCount.setVisibility(View.GONE);
        }
        if (holder.nick.getVisibility() != View.GONE) {
            holder.nick.setVisibility(View.GONE);
        }
        if (holder.date.getVisibility() != View.GONE) {
            holder.date.setVisibility(View.GONE);
        }
    } else {
        holder.itemView.setClickable(ClientHelper.getAuthState());
        if (holder.likeImage.getVisibility() != View.VISIBLE) {
            holder.likeImage.setVisibility(View.VISIBLE);
        }
        if (holder.likeCount.getVisibility() != View.VISIBLE) {
            holder.likeCount.setVisibility(View.VISIBLE);
        }
        if (holder.nick.getVisibility() != View.VISIBLE) {
            holder.nick.setVisibility(View.VISIBLE);
        }
        if (holder.date.getVisibility() != View.VISIBLE) {
            holder.date.setVisibility(View.VISIBLE);
        }
        holder.nick.setText(item.getUserNick());
        holder.date.setText(item.getDate());
        if (karma.getCount() == 0) {
            if (holder.likeCount.getVisibility() != View.GONE) {
                holder.likeCount.setVisibility(View.GONE);
            }
        } else {
            if (holder.likeCount.getVisibility() != View.VISIBLE) {
                holder.likeCount.setVisibility(View.VISIBLE);
            }
            holder.likeCount.setText(Integer.toString(karma.getCount()));
        }
        switch(karma.getStatus()) {
            case Comment.Karma.LIKED:
                {
                    holder.likeImage.setImageDrawable(holder.heart);
                    holder.likeImage.setColorFilter(likedColorFilter);
                    holder.likeImage.setClickable(false);
                    break;
                }
            case Comment.Karma.DISLIKED:
                {
                    holder.likeImage.setImageDrawable(holder.heart_outline);
                    holder.likeImage.setColorFilter(dislikedColorFilter);
                    holder.likeImage.setClickable(false);
                    break;
                }
            case Comment.Karma.NOT_LIKED:
                {
                    holder.likeImage.setImageDrawable(holder.heart_outline);
                    holder.likeImage.clearColorFilter();
                    holder.likeImage.setClickable(ClientHelper.getAuthState() && ClientHelper.getUserId() != item.getUserId());
                    break;
                }
        }
    }
    holder.itemView.setPadding(App.px12 * item.getLevel(), 0, 0, 0);
}
Also used : Comment(forpdateam.ru.forpda.api.news.models.Comment)

Example 3 with Comment

use of forpdateam.ru.forpda.api.news.models.Comment in project ForPDA by RadiationX.

the class NewsApi method updateComments.

public Comment updateComments(DetailsPage article, DetailsPage newArticle) {
    article.getKarmaMap().clear();
    article.setKarmaMap(newArticle.getKarmaMap());
    article.setCommentsSource(newArticle.getCommentsSource());
    article.setCommentsCount(newArticle.getCommentsCount());
    Comment newComments = parseComments(article.getKarmaMap(), newArticle.getCommentsSource());
    article.setCommentTree(newComments);
    return newComments;
}
Also used : Comment(forpdateam.ru.forpda.api.news.models.Comment)

Example 4 with Comment

use of forpdateam.ru.forpda.api.news.models.Comment in project ForPDA by RadiationX.

the class NewsApi method recurseComments.

private Comment recurseComments(final SparseArray<Comment.Karma> karmaMap, Node root, Comment parentComment, int level) {
    Node rootComments = Parser.findNode(root, "ul", "class", "comment-list");
    ArrayList<Node> commentNodes = Parser.findChildNodes(rootComments, "li", null, null);
    /*if (commentNodes.size() == 0) {
            return null;
        }*/
    for (Node commentNode : commentNodes) {
        Comment comment = new Comment();
        String id = null, userId = null, userNick = null, date = null, content = null;
        Matcher matcher;
        Node anchorNode = Parser.findNode(commentNode, "div", "id", "comment-");
        if (anchorNode == null) {
            continue;
        }
        id = anchorNode.getAttribute("id");
        if (id != null) {
            matcher = idPattern.matcher(id);
            if (matcher.find()) {
                id = matcher.group(1);
                comment.setId(Integer.parseInt(id));
            }
        }
        String deletedString = anchorNode.getAttribute("class");
        boolean isDeleted = deletedString != null && deletedString.contains("deleted");
        comment.setDeleted(isDeleted);
        if (!isDeleted) {
            Node nickNode = Parser.findNode(commentNode, "a", "class", "nickname");
            Node metaNode = Parser.findNode(commentNode, "span", "class", "h-meta");
            userId = nickNode.getAttribute("href");
            if (userId != null) {
                matcher = userIdPattern.matcher(userId);
                if (matcher.find()) {
                    userId = matcher.group(1);
                    comment.setUserId(Integer.parseInt(userId));
                }
            }
            userNick = Parser.getHtml(nickNode, true);
            comment.setUserNick(ApiUtils.fromHtml(userNick));
            date = Parser.ownText(metaNode).trim();
            date = date.replace(" |", ",");
            comment.setDate(date);
        }
        Node contentNode = Parser.findNode(commentNode, "p", "class", "content");
        content = Parser.getHtml(contentNode, true);
        comment.setContent(ApiUtils.fromHtml(content));
        comment.setLevel(level);
        comment.setKarma(karmaMap.get(comment.getId()));
        parentComment.addChild(comment);
        level++;
        recurseComments(karmaMap, commentNode, comment, level);
        level--;
    }
    return parentComment;
}
Also used : Comment(forpdateam.ru.forpda.api.news.models.Comment) Matcher(java.util.regex.Matcher) Node(forpdateam.ru.forpda.api.regex.parser.Node)

Example 5 with Comment

use of forpdateam.ru.forpda.api.news.models.Comment in project ForPDA by RadiationX.

the class NewsApi method recurseCommentsToList.

public void recurseCommentsToList(ArrayList<Comment> comments, Comment comment) {
    for (Comment child : comment.getChildren()) {
        comments.add(new Comment(child));
        recurseCommentsToList(comments, child);
    }
}
Also used : Comment(forpdateam.ru.forpda.api.news.models.Comment)

Aggregations

Comment (forpdateam.ru.forpda.api.news.models.Comment)6 Context (android.content.Context)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatImageButton (android.support.v7.widget.AppCompatImageButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Editable (android.text.Editable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 ProgressBar (android.widget.ProgressBar)1 RelativeLayout (android.widget.RelativeLayout)1 App (forpdateam.ru.forpda.App)1