use of org.mazhuang.guanggoo.data.entity.Comment in project guanggoo-android by mzlogin.
the class GetCommentsTask method run.
@Override
public void run() {
try {
Document doc = get(mUrl);
Map<Integer, Comment> comments = getCommentsFromElements(doc.select("div.topic-reply"));
successOnUI(comments);
} catch (IOException e) {
e.printStackTrace();
failedOnUI(e.getMessage());
}
}
use of org.mazhuang.guanggoo.data.entity.Comment in project guanggoo-android by mzlogin.
the class GetTopicDetailTask method run.
@Override
public void run() {
Document doc;
try {
doc = get(mUrl);
} catch (IOException e) {
e.printStackTrace();
failedOnUI(e.getMessage());
return;
}
Elements topicDetailElements = doc.select("div.topic-detail");
if (topicDetailElements.isEmpty()) {
failedOnUI("找不到主题详情");
return;
}
Elements elements = topicDetailElements.select("div.ui-header");
if (elements.isEmpty()) {
failedOnUI("找不到主题元信息");
return;
}
TopicDetail topicDetail = new TopicDetail();
Topic topic = GetTopicListTask.createTopicFromElement(elements.first());
topicDetail.setTopic(topic);
// 解析收藏
Favorite favorite = new Favorite();
Elements favouriteElement = doc.select(".J_topicFavorite");
if (favouriteElement != null) {
String dataType = favouriteElement.attr("data-type");
favorite.setFavorite(!Favorite.TYPE_NOT_FAVORITE.equals(dataType));
}
topicDetail.setFavorite(favorite);
elements = topicDetailElements.select("div.ui-content");
if (elements.isEmpty()) {
failedOnUI("找不到主题内容");
return;
}
topicDetail.setContent(elements.first().outerHtml());
Elements commentsElements = doc.select("div.topic-reply");
Map<Integer, Comment> comments = GetCommentsTask.getCommentsFromElements(commentsElements);
topicDetail.setComments(comments);
successOnUI(topicDetail);
}
use of org.mazhuang.guanggoo.data.entity.Comment in project guanggoo-android by mzlogin.
the class GetCommentsTask method getCommentFromElement.
public static Comment getCommentFromElement(Element element) {
Comment comment = new Comment();
comment.setAvatar(element.select("img.avatar").attr("src"));
Element metaElement = element.select("div.meta").first();
Comment.Meta meta = new Comment.Meta();
Element replyUsernameElement = metaElement.select("a.reply-username").first();
User replier = new User();
replier.setUrl(replyUsernameElement.absUrl("href"));
replier.setUsername(replyUsernameElement.select("span.username").text());
meta.setReplier(replier);
meta.setTime(metaElement.select("span.time").text());
try {
meta.setFloor(Integer.valueOf(metaElement.select("span.fr.floor").first().text().replaceAll("[^\\d]", "")));
} catch (NumberFormatException e) {
e.printStackTrace();
meta.setFloor(0);
}
Element voteElement = metaElement.select("a.J_replyVote").first();
Comment.Vote vote = new Comment.Vote();
vote.setUrl(voteElement.absUrl("href"));
try {
vote.setCount(Integer.valueOf(voteElement.attr("data-count")));
} catch (NumberFormatException e) {
e.printStackTrace();
vote.setCount(0);
}
meta.setVote(vote);
comment.setMeta(meta);
comment.setContent(element.select("span.content").outerHtml());
return comment;
}
use of org.mazhuang.guanggoo.data.entity.Comment in project guanggoo-android by mzlogin.
the class GetCommentsTask method getCommentsFromElements.
public static Map<Integer, Comment> getCommentsFromElements(Elements elements) {
TreeMap<Integer, Comment> comments = new TreeMap<>();
Elements replyItems = elements.select("div.reply-item");
for (Element replyItem : replyItems) {
Comment comment = getCommentFromElement(replyItem);
comments.put(comment.getMeta().getFloor(), comment);
}
return comments.descendingMap();
}
Aggregations