MyAndroidFrame-net

使用了rxjava, rxandroid,retrofit

构建retroiftmodel

public class RetrofitModel {
private static Retrofit mRetrofit;
private static ServiceAPI mServiceAPI;

public static ServiceAPI getServiceAPI() {
if (null == mServiceAPI) {
KLog.w("UID : " + HeadersInterceptor.UID);
KLog.w("token : " + HeadersInterceptor.TOKEN);
mServiceAPI = getRetrofit().create(ServiceAPI.class);
}
return mServiceAPI;
}

private static Retrofit getRetrofit() {
if (null == mRetrofit) {
//设置okhttp
OkHttpClient.Builder mOkHttpClientBuilder = new OkHttpClient.Builder();
if (BuildConfig.DEBUG) {
//DEBUG模式打印Log
LogInterceptor logInterceptor = new LogInterceptor()
.setLogTag(Config.NET_LOG_TAG);
mOkHttpClientBuilder
.addInterceptor(logInterceptor);
mOkHttpClientBuilder.addInterceptor(new HeadersInterceptor());
mOkHttpClientBuilder.connectTimeout(10, TimeUnit.SECONDS);
mOkHttpClientBuilder.readTimeout(20, TimeUnit.SECONDS);
mOkHttpClientBuilder.writeTimeout(20, TimeUnit.SECONDS);
mOkHttpClientBuilder.retryOnConnectionFailure(true);

mRetrofit = new Retrofit.Builder().baseUrl(Config.BASE_URL).
addCallAdapterFactory(RxJavaCallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create())
.client(mOkHttpClientBuilder.build())
.build();
}
}
return mRetrofit;
}
}

上面重点是DEBUG模式下打印LOG,显示UID token

你可能感兴趣的:(MyAndroidFrame-net)