Android链式请求框架(RequestChain)

2019-07-25  本文已影响0人  ACap

RequestChain是一个链式请求框架,基于EventChain+Retrofit2+Rxjava2+OkHttp3搭建

简单使用

// 用户登陆信息
public static final class LoginBean{ int userId; }

public void login(){
    /*
      ApiManager.getApi().login():通过Retrofit生成请求
      getLifecycle():Activity和Fragment的生命周期观察者,当页面退出的时候自定停止请求
    */
    new RequestEvent<LoginBean>(ApiManager.getApi().login(), getLifecycle())
                .addOnRequestListener((OnRequestSucceedListener<LoginBean>) s -> mTV_Text.setText(new Gson().toJson(s))) //请求成功监听
                .addOnEventListener(new OnEventDelayWaitBar(this).setShowThrowable(true)) /*请求进度提示监听*/
                .start();

 }

关于链式调用 参考 EventChain

上一篇 下一篇

猜你喜欢

热点阅读