package com.github.hunter0x7c7.sync.model.server.net; /* * @Auther: Hunter * @Date: 2022/12/05/15:00 * @Description: */ import okhttp3.OkHttpClient; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; import java.util.concurrent.TimeUnit; public class DownPictureFactory { // private static final String BASE_API = "http://api2.diction.com/Api/"; private static final String BASE_API = "http://epdapi2.diction.diexun.com/Api/"; private static final int CONNECT_TIME_OUT = 60;//连接超时时长x秒 private static final int READ_TIME_OUT = 60;//读数据超时时长x秒 private static final int WRITE_TIME_OUT = 60;//写数据接超时时长x秒 private static DownPictureFactory mInstance = null; private Retrofit mApiService; public static DownPictureFactory getInstance() { if (mInstance == null) { synchronized (DownPictureFactory.class) { if (mInstance == null) { mInstance = new DownPictureFactory(); } } } return mInstance; } private DownPictureFactory() { // GsonConverterFactory mConverterFactory = GsonConverterFactory.create(new GsonBuilder().create()); // RxJava2CallAdapterFactory mAdapterFactory = RxJava2CallAdapterFactory.create(); mApiService = new Retrofit.Builder() .baseUrl(BASE_API) .client(configOkHttpClient()) .addConverterFactory(GsonConverterFactory.create()) // json解析 .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addCallAdapterFactory(mAdapterFactory) // 支持rxjava .build(); } private OkHttpClient configOkHttpClient() { OkHttpClient.Builder mBuilder = new OkHttpClient().newBuilder(); mBuilder.connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS); mBuilder.writeTimeout(WRITE_TIME_OUT, TimeUnit.SECONDS); mBuilder.readTimeout(READ_TIME_OUT, TimeUnit.SECONDS); // mBuilder.addInterceptor(new BaseUrlInterceptor()); /*if (AppManager.getInstance().isShowHttpLog) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); mBuilder.addInterceptor(logging); }*/ return mBuilder.build(); } public Retrofit getRetrofit(){ return mApiService; } }