Java Code Examples for com.socks.jiandan.cache.JokeCache
The following examples show how to use
com.socks.jiandan.cache.JokeCache.
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: JokeAdapter.java License: Apache License 2.0 | 6 votes |
private void loadCache() { Subscription subscription = Observable .create((Observable.OnSubscribe<ArrayList<Joke>>) subscriber -> { subscriber.onNext(JokeCache.getInstance(mActivity).getCacheByPage(page)); subscriber.onCompleted(); }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(jokes -> { if (page == 1) { mJokes.clear(); ToastHelper.Short(ConstantString.LOAD_NO_NETWORK); } }) .subscribe(jokes -> { mJokes.addAll(jokes); notifyDataSetChanged(); mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); }); mActivity.addSubscription(subscription); }
Example #2
Source Project: JianDan_OkHttpWithVolley Author: ZhaoKaiQiang File: JokeAdapter.java License: Apache License 2.0 | 5 votes |
private void loadCache() { mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); JokeCache jokeCacheUtil = JokeCache.getInstance(mActivity); if (page == 1) { mJokes.clear(); ShowToast.Short(ConstantString.LOAD_NO_NETWORK); } mJokes.addAll(jokeCacheUtil.getCacheByPage(page)); notifyDataSetChanged(); }
Example #3
Source Project: JianDan Author: ZhaoKaiQiang File: JokeAdapter.java License: Apache License 2.0 | 5 votes |
private void loadCache() { mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); JokeCache jokeCacheUtil = JokeCache.getInstance(mActivity); if (page == 1) { mJokes.clear(); ShowToast.Short(ConstantString.LOAD_NO_NETWORK); } mJokes.addAll(jokeCacheUtil.getCacheByPage(page)); notifyDataSetChanged(); }
Example #4
Source Project: JianDanRxJava Author: ZhaoKaiQiang File: JokeAdapter.java License: Apache License 2.0 | 5 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); } JDApi.getCommentNumber(url) .observeOn(Schedulers.io()) .doOnNext(commentNumbers -> { if (page == 1) { mJokes.clear(); JokeCache.getInstance(mActivity).clearAllCache(); } JokeCache.getInstance(mActivity).addResultCache(GsonHelper.toString(jokes), page); }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(commentNumbers -> { for (int i = 0; i < jokes.size(); i++) { jokes.get(i).setComment_counts(commentNumbers.get(i).comments + ""); } mJokes.addAll(jokes); notifyDataSetChanged(); mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); }, e -> { mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET); mLoadFinisCallBack.loadFinish(null); KLog.e(e); }); }
Example #5
Source Project: JianDan_OkHttp Author: ZhaoKaiQiang File: JokeAdapter.java License: Apache License 2.0 | 5 votes |
private void loadCache() { mLoadFinisCallBack.loadFinish(null); mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null); JokeCache jokeCacheUtil = JokeCache.getInstance(mActivity); if (page == 1) { mJokes.clear(); ShowToast.Short(ConstantString.LOAD_NO_NETWORK); } mJokes.addAll(jokeCacheUtil.getCacheByPage(page)); notifyDataSetChanged(); }
Example #6
Source Project: JianDan_OkHttpWithVolley Author: ZhaoKaiQiang File: JokeAdapter.java License: 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 #7
Source Project: JianDan Author: ZhaoKaiQiang File: JokeAdapter.java License: 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); }