OkHttp + Picasso + Retrofit

Ale*_*lex 6 android picasso retrofit okhttp

问题是如何在一个项目中组合所有这三个库?

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

Cat*_*san 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();
Run Code Online (Sandbox Code Playgroud)

我不认为有可能优先使用当前版本的Retrofit.


Yai*_*lka 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();
Run Code Online (Sandbox Code Playgroud)

优先级已经从堆栈模型向下移动到http客户端,并且正在研究一个问题:https://github.com/square/okhttp/issues/1361