Search in sources :

Example 1 with MutableBoolean

use of com.hippo.util.MutableBoolean in project EhViewer by seven332.

the class GalleryDetailParser method parseComments.

/**
 * Parse comments with html parser
 */
@NonNull
public static GalleryCommentList parseComments(Document document) {
    try {
        Element cdiv = document.getElementById("cdiv");
        Elements c1s = cdiv.getElementsByClass("c1");
        List<GalleryComment> list = new ArrayList<>(c1s.size());
        for (int i = 0, n = c1s.size(); i < n; i++) {
            GalleryComment comment = parseComment(c1s.get(i));
            if (null != comment) {
                list.add(comment);
            }
        }
        Element chd = cdiv.getElementById("chd");
        MutableBoolean hasMore = new MutableBoolean(false);
        NodeTraversor.traverse(new NodeVisitor() {

            @Override
            public void head(Node node, int depth) {
                if (node instanceof Element && ((Element) node).text().equals("click to show all")) {
                    hasMore.value = true;
                }
            }

            @Override
            public void tail(Node node, int depth) {
            }
        }, chd);
        return new GalleryCommentList(list.toArray(new GalleryComment[list.size()]), hasMore.value);
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
        e.printStackTrace();
        return EMPTY_GALLERY_COMMENT_ARRAY;
    }
}
Also used : Element(org.jsoup.nodes.Element) MutableBoolean(com.hippo.util.MutableBoolean) Node(org.jsoup.nodes.Node) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements) GalleryCommentList(com.hippo.ehviewer.client.data.GalleryCommentList) NodeVisitor(org.jsoup.select.NodeVisitor) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1 GalleryComment (com.hippo.ehviewer.client.data.GalleryComment)1 GalleryCommentList (com.hippo.ehviewer.client.data.GalleryCommentList)1 MutableBoolean (com.hippo.util.MutableBoolean)1 ArrayList (java.util.ArrayList)1 Element (org.jsoup.nodes.Element)1 Node (org.jsoup.nodes.Node)1 Elements (org.jsoup.select.Elements)1 NodeVisitor (org.jsoup.select.NodeVisitor)1