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;
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations