Skip to content

Commit

Permalink
新增网络请求拦截器
Browse files Browse the repository at this point in the history
  • Loading branch information
juyao committed Dec 14, 2018
1 parent 0e241a9 commit dcc3e8c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion jmvp/src/main/java/com/juyao/jmvp/net/JApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.juyao.jmvp.net

import okhttp3.Interceptor
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
Expand All @@ -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()).
Expand All @@ -23,4 +28,5 @@ object JApi {
}



}

0 comments on commit dcc3e8c

Please sign in to comment.