rxjava记录

//p
model.LOGIN(phone,pwd)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer() {
                    @Override
                    public void accept(Login_Bean login_bean) throws Exception {
                          view_mvp.Login(login_bean);
                    }
                });
//m
public Observable LOGIN(String phone, String pwd) {
        I_Urls i_urls = NetWork_Retrofit.getInstance().create(I_Urls.class);
        Observable login_beanObservable = i_urls.LOGIN_BEAN_OBSERVABLE(phone, pwd);

        return login_beanObservable;
    }
//utils
private static NetWork_Retrofit netWork_retrofit;
    private OkHttpClient okHttpClient;
    private Retrofit retrofit;
    private Retrofit retrofit1;

    private NetWork_Retrofit(){
        init();
    }
    public static NetWork_Retrofit getInstance() {
        synchronized (NetWork_Retrofit.class){
                        if( netWork_retrofit== null){
                            return netWork_retrofit= new NetWork_Retrofit();
                        }
                    }
                    return netWork_retrofit;
    }
    private void init(){
        okHttpClient = new OkHttpClient.Builder()
                .readTimeout(5000, TimeUnit.MILLISECONDS)
                .connectTimeout(5000, TimeUnit.MILLISECONDS)
                .writeTimeout(5000, TimeUnit.MILLISECONDS)
                .build();

        retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(Urls.Url)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }
    public  T create(Class service){
        return retrofit.create(service);
    }

你可能感兴趣的:(记录)