Retrofit2使用方法加MVP

1.写四大请求方式
Retrofit2使用方法加MVP
2.封装一个带有四大请求方式的工具类
Retrofit2使用方法加MVP
声明一个接口带有成功失败方法
Retrofit2使用方法加MVP
产生订阅
Retrofit2使用方法加MVP
传递头参
Retrofit2使用方法加MVP

Fresco设置缓存大小和路径
Fresco.initialize(this, ImagePipelineConfig.newBuilder(App.this)
.setMainDiskCacheConfig(DiskCacheConfig.newBuilder(this)
.setBaseDirectoryPath(Environment.getExternalStorageDirectory().getAbsoluteFile()
)
.setMaxCacheSize(1024102410).build())
.build());
Retrofit的缓存和日志拦截器
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request=chain.request();
String method = request.method();
Log.i(“method”,method);
String host = request.url().host();
Log.i(“method”,host);
return chain.proceed(request);
}
}).cache(new Cache(new File(path),1024*1024)).build();

Retrofit builder=new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(“http://172.17.8.100”)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();