use of org.mazhuang.guanggoo.data.entity.Favorite 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);
}
Aggregations