mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-12-20 18:45:39 +08:00
update
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user