com.socks.jiandan.net.RequestManager Java Examples

The following examples show how to use com.socks.jiandan.net.RequestManager. 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 with Apache License 2.0 6 votes vote down vote up
private void loadData() {

        RequestManager.addRequest(new Request4Picture(Picture.getRequestUrl(mType, page),
                new Response.Listener<ArrayList<Picture>>
                        () {
                    @Override
                    public void onResponse(ArrayList<Picture> response) {
                        getCommentCounts(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                mLoadFinisCallBack.loadFinish(null);
            }
        }), mActivity);
    }
 
Example #2
Source File: PictureAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 6 votes vote down vote up
private void loadData() {

        RequestManager.addRequest(new Request4Picture(Picture.getRequestUrl(mType, page),
                new Response.Listener<ArrayList<Picture>>
                        () {
                    @Override
                    public void onResponse(ArrayList<Picture> response) {
                        getCommentCounts(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                mLoadFinisCallBack.loadFinish(null);
            }
        }), mActivity);
    }
 
Example #3
Source File: BaseFragment.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    JDApplication.getRefWatcher(getActivity()).watch(this);
    RequestManager.cancelAll(this);
    ImageLoadProxy.getImageLoader().clearMemoryCache();
}
 
Example #4
Source File: PictureAdapter.java    From JianDan with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: JokeAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
private void loadData() {
    RequestManager.addRequest(new Request4Joke(Joke.getRequestUrl(page),
            new Response.Listener<ArrayList<Joke>>
                    () {
                @Override
                public void onResponse(ArrayList<Joke> response) {
                    getCommentCounts(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            mLoadFinisCallBack.loadFinish(null);
        }
    }), mActivity);
}
 
Example #6
Source File: BaseFragment.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    JDApplication.getRefWatcher(getActivity()).watch(this);
    RequestManager.cancelAll(this);
    ImageLoadProxy.getImageLoader().clearMemoryCache();
}
 
Example #7
Source File: PictureAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
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: JokeAdapter.java    From JianDan with Apache License 2.0 5 votes vote down vote up
private void loadData() {
    RequestManager.addRequest(new Request4Joke(Joke.getRequestUrl(page),
            new Response.Listener<ArrayList<Joke>>
                    () {
                @Override
                public void onResponse(ArrayList<Joke> response) {
                    getCommentCounts(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            mLoadFinisCallBack.loadFinish(null);
        }
    }), mActivity);
}
 
Example #9
Source File: VideoAdapter.java    From JianDan_OkHttpWithVolley with 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 #10
Source File: BaseFragment.java    From JianDan with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    JDApplication.getRefWatcher(getActivity()).watch(this);
    RequestManager.cancelAll(this);
    ImageLoadProxy.getImageLoader().clearMemoryCache();
}
 
Example #11
Source File: VideoAdapter.java    From JianDan with 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 #12
Source File: BaseActivity.java    From JianDan_OkHttp with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    JDApplication.getRefWatcher(this).watch(this);
    RequestManager.cancelAll(this);
}
 
Example #13
Source File: FreshNewsAdapter.java    From JianDan with Apache License 2.0 4 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            RequestManager.addRequest(new Request4FreshNews(FreshNews.getUrlFreshNews(page),
                    new Response.Listener<ArrayList<FreshNews>>() {
                        @Override
                        public void onResponse(ArrayList<FreshNews> response) {

                            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                            mLoadFinisCallBack.loadFinish(null);

                            if (page == 1) {
                                mFreshNews.clear();
                                FreshNewsCache.getInstance(mActivity).clearAllCache();
                            }

                            mFreshNews.addAll(response);
                            notifyDataSetChanged();

                            FreshNewsCache.getInstance(mActivity).addResultCache(JSONParser.toString(response),
                                    page);
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                    mLoadFinisCallBack.loadFinish(null);
                }
            }), mActivity);
        } else {
            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            mLoadFinisCallBack.loadFinish(null);

            if (page == 1) {
                mFreshNews.clear();
                ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
            }

            mFreshNews.addAll(FreshNewsCache.getInstance(mActivity).getCacheByPage(page));
            notifyDataSetChanged();
        }

    }
 
Example #14
Source File: VideoAdapter.java    From JianDan with 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 File: CommentAdapter.java    From JianDan with Apache License 2.0 4 votes vote down vote up
public void loadData() {
    RequestManager.addRequest(new Request4CommentList(Commentator.getUrlCommentList(thread_key), new Response
            .Listener<ArrayList<Commentator>>() {
        @Override
        public void onResponse(ArrayList<Commentator> response) {

            if (response.size() == 0) {
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_NONE, null);
            } else {
                commentators.clear();

                ArrayList<Commentator> hotCommentator = new ArrayList<>();
                ArrayList<Commentator> normalComment = new ArrayList<>();

                //添加热门评论
                for (Commentator commentator : response) {
                    if (commentator.getTag().equals(Commentator.TAG_HOT)) {
                        hotCommentator.add(commentator);
                    } else {
                        normalComment.add(commentator);
                    }
                }

                //添加热门评论标签
                if (hotCommentator.size() != 0) {
                    Collections.sort(hotCommentator);
                    Commentator hotCommentFlag = new Commentator();
                    hotCommentFlag.setType(Commentator.TYPE_HOT);
                    hotCommentator.add(0, hotCommentFlag);
                    commentators.addAll(hotCommentator);
                }

                //添加最新评论及标签
                if (normalComment.size() != 0) {
                    Commentator newCommentFlag = new Commentator();
                    newCommentFlag.setType(Commentator.TYPE_NEW);
                    commentators.add(newCommentFlag);
                    Collections.sort(normalComment);
                    commentators.addAll(normalComment);
                }

                notifyDataSetChanged();
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
        }
    }, new LoadFinishCallBack() {
        @Override
        public void loadFinish(Object obj) {
            thread_id = (String) obj;
        }
    }), mActivity);
}
 
