Search in sources :

Example 1 with Meta

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

the class GetTopicListTask method createTopicFromElement.

public static Topic createTopicFromElement(Element element) {
    Topic topic = new Topic();
    Element titleElement = element.select("h3.title").select("a").first();
    if (titleElement != null) {
        // 主题列表页
        topic.setTitle(titleElement.text());
    } else {
        // 主题详情页
        titleElement = element.select("h3.title").first();
        if (titleElement != null) {
            topic.setTitle(titleElement.text());
        }
    }
    topic.setUrl(titleElement.absUrl("href"));
    topic.setAvatar(element.select("img.avatar").attr("src"));
    Element metaElement = element.select("div.meta").first();
    Meta meta = createMetaFromElement(metaElement);
    topic.setMeta(meta);
    Elements countElements = element.select("div.count");
    if (!countElements.isEmpty()) {
        topic.setCount(Integer.valueOf(countElements.first().select("a").first().text()));
    }
    return topic;
}
Also used : Meta(org.mazhuang.guanggoo.data.entity.Meta) Element(org.jsoup.nodes.Element) Topic(org.mazhuang.guanggoo.data.entity.Topic) Elements(org.jsoup.select.Elements)

Example 2 with Meta

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

the class GetTopicListTask method createMetaFromElement.

private static Meta createMetaFromElement(Element element) {
    Meta meta = new Meta();
    Element nodeElement = element.select("span.node").select("a").first();
    Node node = new Node();
    node.setTitle(nodeElement.text());
    node.setUrl(nodeElement.absUrl("href"));
    meta.setNode(node);
    Element userElement = element.select("span.username").select("a").first();
    User user = new User();
    user.setUsername(userElement.text());
    user.setUrl(userElement.absUrl("href"));
    meta.setAuthor(user);
    // 主题列表页
    Elements lastTouchedElement = element.select("span.last-touched");
    if (lastTouchedElement.isEmpty()) {
        // 主题详情页
        lastTouchedElement = element.select("span.last-reply-time");
    }
    meta.setLastTouched(lastTouchedElement.text());
    Elements createdTimeElement = element.select("span.created-time");
    meta.setCreatedTime(createdTimeElement.text());
    Element lastReplyUserElement = element.select("span.last-reply-username").select("a").first();
    if (lastReplyUserElement != null) {
        User lastReplyUser = new User();
        lastReplyUser.setUsername(lastReplyUserElement.select("strong").text());
        lastReplyUser.setUrl(lastReplyUserElement.absUrl("href"));
        meta.setLastReplyUser(lastReplyUser);
    }
    return meta;
}
Also used : Meta(org.mazhuang.guanggoo.data.entity.Meta) User(org.mazhuang.guanggoo.data.entity.User) Element(org.jsoup.nodes.Element) Node(org.mazhuang.guanggoo.data.entity.Node) Elements(org.jsoup.select.Elements)

Aggregations

Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 Meta (org.mazhuang.guanggoo.data.entity.Meta)2 Node (org.mazhuang.guanggoo.data.entity.Node)1 Topic (org.mazhuang.guanggoo.data.entity.Topic)1 User (org.mazhuang.guanggoo.data.entity.User)1