//interface拼接接口
package com.example.lianxi_yue2.APP;
import com.example.lianxi_yue2.modl.Rv_bean;
import io.reactivex.Flowable;
import retrofit2.http.GET;
/**
* Created by Administrator on 2017/12/22.
*/
public interface Api_inter {
@GET("product/searchProducts?keywords=%E7%AC%94%E8%AE%B0%E6%9C%AC&page=1")
Flowable<Rv_bean> Api_inter_hou();
}
//解析数据方法
package com.example.lianxi_yue2.modl;
import com.example.lianxi_yue2.APP.Api_class;
import com.example.lianxi_yue2.APP.Api_inter;
import com.example.lianxi_yue2.presenter.Rv_ipresenter;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by Administrator on 2017/12/22.
*/
public class Rv_shoumodl implements Rv_imodl{
@Override
public void getmyimold(final Rv_ipresenter rv_ipresenter) {
//Retrofit方法
Retrofit retrofit = new Retrofit.Builder().baseUrl(Api_class.Api_class_qian)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
//获取拼接后半部分
Flowable<Rv_bean> inter_hou = retrofit.create(Api_inter.class).Api_inter_hou();
//Retrofit方法结合Rxjava解析方法
inter_hou.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Rv_bean>() {
@Override
public void accept(Rv_bean rv_bean) throws Exception {
rv_ipresenter.getmyipresenter(rv_bean);
}
});
}
}
//依赖
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'//Retrofit2所需要的包
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'//ConverterFactory的Gson依赖包
compile 'com.squareup.retrofit2:converter-scalars:2.0.0-beta4'//ConverterFactory的String依赖包
compile 'io.reactivex.rxjava2:rxjava:2.1.3'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'de.greenrobot:eventbus:3.0.0-beta1'
compile 'com.facebook.fresco:fresco:0.11.0'