com.socks.jiandan.cache.PictureCache Java Examples
The following examples show how to use
com.socks.jiandan.cache.PictureCache.
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 JianDanRxJava with Apache License 2.0 | 6 votes |
private void loadData() { Subscription subscription = JDApi.getPictures(mType, page) .flatMap(Observable::from) .filter(picture -> picture.getPics() != null) .toList() .observeOn(Schedulers.io()) .doOnNext(pictures -> { if (page == 1) { PictureAdapter.this.mPictures.clear(); PictureCache.getInstance(mActivity).clearAllCache(); } }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::getCommentCounts, e -> { mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET); mLoadFinisCallBack.loadFinish(null); }); mActivity.addSubscription(subscription); }
Example #2
Source File: PictureAdapter.java From JianDanRxJava with Apache License 2.0 | 6 votes |
private void loadCache() { Subscription subscription = Observable.create((Observable.OnSubscribe<ArrayList<Picture>>) subscriber -> { subscriber.onNext(PictureCache.getInstance(mActivity).getCacheByPage(page)); subscriber.onCompleted(); }).compose(JDApi.applySchedulers()) .doOnNext(pictures -> { if (page == 1) { mPictures.clear(); ToastHelper.Short(ConstantString.LOAD_NO_NETWORK); } }) .subscribe(pictures -> { mPictures.addAll(pictures); notifyDataSetChanged(); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); mLoadFinisCallBack.loadFinish(null); }); mActivity.addSubscription(subscription); }
Example #3
Source File: PictureAdapter.java From JianDanRxJava with Apache License 2.0 | 6 votes |
private void getCommentCounts(final List<Picture> pictures) { StringBuilder sb = new StringBuilder(); for (Picture joke : pictures) { sb.append("comment-").append(joke.getComment_ID()).append(","); } JDApi.getCommentNumber(sb.toString()) .doOnCompleted(() -> PictureCache.getInstance(mActivity).addResultCache(GsonHelper.toString(mPictures), page)) .subscribe(commentNumbers -> { mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); mLoadFinisCallBack.loadFinish(null); for (int i = 0; i < pictures.size(); i++) { pictures.get(i).setComment_counts(commentNumbers.get(i).comments + ""); } PictureAdapter.this.mPictures.addAll(pictures); notifyDataSetChanged(); }, e -> { ToastHelper.Short(ConstantString.LOAD_FAILED); mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET); }); }
Example #4
Source File: PictureAdapter.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
private void loadCache() { mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); mLoadFinisCallBack.loadFinish(null); PictureCache pictureCacheUtil = PictureCache.getInstance(mActivity); if (page == 1) { pictures.clear(); ShowToast.Short(ConstantString.LOAD_NO_NETWORK); } pictures.addAll(pictureCacheUtil.getCacheByPage(page)); notifyDataSetChanged(); }
Example #5
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 #6
Source File: PictureAdapter.java From JianDan with Apache License 2.0 | 5 votes |
private void loadCache() { mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); mLoadFinisCallBack.loadFinish(null); PictureCache pictureCacheUtil = PictureCache.getInstance(mActivity); if (page == 1) { pictures.clear(); ShowToast.Short(ConstantString.LOAD_NO_NETWORK); } pictures.addAll(pictureCacheUtil.getCacheByPage(page)); notifyDataSetChanged(); }
Example #7
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 #8
Source File: PictureAdapter.java From JianDan_OkHttp with Apache License 2.0 | 5 votes |
private void loadCache() { mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); mLoadFinisCallBack.loadFinish(null); PictureCache pictureCacheUtil = PictureCache.getInstance(mActivity); if (page == 1) { pictures.clear(); ShowToast.Short(ConstantString.LOAD_NO_NETWORK); } pictures.addAll(pictureCacheUtil.getCacheByPage(page)); notifyDataSetChanged(); }