From dcc3e8c817d38fe85e8d7a8fb8420b9dc33cddfe Mon Sep 17 00:00:00 2001 From: juyao Date: Fri, 14 Dec 2018 10:56:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BD=91=E7=BB=9C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=8B=A6=E6=88=AA=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jmvp/src/main/java/com/juyao/jmvp/net/JApi.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jmvp/src/main/java/com/juyao/jmvp/net/JApi.kt b/jmvp/src/main/java/com/juyao/jmvp/net/JApi.kt index ffc976a..3b3f364 100644 --- a/jmvp/src/main/java/com/juyao/jmvp/net/JApi.kt +++ b/jmvp/src/main/java/com/juyao/jmvp/net/JApi.kt @@ -1,5 +1,6 @@ package com.juyao.jmvp.net +import okhttp3.Interceptor import okhttp3.OkHttpClient import retrofit2.Retrofit import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory @@ -10,9 +11,13 @@ import java.util.concurrent.TimeUnit * Created by juyao on 2017/11/22. */ object JApi { + var interceptor: Interceptor?=null val DEFAULT_TIMEOUT: Long = 20 fun getRetrofit(baseUrl: String): Retrofit { - val httpClientBuilder: OkHttpClient.Builder = OkHttpClient.Builder() + val httpClientBuilder: OkHttpClient.Builder = when(interceptor){ + null->OkHttpClient.Builder() + else->OkHttpClient.Builder().addInterceptor(interceptor) + } httpClientBuilder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) return Retrofit.Builder(). client(httpClientBuilder.build()). @@ -23,4 +28,5 @@ object JApi { } + } \ No newline at end of file