问题是如何将这3个库合并到一个项目中?
- 创建一个OkHttpClient作为Picasso和Retrofit的后台层。
- 如何进行优先级更改(如Volley库中的分页)?
问题是如何将这3个库合并到一个项目中?
简而言之:
OkHttpClient okHttpClient = new OkHttpClient();
RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(okHttpClient)).build();
OkHttpDownloader downloader = new OkHttpDownloader(okHttpClient);
Picasso picasso = new Picasso.Builder(this).downloader(downloader).build();
我不认为在当前版本的Retrofit中有可能设置优先级。
对于OkHttpClient 3.0和Retrofit 2.0,做法如下:
OkHttpClient client = new OkHttpClient.Builder()
.cache(cache) // optional for adding cache
.networkInterceptors().add(loggingInterceptor) // optional for adding an interceptor
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.yourdomain.com/v1/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
Picasso picasso = Picasso.Builder(context)
.downloader(new OkHttp3Downloader(client))
.build();
优先级已经被移动到HTTP客户端的堆栈模型中,目前正在研究一个问题:https://github.com/square/okhttp/issues/1361
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2'
。 - CoolMind