Git Product home page Git Product logo

rx-retrofit's Introduction

#Rx-Retrofit极简方式使用

为了方便快速集成,这里去掉回调base统一处理,结果返回服务器原始数据,在回调onNext中自行挑选gson解析第三方包处理

##依赖

根目录下build.gradle添加仓地址

	maven { url 'https://jitpack.io' }

依赖库

	compile 'com.github.wzgiceman:Rx-Retrofit:v1.0'

##使用 ###1.初始化RxRetrofitApp

public class MyApplication extends Application{

    @Override
    public void onCreate() {
        super.onCreate();
        //app和基础baseurl
        RxRetrofitApp.init(this,"http://www.izaodao.com/Api/");
    }
}

###2.初始化HttpManager对象 传递数据回调接口HttpOnNextListener和RxAppCompatActivity对象

HttpManager x=new HttpManager(this, this);

###3.初始api接口数据

一个api接口需要创建一个api类基础BaseApi,可动态设置缓存,加载框显示等处理,同时给定post请求接口参数

例如:

public class SubjectPostApi extends BaseApi {
    //    接口需要传入的参数 可自定义不同类型
    private boolean all;

    /**
     * 默认初始化需要给定回调和rx周期类
     * 可以额外设置请求设置加载框显示,回调等(可扩展)
     * 设置可查看BaseApi
     */
    public SubjectPostApi() {
        setShowProgress(true);
        setCancel(true);
        setMothed("AppFiftyToneGraph/videoLink");
        setCache(false);
    }

    @Override
    public Observable getObservable(Retrofit retrofit) {
        //可定义多个ApiService接口类,随意切换
        HttpTestService httpService = retrofit.create(HttpTestService.class);
        return httpService.getAllVedioBy(all);
    }

}

###4.发送请求

 manager.doHttpDeal(xxxApi);

###5.回调处理 HttpOnNextSubListener接口类抽象了两个回调方法

    /**
     * 成功后回调方法
     * @param resulte 这里是服务器返回的原始数据无任何处理
     * @param mothead
     */
   void onNext(String resulte,String mothead);

    /**
     * 失败
     * 失败或者错误方法
     * 自定义异常处理
     * @param e
     */
    void onError(ApiException e);

更多用法可以参考MainActivity

完整使用请查看demo


##其他版本

回调判断版本-Rxjava+ReTrofit+okHttp深入浅出-终极封装String方案

兄弟版本-Rxjava+ReTrofit+okHttp深入浅出-终极封装Gson方案

封装原理博客专栏:

Rxjava+ReTrofit+okHttp深入浅出-终极封装

rx-retrofit's People

Contributors

wzgiceman avatar

Watchers

 avatar

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.