com.socks.jiandan.cache.VideoCache Java Examples

The following examples show how to use com.socks.jiandan.cache.VideoCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoAdapter.java    From JianDanRxJava with Apache License 2.0 6 votes vote down vote up
private void loadCache() {
    Subscription subscription = Observable.create((Observable.OnSubscribe<ArrayList<Video>>) subscriber -> {
        subscriber.onNext(VideoCache.getInstance(mActivity).getCacheByPage(page));
        subscriber.onCompleted();
    }).compose(JDApi.applySchedulers())
            .doOnNext(videos -> {
                if (page == 1) {
                    mVideos.clear();
                    ToastHelper.Short(ConstantString.LOAD_NO_NETWORK);
                }
            })
            .subscribe(videos -> {
                mVideos.addAll(videos);
                notifyDataSetChanged();
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);
            });
    mActivity.addSubscription(subscription);
}
 
Example #2
Source File: VideoAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
private void loadCache() {

        mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
        mLoadFinisCallBack.loadFinish(null);
        VideoCache videoCacheUtil = VideoCache.getInstance(mActivity);
        if (page == 1) {
            mVideos.clear();
            ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
        }
        mVideos.addAll(videoCacheUtil.getCacheByPage(page));
        notifyDataSetChanged();

    }
 
Example #3
Source File: VideoAdapter.java    From JianDan with Apache License 2.0 5 votes vote down vote up
private void loadCache() {

        mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
        mLoadFinisCallBack.loadFinish(null);
        VideoCache videoCacheUtil = VideoCache.getInstance(mActivity);
        if (page == 1) {
            mVideos.clear();
            ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
        }
        mVideos.addAll(videoCacheUtil.getCacheByPage(page));
        notifyDataSetChanged();

    }
 
Example #4
Source File: VideoAdapter.java    From JianDanRxJava with Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Video> videos) {

        StringBuilder sb = new StringBuilder();
        for (Video video : videos) {
            sb.append("comment-" + video.getComment_ID() + ",");
        }

        Subscription subscription = JDApi.getCommentNumber(sb.toString())
                .observeOn(Schedulers.io())
                .doOnNext(commentNumbers -> {
                    if (page == 1) {
                        mVideos.clear();
                        VideoCache.getInstance(mActivity).clearAllCache();
                    }
                    VideoCache.getInstance(mActivity).addResultCache(GsonHelper.toString
                            (videos), page);
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(commentNumbers -> {

                    for (int i = 0; i < videos.size(); i++) {
                        videos.get(i).setComment_count(commentNumbers.get(i).comments + "");
                    }

                    mVideos.addAll(videos);
                    notifyDataSetChanged();

                    if (mVideos.size() < 10) {
                        loadNextPage();
                    }
                    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                    mLoadFinisCallBack.loadFinish(null);
                }, e -> {
                    mLoadFinisCallBack.loadFinish(e);
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET);
                });
        mActivity.addSubscription(subscription);
    }
 
Example #5
Source File: VideoAdapter.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
private void loadCache() {

        mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
        mLoadFinisCallBack.loadFinish(null);
        VideoCache videoCacheUtil = VideoCache.getInstance(mActivity);
        if (page == 1) {
            mVideos.clear();
            ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
        }
        mVideos.addAll(videoCacheUtil.getCacheByPage(page));
        notifyDataSetChanged();

    }
 
Example #6
Source File: VideoAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
private void getCommentCounts(final ArrayList<Video> videos) {

        StringBuilder sb = new StringBuilder();
        for (Video video : videos) {
            sb.append("comment-" + video.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < videos.size(); i++) {
                    videos.get(i).setComment_count(response.get(i).getComments() + "");
                }

                if (page == 1) {
                    mVideos.clear();
                    VideoCache.getInstance(mActivity).clearAllCache();
                }

                mVideos.addAll(videos);
                notifyDataSetChanged();
                VideoCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (videos), page);
                //防止加载不到一页的情况
                if (mVideos.size() < 10) {
                    loadNextPage();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, null);
            }
        }
        ), mActivity);

    }
 
Example #7
Source File: VideoAdapter.java    From JianDan with Apache License 2.0 4 votes vote down vote up
private void getCommentCounts(final ArrayList<Video> videos) {

        StringBuilder sb = new StringBuilder();
        for (Video video : videos) {
            sb.append("comment-" + video.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < videos.size(); i++) {
                    videos.get(i).setComment_count(response.get(i).getComments() + "");
                }

                if (page == 1) {
                    mVideos.clear();
                    VideoCache.getInstance(mActivity).clearAllCache();
                }

                mVideos.addAll(videos);
                notifyDataSetChanged();
                VideoCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (videos), page);
                //防止加载不到一页的情况
                if (mVideos.size() < 10) {
                    loadNextPage();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, null);
            }
        }
        ), mActivity);

    }