com.socks.jiandan.model.CommentNumber Java Examples
The following examples show how to use
com.socks.jiandan.model.CommentNumber.
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: PictureAdapter.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
private void getCommentCounts(final ArrayList<Picture> pictures) { StringBuilder sb = new StringBuilder(); for (Picture joke : pictures) { sb.append("comment-" + joke.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 < pictures.size(); i++) { pictures.get(i).setComment_counts(response.get(i).getComments() + ""); } if (page == 1) { PictureAdapter.this.pictures.clear(); PictureCache.getInstance(mActivity).clearAllCache(); } PictureAdapter.this.pictures.addAll(pictures); notifyDataSetChanged(); //加载完毕后缓存 PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString (pictures), page); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { ShowToast.Short(ConstantString.LOAD_FAILED); mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage()); } } ), mActivity); }
Example #2
Source File: Request4CommentCounts.java From JianDan_OkHttp with Apache License 2.0 | 5 votes |
@Override protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) { try { String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response"); String[] comment_IDs = getUrl().split("\\=")[1].split("\\,"); ArrayList<CommentNumber> commentNumbers = new ArrayList<>(); for (String comment_ID : comment_IDs) { if (!jsonObject.isNull(comment_ID)) { CommentNumber commentNumber = new CommentNumber(); commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS)); commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID)); commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY)); commentNumbers.add(commentNumber); } else { //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据 commentNumbers.add(new CommentNumber("0", "0", 0)); } } return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example #3
Source File: Request4CommentCounts.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
@Override protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) { try { String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response"); String[] comment_IDs = getUrl().split("\\=")[1].split("\\,"); ArrayList<CommentNumber> commentNumbers = new ArrayList<>(); for (String comment_ID : comment_IDs) { if (!jsonObject.isNull(comment_ID)) { CommentNumber commentNumber = new CommentNumber(); commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS)); commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID)); commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY)); commentNumbers.add(commentNumber); } else { //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据 commentNumbers.add(new CommentNumber("0", "0", 0)); } } return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example #4
Source File: CommentCountsParser.java From JianDan_OkHttp with Apache License 2.0 | 5 votes |
@Override public ArrayList<CommentNumber> parse(Response response) { code = wrapperCode(response.code()); if (!response.isSuccessful()) return null; try { String body = response.body().string(); JSONObject jsonObject = new JSONObject(body).getJSONObject("response"); String[] comment_IDs = response.request().urlString().split("\\=")[1].split("\\,"); ArrayList<CommentNumber> commentNumbers = new ArrayList<>(); for (String comment_ID : comment_IDs) { if (!jsonObject.isNull(comment_ID)) { CommentNumber commentNumber = new CommentNumber(); commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS)); commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID)); commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY)); commentNumbers.add(commentNumber); } else { //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据 commentNumbers.add(new CommentNumber("0", "0", 0)); } } return commentNumbers; } catch (Exception e) { e.printStackTrace(); return null; } }
Example #5
Source File: PictureAdapter.java From JianDan with Apache License 2.0 | 5 votes |
private void getCommentCounts(final ArrayList<Picture> pictures) { StringBuilder sb = new StringBuilder(); for (Picture joke : pictures) { sb.append("comment-" + joke.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 < pictures.size(); i++) { pictures.get(i).setComment_counts(response.get(i).getComments() + ""); } if (page == 1) { PictureAdapter.this.pictures.clear(); PictureCache.getInstance(mActivity).clearAllCache(); } PictureAdapter.this.pictures.addAll(pictures); notifyDataSetChanged(); //加载完毕后缓存 PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString (pictures), page); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { ShowToast.Short(ConstantString.LOAD_FAILED); mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage()); } } ), mActivity); }
Example #6
Source File: JDApi.java From JianDanRxJava with Apache License 2.0 | 5 votes |
public static Observable<ArrayList<CommentNumber>> getCommentNumber(String comments) { return Observable.create(new Observable.OnSubscribe<ArrayList<CommentNumber>>() { @Override public void call(Subscriber<? super ArrayList<CommentNumber>> subscriber) { String url = CommentNumber.getCommentCountsURL(comments); try { subscriber.onNext(new CommentCountsParser().parse(OkHttpProxy.get().url(url).execute())); subscriber.onCompleted(); } catch (IOException e) { subscriber.onError(e); } } }).compose(applySchedulers()); }
Example #7
Source File: CommentCountsParser.java From JianDanRxJava with Apache License 2.0 | 5 votes |
@Override public ArrayList<CommentNumber> parse(Response response) { if (!response.isSuccessful()) return null; try { String body = response.body().string(); JSONObject jsonObject = new JSONObject(body).getJSONObject("response"); String[] comment_IDs = response.request().url().toString().split("\\=")[1].split("\\,"); ArrayList<CommentNumber> commentNumbers = new ArrayList<>(); GsonHelper<CommentNumber> helper = new GsonHelper<>(); for (String comment_ID : comment_IDs) { if (!jsonObject.isNull(comment_ID)) { JSONObject commentObject = jsonObject.getJSONObject(comment_ID); CommentNumber commentNumber = helper.fromJson(commentObject.toString(), CommentNumber.class); commentNumbers.add(commentNumber); } else { //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据 commentNumbers.add(new CommentNumber("0", "0", 0)); } } return commentNumbers; } catch (Exception e) { e.printStackTrace(); return null; } }
Example #8
Source File: Request4CommentCounts.java From JianDan with Apache License 2.0 | 5 votes |
@Override protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) { try { String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response"); String[] comment_IDs = getUrl().split("\\=")[1].split("\\,"); ArrayList<CommentNumber> commentNumbers = new ArrayList<>(); for (String comment_ID : comment_IDs) { if (!jsonObject.isNull(comment_ID)) { CommentNumber commentNumber = new CommentNumber(); commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS)); commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID)); commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY)); commentNumbers.add(commentNumber); } else { //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据 commentNumbers.add(new CommentNumber("0", "0", 0)); } } return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example #9
Source File: Request4CommentCounts.java From JianDan_OkHttp with Apache License 2.0 | 4 votes |
@Override protected void deliverResponse(ArrayList<CommentNumber> response) { listener.onResponse(response); }
Example #10
Source File: JokeAdapter.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
private void getCommentCounts(final ArrayList<Joke> jokes) { StringBuilder sb = new StringBuilder(); for (Joke joke : jokes) { sb.append("comment-" + joke.getComment_ID() + ","); } String url = sb.toString(); if (url.endsWith(",")) { url = url.substring(0, url.length() - 1); } RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(url), new Response .Listener<ArrayList<CommentNumber>>() { @Override public void onResponse(ArrayList<CommentNumber> response) { for (int i = 0; i < jokes.size(); i++) { jokes.get(i).setComment_counts(response.get(i).getComments() + ""); } if (page == 1) { mJokes.clear(); //首次正常加载之后,清空之前的缓存 JokeCache.getInstance(mActivity).clearAllCache(); } mJokes.addAll(jokes); notifyDataSetChanged(); //加载完毕后缓存 JokeCache.getInstance(mActivity).addResultCache(JSONParser.toString(jokes), page); mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage()); mLoadFinisCallBack.loadFinish(null); } } ), mActivity); }
Example #11
Source File: Request4CommentCounts.java From JianDan_OkHttp with Apache License 2.0 | 4 votes |
public Request4CommentCounts(String url, Response.Listener<ArrayList<CommentNumber>> listener, Response.ErrorListener errorListener) { super(Method.GET, url, errorListener); this.listener = listener; }
Example #12
Source File: Request4CommentCounts.java From JianDan with Apache License 2.0 | 4 votes |
@Override protected void deliverResponse(ArrayList<CommentNumber> response) { listener.onResponse(response); }
Example #13
Source File: Request4CommentCounts.java From JianDan with Apache License 2.0 | 4 votes |
public Request4CommentCounts(String url, Response.Listener<ArrayList<CommentNumber>> listener, Response.ErrorListener errorListener) { super(Method.GET, url, errorListener); this.listener = listener; }
Example #14
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 #15
Source File: JokeAdapter.java From JianDan with Apache License 2.0 | 4 votes |
private void getCommentCounts(final ArrayList<Joke> jokes) { StringBuilder sb = new StringBuilder(); for (Joke joke : jokes) { sb.append("comment-" + joke.getComment_ID() + ","); } String url = sb.toString(); if (url.endsWith(",")) { url = url.substring(0, url.length() - 1); } RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(url), new Response .Listener<ArrayList<CommentNumber>>() { @Override public void onResponse(ArrayList<CommentNumber> response) { for (int i = 0; i < jokes.size(); i++) { jokes.get(i).setComment_counts(response.get(i).getComments() + ""); } if (page == 1) { mJokes.clear(); //首次正常加载之后,清空之前的缓存 JokeCache.getInstance(mActivity).clearAllCache(); } mJokes.addAll(jokes); notifyDataSetChanged(); //加载完毕后缓存 JokeCache.getInstance(mActivity).addResultCache(JSONParser.toString(jokes), page); mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage()); mLoadFinisCallBack.loadFinish(null); } } ), mActivity); }
Example #16
Source File: Request4CommentCounts.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
@Override protected void deliverResponse(ArrayList<CommentNumber> response) { listener.onResponse(response); }
Example #17
Source File: Request4CommentCounts.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
public Request4CommentCounts(String url, Response.Listener<ArrayList<CommentNumber>> listener, Response.ErrorListener errorListener) { super(Method.GET, url, errorListener); this.listener = listener; }
Example #18
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); }