Search in sources :

Example 1 with VideoComment

use of com.dante.data.model.VideoComment in project 91Pop by DanteAndroid.

the class Parse91PronVideo method parseVideoComment.

/**
 * 解析视频评论
 *
 * @param html 评论html
 * @return 评论列表
 */
public static List<VideoComment> parseVideoComment(String html) {
    List<VideoComment> videoCommentList = new ArrayList<>();
    Document doc = Jsoup.parse(html);
    Elements elements = doc.select("table.comment-divider");
    for (Element element : elements) {
        VideoComment videoComment = new VideoComment();
        String ownnerUrl = element.select("a[href*=UID]").first().attr("href");
        String uid = ownnerUrl.substring(ownnerUrl.indexOf("=") + 1, ownnerUrl.length());
        videoComment.setUid(uid);
        // Logger.t(TAG).d(uid);
        String uName = element.select("a[href*=UID]").first().text();
        videoComment.setuName(uName);
        Logger.t(TAG).d(uName);
        String replyTime = element.select("span.comment-info").first().text();
        videoComment.setReplyTime(replyTime.replace("(", "").replace(")", ""));
        // Logger.t(TAG).d(replyTime);
        String tmpreplyId = element.select("div.comment-body").first().attr("id");
        String replyId = tmpreplyId.substring(tmpreplyId.lastIndexOf("_") + 1, tmpreplyId.length());
        videoComment.setReplyId(replyId);
        // Logger.t(TAG).d("replyId:" + replyId);
        String comment = element.select("div.comment-body").first().text().replace("举报", "").replace("Show", "");
        // videoComment.setContentMessage(comment.replace("Show", ""));
        // Logger.t(TAG).d(comment);
        List<String> tmpQuoteList = new ArrayList<>();
        tmpQuoteList.add(comment);
        Elements quotes = element.select("div.comment-body").select("div.comment_quote");
        for (Element element1 : quotes) {
            String quote = element1.text();
            tmpQuoteList.add(quote);
        }
        List<String> quoteList = new ArrayList<>();
        for (int i = 0; i < tmpQuoteList.size(); i++) {
            String quote;
            if (i + 1 >= tmpQuoteList.size()) {
                quote = tmpQuoteList.get(i);
                quoteList.add(0, quote.trim());
                // Logger.t(TAG).d(quote);
                break;
            }
            quote = tmpQuoteList.get(i).replace(tmpQuoteList.get(i + 1), "");
            quoteList.add(0, quote.trim());
        // Logger.t(TAG).d(quote);
        }
        videoComment.setCommentQuoteList(quoteList);
        String info = element.select("td").first().text();
        String titleInfo = info.substring(0, info.indexOf("("));
        videoComment.setTitleInfo(titleInfo.replace(uName, ""));
        // Logger.t(TAG).d(titleInfo);
        videoCommentList.add(videoComment);
    }
    return videoCommentList;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) VideoComment(com.dante.data.model.VideoComment)

Example 2 with VideoComment

use of com.dante.data.model.VideoComment in project 91Pop by DanteAndroid.

the class PlayVideoPresenter method loadVideoComment.

