package bawei.com.fjb.moni2.utils;
import java.util.concurrent.TimeUnit;
import bawei.com.fjb.moni2.common.Api;
import bawei.com.fjb.moni2.common.ApiInterface;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitUtils {
private static RetrofitUtils retrofitUtils;
private final ApiInterface apiInterface;
private OkHttpClient okHttpClient;
private RetrofitUtils(){
HttpLoggingInterceptor httpLoggingInterceptor=new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
okHttpClient=new OkHttpClient.Builder()
.connectTimeout(5,TimeUnit.SECONDS)
.readTimeout(5,TimeUnit.SECONDS)
.writeTimeout(5,TimeUnit.SECONDS)
.addInterceptor(httpLoggingInterceptor)
.build();
Retrofit retrofit=new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build();
apiInterface = retrofit.create(ApiInterface.class);
}
public static RetrofitUtils getInstance(){
if(retrofitUtils==null){
synchronized (RetrofitUtils.class){
if(retrofitUtils==null){
retrofitUtils=new RetrofitUtils();
}
}
}
return retrofitUtils;
}
public ApiInterface Api(){
return apiInterface;
}
}
package bawei.com.fjb.moni2.comment;
import android.app.Application;
import android.content.Context;
import com.facebook.drawee.backends.pipeline.Fresco;
public class App extends Application {
private static Context context;
@Override
public void onCreate() {
super.onCreate();
context=this;
Fresco.initialize(this);
}
public static Context getContext(){
return context;
}
}