Hunter0x7c7
2023-08-11 198dd6e1b210758867eed417bf6e00ba733d47c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
    }
 
 
}