Search in sources :

Example 1 with User

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

Example 2 with User

use of org.mazhuang.guanggoo.data.entity.User 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;
}
Also used : Comment(org.mazhuang.guanggoo.data.entity.Comment) User(org.mazhuang.guanggoo.data.entity.User) Element(org.jsoup.nodes.Element)

Aggregations

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