Search in sources :

Example 1 with TopicDetail

use of org.mazhuang.guanggoo.data.entity.TopicDetail 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)

Example 2 with TopicDetail

use of org.mazhuang.guanggoo.data.entity.TopicDetail in project guanggoo-android by mzlogin.

the class TopicDetailPresenter method getTopicDetail.

@Override
public void getTopicDetail() {
    mView.startLoading();
    NetworkTaskScheduler.getInstance().execute(new GetTopicDetailTask(getUrl(), new OnResponseListener<TopicDetail>() {

        @Override
        public void onSucceed(TopicDetail data) {
            mView.stopLoading();
            mView.onGetTopicDetailSucceed(data);
        }

        @Override
        public void onFailed(String msg) {
            mView.stopLoading();
            mView.onGetTopicDetailFailed(msg);
        }
    }));
}
Also used : OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) GetTopicDetailTask(org.mazhuang.guanggoo.data.task.GetTopicDetailTask) TopicDetail(org.mazhuang.guanggoo.data.entity.TopicDetail)

Aggregations

TopicDetail (org.mazhuang.guanggoo.data.entity.TopicDetail)2 IOException (java.io.IOException)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1 OnResponseListener (org.mazhuang.guanggoo.data.OnResponseListener)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 GetTopicDetailTask (org.mazhuang.guanggoo.data.task.GetTopicDetailTask)1