RxNetWork

项目地址:7449/RxNetWork
简介:rxjava1.x and retrofit2.x 版本的网络请求简化库,以及 RxBus
更多:作者   提 Bug   示例 APK   
标签:
RxJava-NetWork-retrofit2-RxBus-okhttp-gson-

this is android network ,and RxBus

android 网络请求简化库

分支

master

rxJava1.x and retrofit2

gradle
compile 'com.ydevelop:rxNetWork:0.0.5'

rx2NetWork

rxJava2.x and retrofit2

gradle
compile 'com.ydevelop:rx2NetWork:0.0.1'

rxJsoupNetWork

rxJava1.x and jsoup

gradle
compile 'com.ydevelop:rxJsoupNetWork:0.0.1'

rx2JsoupNetWork

rxJava2.x and jsoup

gradle
compile 'com.ydevelop:rx2JsoupNetWork:0.0.1'

RxNetWork 项目试用:

https://github.com/7449/ZLSimple

RxJsoupNetWork 项目试用

https://github.com/7449/JsoupSample

rx2NetWork README

rxJsoupNetWork README

rx2JsoupNetWork README:

rxNetWork README:

建议初始化:

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        RxNetWork
                .getInstance()
                .setBaseUrl("your base url")
                ...;
    }

}

支持一下自定义(如果不想使用内置类库可自定义):

Gson,

OkHttpClient

Converter.Factory

CallAdapter.Factory

使用方法:

这里假设在Application里已经自定义好BaseUrl;

getApi 需要两个参数,一个Observable还有一个网络回调RxNetWorkListener

    RxNetWork.getInstance().getApi(

            RxNetWork.observable(Api.ZLService.class).getList("", 20, 0),

            new RxNetWorkListener<List<ListModel>>() {
                @Override
                public void onNetWorkStart() {

                }

                @Override
                public void onNetWorkError(Throwable e) {

                }

                @Override
                public void onNetWorkCompleted() {

                }

                @Override
                public void onNetWorkSuccess(List<ListModel> data) {

                }
            }

    );

缓存:

如果使用默认的okhttp,缓存需要如下配置

    RxNetWork
            .getInstance()
            .setCache()
            .setCacheInterceptor();

具体可参考:https://github.com/7449/AndroidDevelop/blob/master/codeKK/src/main/java/framework/network/NetWork.java

配置 Header:

如果使用默认的okhttp,配置 Header 需要如下操作:

    RxNetWork
            .getInstance()
            .setHeaderInterceptor();

配置 Log

如果使用默认的okhttp,配置 Log 需要如下操作:

    RxNetWork
            .getInstance()
            .setLogInterceptor();

取消当前订阅

RxSubscriptionManager.getInstance().unSubscription();

取消所有订阅

RxSubscriptionManager.getInstance().clearSubscription();

RxBus 使用:

发送消息:

    RxBus.getInstance().send("tag","message");
    RxBus.getInstance().send("tag");

接受消息:

    RxBus.getInstance().toSubscription("tag", String.class, new RxBusCallBack<String>() {
        @Override
        public void onNext(String data) {

        }

        @Override
        public void onError(Throwable throwable) {

        }
    });

解绑:

RxBus.getInstance().unregister("tag");
Android 开发经验分享
Android 开发经验分享