com.socks.jiandan.model.Video Java Examples
The following examples show how to use
com.socks.jiandan.model.Video.
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 |
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: VideoCache.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
@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 #3
Source File: VideoCache.java From JianDan_OkHttp with Apache License 2.0 | 5 votes |
@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 File: VideoAdapter.java From JianDan with Apache License 2.0 | 5 votes |
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 File: VideoCache.java From JianDan with Apache License 2.0 | 5 votes |
@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 File: JDApi.java From JianDanRxJava with Apache License 2.0 | 5 votes |
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 #7
Source File: VideoAdapter.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
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 #8
Source File: VideoAdapter.java From JianDanRxJava with Apache License 2.0 | 5 votes |
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 #9
Source File: VideoCache.java From JianDanRxJava with Apache License 2.0 | 5 votes |
@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 File: Request4Video.java From JianDan with Apache License 2.0 | 4 votes |
@Override protected void deliverResponse(ArrayList<Video> response) { listener.onResponse(response); }
Example #11
Source File: Request4Video.java From JianDan_OkHttp with Apache License 2.0 | 4 votes |
@Override protected void deliverResponse(ArrayList<Video> response) { listener.onResponse(response); }
Example #12
Source File: Request4Video.java From JianDan_OkHttp with Apache License 2.0 | 4 votes |
@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 File: Request4Video.java From JianDan_OkHttp with Apache License 2.0 | 4 votes |
public Request4Video(String url, Response.Listener<ArrayList<Video>> listener, Response.ErrorListener errorListener) { super(Method.GET, url, errorListener); this.listener = listener; }
Example #14
Source File: VideoParser.java From JianDan_OkHttp with Apache License 2.0 | 4 votes |
@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 #15
Source File: VideoParser.java From JianDanRxJava with Apache License 2.0 | 4 votes |
@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 #16
Source File: Request4Video.java From JianDan with Apache License 2.0 | 4 votes |
@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 File: Request4Video.java From JianDan with Apache License 2.0 | 4 votes |
public Request4Video(String url, Response.Listener<ArrayList<Video>> listener, Response.ErrorListener errorListener) { super(Method.GET, url, errorListener); this.listener = listener; }
Example #18
Source File: VideoAdapter.java From JianDan with Apache License 2.0 | 4 votes |
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 #19
Source File: Request4Video.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
@Override protected void deliverResponse(ArrayList<Video> response) { listener.onResponse(response); }
Example #20
Source File: Request4Video.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
@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 #21
Source File: Request4Video.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
public Request4Video(String url, Response.Listener<ArrayList<Video>> listener, Response.ErrorListener errorListener) { super(Method.GET, url, errorListener); this.listener = listener; }
Example #22
Source File: VideoAdapter.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
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); }