1
0
mirror of https://github.com/WuXiaolong/AndroidMVPSample.git synced 2025-12-20 18:45:39 +08:00
This commit is contained in:
wuxiaolong
2017-06-02 16:37:57 +08:00
parent 77bfdb5d4a
commit 6d23bebca7
7 changed files with 16 additions and 13 deletions

View File

@@ -0,0 +1,42 @@
package com.wuxiaolong.androidmvpsample.retrofit;
import com.wuxiaolong.androidmvpsample.BuildConfig;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by WuXiaolong on 2016/3/24.
* github:https://github.com/WuXiaolong/
* 微信公众号:吴小龙同学
* 个人博客http://wuxiaolong.me/
*/
public class ApiClient {
public static Retrofit mRetrofit;
public static Retrofit retrofit() {
if (mRetrofit == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (BuildConfig.DEBUG) {
// Log信息拦截器
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
//设置 Debug Log 模式
builder.addInterceptor(loggingInterceptor);
}
OkHttpClient okHttpClient = builder.build();
mRetrofit = new Retrofit.Builder()
.baseUrl(ApiStores.API_SERVER_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.client(okHttpClient)
.build();
}
return mRetrofit;
}
}