Search in sources :

Example 1 with Favorite

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);
}
Also used : Favorite(org.mazhuang.guanggoo.data.entity.Favorite) Comment(org.mazhuang.guanggoo.data.entity.Comment) TopicDetail(org.mazhuang.guanggoo.data.entity.TopicDetail) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Topic(org.mazhuang.guanggoo.data.entity.Topic)

Aggregations

IOException (java.io.IOException)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1 Comment (org.mazhuang.guanggoo.data.entity.Comment)1 Favorite (org.mazhuang.guanggoo.data.entity.Favorite)1 Topic (org.mazhuang.guanggoo.data.entity.Topic)1 TopicDetail (org.mazhuang.guanggoo.data.entity.TopicDetail)1