RxJava

public class OkHttp {
    private static OkHttp instance;
    private final OkHttpClient okHttpClient;

    private OkHttp() {
        okHttpClient = new OkHttpClient.Builder()
                .writeTimeout(5000, TimeUnit.MILLISECONDS)
                .connectTimeout(5000, TimeUnit.MILLISECONDS)
                .readTimeout(5000, TimeUnit.MILLISECONDS)
                .addInterceptor(new HttpLoggingInterceptor())
                .addInterceptor(new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
                    @Override
                    public void log(String message) {
                        if (message.startsWith("{") || message.startsWith("[")) {
                            Logger.json(message);
                        } else {
                            Logger.d(message);
                        }
                    }
                }).setLevel(HttpLoggingInterceptor.Level.BODY)).build();
    }

    public static OkHttp getInstance() {
        if (instance==null){
            synchronized (OkHttp.class){
                if (instance==null){
                    instance=new OkHttp();
                }
            }
        }
        return instance;
    }

    public OkHttpClient okHttpClient(){
        return okHttpClient;
    }
public class RetrofitManager {
    private static RetrofitManager instance;
    private final Retrofit retrofit;

    private RetrofitManager() {
        retrofit = new Retrofit.Builder().baseUrl(Api.Show_Data)
                .client(OkHttp.getInstance().okHttpClient())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public static RetrofitManager getInstance() {
        if (instance==null){
            synchronized (RetrofitManager.class){
                if (instance==null){
                    instance=new RetrofitManager();
                }
            }
        }
        return instance;
    }
    public <T> T create(final Class<T> service) {
        T t = retrofit.create(service);
        return t;
    }
    public ApiService apiService(){
        ApiService apiService = retrofit.create(ApiService.class);
        return apiService;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值