package com.example.myapplication.mvvm.http; import java.util.concurrent.TimeUnit; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; public class RetrofitManager { public RetrofitManager() { } private static RetrofitManager retrofitManager; public static RetrofitManager getInstance() { if (retrofitManager == null) { retrofitManager = new RetrofitManager(); } return retrofitManager; } private Retrofit retrofit; public Retrofit createRetrofit() { OkHttpClient ok = new OkHttpClient.Builder() .writeTimeout(5, TimeUnit.MINUTES) .connectTimeout(5, TimeUnit.MINUTES) .readTimeout(5, TimeUnit.MINUTES) .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) .build(); if (retrofit == null) { retrofit = new Retrofit.Builder() .client(ok) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl("http://10.161.9.80:7012/") .build(); } return retrofit; } }
mvvm/RetrofitManager
最新推荐文章于 2024-12-25 08:33:33 发布