@Override
public void loadVideoComment(String videoId, String viewKey, final boolean pullToRefresh) {
    if (pullToRefresh) {
        start = 1;
    }
    dataManager.loadPorn91VideoComments(videoId, start, viewKey).retryWhen(new RetryWhenProcess(RetryWhenProcess.PROCESS_TIME)).compose(RxSchedulersHelper.<List<VideoComment>>ioMainThread()).compose(provider.<List<VideoComment>>bindUntilEvent(Lifecycle.Event.ON_STOP)).map(new Function<List<VideoComment>, List<VideoComment>>() {

        @Override
        public List<VideoComment> apply(List<VideoComment> videoComments) throws Exception {
            List<VideoComment> newList = new ArrayList<>();
            for (VideoComment c : videoComments) {
                List<String> list = c.getCommentQuoteList();
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < list.size(); i++) {
                    builder.append(list.get(i));
                }
                if (invalidComment(builder.toString())) {
                    Logger.d("invalidComment " + builder.toString());
                } else {
                    newList.add(c);
                }
            }
            return newList;
        }
    }).subscribe(new CallBackWrapper<List<VideoComment>>() {

        @Override
        public void onBegin(Disposable d) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    if (start == 1 && pullToRefresh) {
                        view.showLoading(pullToRefresh);
                    }
                }
            });
        }

        @Override
        public void onSuccess(final List<VideoComment> videoCommentList) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    if (start == 1) {
                        view.setVideoCommentData(videoCommentList, pullToRefresh);
                    } else {
                        view.setMoreVideoCommentData(videoCommentList);
                    }
                    if (videoCommentList.size() == 0 && start == 1) {
                        view.noMoreVideoCommentData("暂无评论");
                    } else if (videoCommentList.size() == 0 && start > 1) {
                        view.noMoreVideoCommentData("没有更多评论了");
                    }
                    start++;
                    view.showContent();
                }
            });
        }

        @Override
        public void onError(final String msg, int code) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    if (start == 1) {
                        view.loadVideoCommentError(msg);
                    } else {
                        view.loadMoreVideoCommentError(msg);
                    }
                }
            });
        }

        @Override
        public void onCancel(boolean isCancel) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    Logger.t(TAG).d("------getVideoComments  onCancel----------------------------");
                    if (start == 1) {
                        view.loadVideoCommentError("取消请求");
                    } else {
                        view.loadMoreVideoCommentError("取消请求");
                    }
                }
            });
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) ArrayList(java.util.ArrayList) VideoComment(com.dante.data.model.VideoComment) Function(io.reactivex.functions.Function) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with VideoComment

use of com.dante.data.model.VideoComment in project 91Pop by DanteAndroid.

the class BasePlayVideo method initVideoComments.

private void initVideoComments() {
    List<VideoComment> videoCommentList = new ArrayList<>();
    videoCommentAdapter = new VideoCommentAdapter(this, R.layout.item_video_comment, videoCommentList);
    recyclerViewVideoComment.setLayoutManager(new LinearLayoutManager(this));
    // recyclerViewVideoComment.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    recyclerViewVideoComment.setAdapter(videoCommentAdapter);
    videoCommentAdapter.setLoadMoreView(new LoadMoreView() {

        @Override
        public int getLayoutId() {
            return R.layout.loading;
        }

        @Override
        protected int getLoadingViewId() {
            return R.id.loading;
        }

        @Override
        protected int getLoadFailViewId() {
            return R.id.loadFailed;
        }

        @Override
        protected int getLoadEndViewId() {
            return R.id.loadEnd;
        }
    });
    videoCommentAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {

        @Override
        public void onLoadMoreRequested() {
            // 加载评论
            if (unLimit91PornItem.getVideoResultId() == 0) {
                videoCommentAdapter.loadMoreFail();
                return;
            }
            presenter.loadVideoComment(unLimit91PornItem.getVideoResult().getVideoId(), unLimit91PornItem.getViewKey(), false);
        }
    }, recyclerViewVideoComment);
    videoCommentAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            if (floatingToolbar.isShowing()) {
                floatingToolbar.hide();
            }
            if (commentLayoutShown) {
                if (videoCommentAdapter.getClickPosition() == position) {
                    hideCommentLayout();
                }
            } else {
                showCommentLayout();
            }
            isComment = false;
            videoComment = (VideoComment) adapter.getData().get(position);
            etVideoComment.setHint("回复:" + videoComment.getuName());
            videoCommentAdapter.setClickPosition(position);
        }
    });
    recyclerViewVideoComment.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (dy > 0)
                fab.hide();
            else if (dy < -5)
                fab.show();
        }
    });
}
Also used : VideoCommentAdapter(com.dante.adapter.VideoCommentAdapter) LoadMoreView(com.chad.library.adapter.base.loadmore.LoadMoreView) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) LoadMoreView(com.chad.library.adapter.base.loadmore.LoadMoreView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) VideoComment(com.dante.data.model.VideoComment) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

VideoComment (com.dante.data.model.VideoComment)3 ArrayList (java.util.ArrayList)3 NonNull (android.support.annotation.NonNull)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 LoadMoreView (com.chad.library.adapter.base.loadmore.LoadMoreView)1 VideoCommentAdapter (com.dante.adapter.VideoCommentAdapter)1 RetryWhenProcess (com.dante.rxjava.RetryWhenProcess)1 Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1 List (java.util.List)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1