6

问题是如何将所有这3 个库组合到一个项目中?

  • 让一个 OkHttpClient 作为 Picasso 和 Retrofit 的背景层。
  • 如何在 Volley lib 中进行优先级更改。(用于分页)?
4

2 回答 2

20

简而言之:

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 不可能有优先级。

于 2014-05-23T14:43:40.397 回答
8

对于 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

于 2016-01-15T21:50:51.150 回答