Giter Site home page Giter Site logo

volley-okhttp-rebulid's Introduction

RxVolley

基于谷歌volley和OkHttp3网络请求库的重构版本,同时增加文件from上传功能以及网络请求本地cache功能,将请求的cache控制在request中.

sample中有简单的网络库封装逻辑.同时数据解析器会放在线程中执行,这样避免数据在UI中解析造成卡顿,同时有多文件下载.

同时拓展了大文件下载,支持断点续传以及暂停,暂时只支持一个个文件队列下载, 同时使用了intent-service,下载完成后会自动关闭service.

同时修复了http 请求返回eTag 304 无法使用的bug。

增加RxJava和RxJava2 Adapter,支持链式写法。

Usage

Add this line to your build.gradle file under your module directory.

compile 'com.github.leifzhang:VolleyLib:0.5.3'

compile 'com.github.leifzhang:DownloadLib:0.5.3'

compile 'com.github.leifzhang:RxAdapter:0.5.3'
or
compile 'com.github.leifzhang:Rx2Adapter:0.5.3'

How to use it

    StringRequest request = new StringRequest(url);
    request.setRequestListener(new RequestResponse.Listener<NetResponse>() {
            @Override
            public void onResponse(NetResponse response) {
            
            }
        }).setErrorListener(new RequestResponse.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
              
            }
        }).setMethod(Method()).setHeader(getHeader()).setApiParser(getParser())
        .setCacheTime(cacheTime).setIsRefreshNeed(isNeedRefresh);
        request.setRequestBody(getRequestBody());

Step 1

配置默认文件 '必须设置'

        DownloadConfig downloadConfig = new DownloadConfig.Builder().setDownloadDb(new DataBase()).builder();
        DownloadManager.getInstance().setConfig(downloadConfig);

Step 2

下载文件只要使用这个就会自动开启

   DownloadManager.setDownloadModel(downloadUrl, context); 

暂停只需要改变model状态就能完成

   DownloadModel model = DownloadManager.getInstance()
                            .getModel(itemEntity.getDownloadUrl());
   if (model.getState() == DownloadConstants.DOWNLOADING) {
      model.setState(DownloadConstants.DOWNLOAD_PAUSE);
   }

License

MIT

volley-okhttp-rebulid's People

Contributors

leifzhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bxunzhao

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.