package com.whk.moni.utils; import com.whk.moni.inter.APIService; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; public class HttpUtils { private static volatile HttpUtils insetence; private Retrofit retrofit; private APIService service; private HttpUtils(String url){ //http过滤 HttpLoggingInterceptor httpInterceptor = new HttpLoggingInterceptor(); httpInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient build = new OkHttpClient.Builder() .addInterceptor(httpInterceptor) .build(); retrofit = new Retrofit.Builder() .client(build) .baseUrl(url) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); service = retrofit.create(APIService.class); } public static HttpUtils getInsetence(String url) { if (insetence==null){ synchronized (HttpUtils.class){ if (null==insetence){ insetence=new HttpUtils(url); } } } return insetence; } public APIService getService() { return service; } }
Retrofit+mvp
最新推荐文章于 2024-04-05 14:06:30 发布