Search in sources :

Example 1 with GalleryCommentList

use of com.hippo.ehviewer.client.data.GalleryCommentList 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)

Example 2 with GalleryCommentList

use of com.hippo.ehviewer.client.data.GalleryCommentList in project EhViewer by seven332.

the class GalleryDetailScene method onSceneResult.

@Override
protected void onSceneResult(int requestCode, int resultCode, Bundle data) {
    switch(requestCode) {
        case REQUEST_CODE_COMMENT_GALLERY:
            if (resultCode != RESULT_OK || data == null) {
                break;
            }
            GalleryCommentList comments = data.getParcelable(GalleryCommentsScene.KEY_COMMENT_LIST);
            if (mGalleryDetail == null && comments == null) {
                break;
            }
            mGalleryDetail.comments = comments;
            bindComments(comments.comments);
            break;
        default:
            super.onSceneResult(requestCode, resultCode, data);
    }
}
Also used : GalleryCommentList(com.hippo.ehviewer.client.data.GalleryCommentList)

Aggregations

GalleryCommentList (com.hippo.ehviewer.client.data.GalleryCommentList)2 NonNull (androidx.annotation.NonNull)1 GalleryComment (com.hippo.ehviewer.client.data.GalleryComment)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