private Retrofit mRetrofit;
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Log.d("CodeHubServiceManager", message);
}
});
// 自定义gson解析(List不需要也能自己解析)
// Type showCaseType = new TypeToken<ArrayList<ShowCase>>(){}.getType();
// Gson gson = new GsonBuilder().registerTypeAdapter(showCaseType,
// new JsonDeserializer<ArrayList<ShowCase>>() {
// @Override
// public ArrayList<ShowCase> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
// return new Gson().fromJson(json, typeOfT);
// }
// }).create();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor) // 拦截器
.connectTimeout(20, TimeUnit.SECONDS)
.build();
mRetrofit = new Retrofit.Builder()
.baseUrl("http://trending.codehub-app.com")
.client(okHttpClient) // okHttpClient实例,不调用使用默认
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();