Example #16
Source File: TestClass.java    From JianDan with Apache License 2.0 4 votes vote down vote up
protected void executeRequest(Request<?> request) {
	RequestManager.addRequest(request, this);
}
 
Example #17
Source File: TestClass.java    From JianDan_OkHttp with Apache License 2.0 4 votes vote down vote up
protected void executeRequest(Request<?> request) {
	RequestManager.addRequest(request, this);
}
 
Example #18
Source File: BaseActivity.java    From JianDan_OkHttp with Apache License 2.0 4 votes vote down vote up
public void executeRequest(Request<?> request) {
    RequestManager.addRequest(request, this);
}
 
Example #19
Source File: BaseFragment.java    From JianDan_OkHttp with Apache License 2.0 4 votes vote down vote up
protected void executeRequest(Request request) {
    RequestManager.addRequest(request, this);
}
 
Example #20
Source File: BaseActivity.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    JDApplication.getRefWatcher(this).watch(this);
    RequestManager.cancelAll(this);
}
 
Example #21
Source File: JokeAdapter.java    From JianDan with Apache License 2.0 4 votes vote down vote up
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 #22
Source File: BaseFragment.java    From JianDan with Apache License 2.0 4 votes vote down vote up
protected void executeRequest(Request request) {
    RequestManager.addRequest(request, this);
}
 
Example #23
Source File: BaseActivity.java    From JianDan with Apache License 2.0 4 votes vote down vote up
public void executeRequest(Request<?> request) {
    RequestManager.addRequest(request, this);
}
 
Example #24
Source File: BaseActivity.java    From JianDan with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    JDApplication.getRefWatcher(this).watch(this);
    RequestManager.cancelAll(this);
}
 
Example #25
Source File: TestClass.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
protected void executeRequest(Request<?> request) {
	RequestManager.addRequest(request, this);
}
 
Example #26
Source File: CommentAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
public void loadData() {
    RequestManager.addRequest(new Request4CommentList(Commentator.getUrlCommentList(thread_key), new Response
            .Listener<ArrayList<Commentator>>() {
        @Override
        public void onResponse(ArrayList<Commentator> response) {

            if (response.size() == 0) {
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_NONE, null);
            } else {
                commentators.clear();

                ArrayList<Commentator> hotCommentator = new ArrayList<>();
                ArrayList<Commentator> normalComment = new ArrayList<>();

                //添加热门评论
                for (Commentator commentator : response) {
                    if (commentator.getTag().equals(Commentator.TAG_HOT)) {
                        hotCommentator.add(commentator);
                    } else {
                        normalComment.add(commentator);
                    }
                }

                //添加热门评论标签
                if (hotCommentator.size() != 0) {
                    Collections.sort(hotCommentator);
                    Commentator hotCommentFlag = new Commentator();
                    hotCommentFlag.setType(Commentator.TYPE_HOT);
                    hotCommentator.add(0, hotCommentFlag);
                    commentators.addAll(hotCommentator);
                }

                //添加最新评论及标签
                if (normalComment.size() != 0) {
                    Commentator newCommentFlag = new Commentator();
                    newCommentFlag.setType(Commentator.TYPE_NEW);
                    commentators.add(newCommentFlag);
                    Collections.sort(normalComment);
                    commentators.addAll(normalComment);
                }

                notifyDataSetChanged();
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
        }
    }, new LoadFinishCallBack() {
        @Override
        public void loadFinish(Object obj) {
            thread_id = (String) obj;
        }
    }), mActivity);
}
 
Example #27
Source File: VideoAdapter.java    From JianDan_OkHttpWithVolley with 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 #28
Source File: FreshNewsAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            RequestManager.addRequest(new Request4FreshNews(FreshNews.getUrlFreshNews(page),
                    new Response.Listener<ArrayList<FreshNews>>() {
                        @Override
                        public void onResponse(ArrayList<FreshNews> response) {

                            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                            mLoadFinisCallBack.loadFinish(null);

                            if (page == 1) {
                                mFreshNews.clear();
                                FreshNewsCache.getInstance(mActivity).clearAllCache();
                            }

                            mFreshNews.addAll(response);
                            notifyDataSetChanged();

                            FreshNewsCache.getInstance(mActivity).addResultCache(JSONParser.toString(response),
                                    page);
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                    mLoadFinisCallBack.loadFinish(null);
                }
            }), mActivity);
        } else {
            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            mLoadFinisCallBack.loadFinish(null);

            if (page == 1) {
                mFreshNews.clear();
                ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
            }

            mFreshNews.addAll(FreshNewsCache.getInstance(mActivity).getCacheByPage(page));
            notifyDataSetChanged();
        }

    }
 
Example #29
Source File: JokeAdapter.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
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 #30
Source File: BaseFragment.java    From JianDan_OkHttpWithVolley with Apache License 2.0 4 votes vote down vote up
protected void executeRequest(Request request) {
    RequestManager.addRequest(request, this);
}