Java Code Examples for com.socks.jiandan.model.Video

The following examples show how to use com.socks.jiandan.model.Video. These examples are extracted from open source projects. 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 Project: JianDanRxJava   Author: ZhaoKaiQiang   File: VideoAdapter.java    License: 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 Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadData() {

        RequestManager.addRequest(new Request4Video(Video.getUrlVideos(page),
                new Response.Listener<ArrayList<Video>>() {
                    @Override
                    public void onResponse(ArrayList<Video> response) {
                        getCommentCounts(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadFinisCallBack.loadFinish(null);
            }
        }), mActivity);
    }
 
Example #3
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example #4
Source Project: JianDan   Author: ZhaoKaiQiang   File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadData() {

        RequestManager.addRequest(new Request4Video(Video.getUrlVideos(page),
                new Response.Listener<ArrayList<Video>>() {
                    @Override
                    public void onResponse(ArrayList<Video> response) {
                        getCommentCounts(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadFinisCallBack.loadFinish(null);
            }
        }), mActivity);
    }
 
Example #5
Source Project: JianDan   Author: ZhaoKaiQiang   File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example #6
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: VideoAdapter.java    License: 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 #7
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example #8
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: JDApi.java    License: Apache License 2.0 5 votes vote down vote up
public static Observable<ArrayList<Video>> getVideos(int page) {
    return Observable.create(new Observable.OnSubscribe<ArrayList<Video>>() {
        @Override
        public void call(Subscriber<? super ArrayList<Video>> subscriber) {
            try {
                subscriber.onNext(new VideoParser().parse(OkHttpProxy.get().url(Video.getUrlVideos(page)).execute()));
                subscriber.onCompleted();
            } catch (IOException e) {
                subscriber.onError(e);
            }
        }
    }).compose(applySchedulers());
}
 
Example #9
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example #10
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: VideoAdapter.java    License: 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 #11
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
public Request4Video(String url, Response.Listener<ArrayList<Video>> listener,
                     Response.ErrorListener errorListener) {
    super(Method.GET, url, errorListener);
    this.listener = listener;
}
 
Example #12
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Video>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject jsonObject = new JSONObject(jsonStr);

        if ("ok".equals(jsonObject.optString("status"))) {

            JSONArray commentsArray = jsonObject.optJSONArray("comments");
            ArrayList<Video> videos = new ArrayList<>();

            for (int i = 0; i < commentsArray.length(); i++) {

                JSONObject commentObject = commentsArray.getJSONObject(i);
                JSONObject videoObject = commentObject.optJSONArray("videos").optJSONObject(0);

                if (videoObject != null) {
                    Video video = new Video();
                    video.setTitle(videoObject.optString("title"));
                    String videoSource = videoObject.optString("video_source");
                    video.setComment_ID(commentObject.optString("comment_ID"));
                    video.setVote_positive(commentObject.optString("vote_positive"));
                    video.setVote_negative(commentObject.optString("vote_negative"));
                    video.setVideo_source(videoSource);

                    if (videoSource.equals("youku")) {
                        video.setUrl(videoObject.optString("link"));
                        video.setDesc(videoObject.optString("description"));
                        video.setImgUrl(videoObject.optString("thumbnail"));
                        video.setImgUrl4Big(videoObject.optString("thumbnail_v2"));
                    } else if (videoSource.equals("56")) {
                        video.setUrl(videoObject.optString("url"));
                        video.setDesc(videoObject.optString("desc"));
                        video.setImgUrl4Big(videoObject.optString("img"));
                        video.setImgUrl(videoObject.optString("mimg"));
                    } else if (videoSource.equals("tudou")) {
                        video.setUrl(videoObject.optString("playUrl"));
                        video.setImgUrl(videoObject.optString("picUrl"));
                        video.setImgUrl4Big(videoObject.optString("picUrl"));
                        video.setDesc(videoObject.optString("description"));
                    }

                    videos.add(video);
                }
            }

            return Response.success(videos, HttpHeaderParser.parseCacheHeaders(response));
        } else {
            return Response.success(new ArrayList<Video>(), HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #13
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void deliverResponse(ArrayList<Video> response) {
    listener.onResponse(response);
}
 
Example #14
Source Project: JianDan   Author: ZhaoKaiQiang   File: VideoAdapter.java    License: 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 #15
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
public Request4Video(String url, Response.Listener<ArrayList<Video>> listener,
                     Response.ErrorListener errorListener) {
    super(Method.GET, url, errorListener);
    this.listener = listener;
}
 
Example #16
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Video>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject jsonObject = new JSONObject(jsonStr);

        if ("ok".equals(jsonObject.optString("status"))) {

            JSONArray commentsArray = jsonObject.optJSONArray("comments");
            ArrayList<Video> videos = new ArrayList<>();

            for (int i = 0; i < commentsArray.length(); i++) {

                JSONObject commentObject = commentsArray.getJSONObject(i);
                JSONObject videoObject = commentObject.optJSONArray("videos").optJSONObject(0);

                if (videoObject != null) {
                    Video video = new Video();
                    video.setTitle(videoObject.optString("title"));
                    String videoSource = videoObject.optString("video_source");
                    video.setComment_ID(commentObject.optString("comment_ID"));
                    video.setVote_positive(commentObject.optString("vote_positive"));
                    video.setVote_negative(commentObject.optString("vote_negative"));
                    video.setVideo_source(videoSource);

                    if (videoSource.equals("youku")) {
                        video.setUrl(videoObject.optString("link"));
                        video.setDesc(videoObject.optString("description"));
                        video.setImgUrl(videoObject.optString("thumbnail"));
                        video.setImgUrl4Big(videoObject.optString("thumbnail_v2"));
                    } else if (videoSource.equals("56")) {
                        video.setUrl(videoObject.optString("url"));
                        video.setDesc(videoObject.optString("desc"));
                        video.setImgUrl4Big(videoObject.optString("img"));
                        video.setImgUrl(videoObject.optString("mimg"));
                    } else if (videoSource.equals("tudou")) {
                        video.setUrl(videoObject.optString("playUrl"));
                        video.setImgUrl(videoObject.optString("picUrl"));
                        video.setImgUrl4Big(videoObject.optString("picUrl"));
                        video.setDesc(videoObject.optString("description"));
                    }

                    videos.add(video);
                }
            }

            return Response.success(videos, HttpHeaderParser.parseCacheHeaders(response));
        } else {
            return Response.success(new ArrayList<Video>(), HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #17
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void deliverResponse(ArrayList<Video> response) {
    listener.onResponse(response);
}
 
Example #18
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: VideoParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
public ArrayList<Video> parse(Response response) {

    try {
        String jsonStr = response.body().string();
        JSONObject jsonObject = new JSONObject(jsonStr);

        if ("ok".equals(jsonObject.optString("status"))) {

            JSONArray commentsArray = jsonObject.optJSONArray("comments");
            ArrayList<Video> videos = new ArrayList<>();

            for (int i = 0; i < commentsArray.length(); i++) {

                JSONObject commentObject = commentsArray.getJSONObject(i);
                JSONObject videoObject = commentObject.optJSONArray("videos").optJSONObject(0);

                if (videoObject != null) {
                    Video video = new Video();
                    video.setTitle(videoObject.optString("title"));
                    String videoSource = videoObject.optString("video_source");
                    video.setComment_ID(commentObject.optString("comment_ID"));
                    video.setVote_positive(commentObject.optString("vote_positive"));
                    video.setVote_negative(commentObject.optString("vote_negative"));
                    video.setVideo_source(videoSource);

                    if (videoSource.equals("youku")) {
                        video.setUrl(videoObject.optString("link"));
                        video.setDesc(videoObject.optString("description"));
                        video.setImgUrl(videoObject.optString("thumbnail"));
                        video.setImgUrl4Big(videoObject.optString("thumbnail_v2"));
                    } else if (videoSource.equals("56")) {
                        video.setUrl(videoObject.optString("url"));
                        video.setDesc(videoObject.optString("desc"));
                        video.setImgUrl4Big(videoObject.optString("img"));
                        video.setImgUrl(videoObject.optString("mimg"));
                    } else if (videoSource.equals("tudou")) {
                        video.setUrl(videoObject.optString("playUrl"));
                        video.setImgUrl(videoObject.optString("picUrl"));
                        video.setImgUrl4Big(videoObject.optString("picUrl"));
                        video.setDesc(videoObject.optString("description"));
                    }

                    videos.add(video);
                }
            }

            return videos;
        } else {
            return new ArrayList<>();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #19
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: VideoParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
public ArrayList<Video> parse(Response response) {

    code = wrapperCode(response.code());
    try {
        String jsonStr = response.body().string();
        JSONObject jsonObject = new JSONObject(jsonStr);

        if ("ok".equals(jsonObject.optString("status"))) {

            JSONArray commentsArray = jsonObject.optJSONArray("comments");
            ArrayList<Video> videos = new ArrayList<>();

            for (int i = 0; i < commentsArray.length(); i++) {

                JSONObject commentObject = commentsArray.getJSONObject(i);
                JSONObject videoObject = commentObject.optJSONArray("videos").optJSONObject(0);

                if (videoObject != null) {
                    Video video = new Video();
                    video.setTitle(videoObject.optString("title"));
                    String videoSource = videoObject.optString("video_source");
                    video.setComment_ID(commentObject.optString("comment_ID"));
                    video.setVote_positive(commentObject.optString("vote_positive"));
                    video.setVote_negative(commentObject.optString("vote_negative"));
                    video.setVideo_source(videoSource);

                    if (videoSource.equals("youku")) {
                        video.setUrl(videoObject.optString("link"));
                        video.setDesc(videoObject.optString("description"));
                        video.setImgUrl(videoObject.optString("thumbnail"));
                        video.setImgUrl4Big(videoObject.optString("thumbnail_v2"));
                    } else if (videoSource.equals("56")) {
                        video.setUrl(videoObject.optString("url"));
                        video.setDesc(videoObject.optString("desc"));
                        video.setImgUrl4Big(videoObject.optString("img"));
                        video.setImgUrl(videoObject.optString("mimg"));
                    } else if (videoSource.equals("tudou")) {
                        video.setUrl(videoObject.optString("playUrl"));
                        video.setImgUrl(videoObject.optString("picUrl"));
                        video.setImgUrl4Big(videoObject.optString("picUrl"));
                        video.setDesc(videoObject.optString("description"));
                    }

                    videos.add(video);
                }
            }

            return videos;
        } else {
            return new ArrayList<>();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #20
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
public Request4Video(String url, Response.Listener<ArrayList<Video>> listener,
                     Response.ErrorListener errorListener) {
    super(Method.GET, url, errorListener);
    this.listener = listener;
}
 
Example #21
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Video>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject jsonObject = new JSONObject(jsonStr);

        if ("ok".equals(jsonObject.optString("status"))) {

            JSONArray commentsArray = jsonObject.optJSONArray("comments");
            ArrayList<Video> videos = new ArrayList<>();

            for (int i = 0; i < commentsArray.length(); i++) {

                JSONObject commentObject = commentsArray.getJSONObject(i);
                JSONObject videoObject = commentObject.optJSONArray("videos").optJSONObject(0);

                if (videoObject != null) {
                    Video video = new Video();
                    video.setTitle(videoObject.optString("title"));
                    String videoSource = videoObject.optString("video_source");
                    video.setComment_ID(commentObject.optString("comment_ID"));
                    video.setVote_positive(commentObject.optString("vote_positive"));
                    video.setVote_negative(commentObject.optString("vote_negative"));
                    video.setVideo_source(videoSource);

                    if (videoSource.equals("youku")) {
                        video.setUrl(videoObject.optString("link"));
                        video.setDesc(videoObject.optString("description"));
                        video.setImgUrl(videoObject.optString("thumbnail"));
                        video.setImgUrl4Big(videoObject.optString("thumbnail_v2"));
                    } else if (videoSource.equals("56")) {
                        video.setUrl(videoObject.optString("url"));
                        video.setDesc(videoObject.optString("desc"));
                        video.setImgUrl4Big(videoObject.optString("img"));
                        video.setImgUrl(videoObject.optString("mimg"));
                    } else if (videoSource.equals("tudou")) {
                        video.setUrl(videoObject.optString("playUrl"));
                        video.setImgUrl(videoObject.optString("picUrl"));
                        video.setImgUrl4Big(videoObject.optString("picUrl"));
                        video.setDesc(videoObject.optString("description"));
                    }

                    videos.add(video);
                }
            }

            return Response.success(videos, HttpHeaderParser.parseCacheHeaders(response));
        } else {
            return Response.success(new ArrayList<Video>(), HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #22
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4Video.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void deliverResponse(ArrayList<Video> response) {
    listener.onResponse(response);
}