File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
app/src/main/java/com/threetree/thttp
tthttp/src/main/java/com/threetree/tthttp Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ protected void onCreate(Bundle savedInstanceState)
2626 .baseUrl ("your baseUrl" )
2727 .addInterceptor (new HttpInterceptor ())
2828 .serviceClass (ApiService .class )
29+ .debug (true )
2930 .create ();
3031
3132 mDocPresenter = new DocPresenter (this ,this );
Original file line number Diff line number Diff line change 22
33import android .text .TextUtils ;
44
5+ import com .threetree .tthttp .interceptor .LogInterceptor ;
6+
57import java .util .concurrent .TimeUnit ;
68
79import okhttp3 .Interceptor ;
@@ -27,6 +29,7 @@ public class RetrofitManager<T> {
2729 private long mReadTimeout ;
2830 private long mWriteTimeout ;
2931 private boolean isReConnect ;
32+ private boolean isDebug ;
3033
3134 private RetrofitManager ()
3235 {
@@ -106,13 +109,25 @@ public RetrofitManager retryOnConnectionFailure(boolean reConnect)
106109 return this ;
107110 }
108111
112+ public RetrofitManager debug (boolean debug )
113+ {
114+ isDebug = debug ;
115+ return this ;
116+ }
117+
118+ public boolean isDebug ()
119+ {
120+ return isDebug ;
121+ }
122+
109123 public void create ()
110124 {
111125 if (TextUtils .isEmpty (mBaseUrl ))
112126 throw new NullPointerException ("baseUrl must not be null" );
113127 if (mServiceClass == null )
114128 throw new NullPointerException ("service must not be null" );
115129
130+ mClientBuilder .addInterceptor (new LogInterceptor ());
116131 mClientBuilder .connectTimeout (mConnectTimeout , TimeUnit .SECONDS );//超时
117132 mClientBuilder .readTimeout (mReadTimeout , TimeUnit .SECONDS );
118133 mClientBuilder .writeTimeout (mWriteTimeout , TimeUnit .SECONDS );
Original file line number Diff line number Diff line change 1+ package com .threetree .tthttp .interceptor ;
2+
3+ import android .util .Log ;
4+
5+ import com .threetree .tthttp .RetrofitManager ;
6+
7+ import java .io .IOException ;
8+
9+ import okhttp3 .Interceptor ;
10+ import okhttp3 .Response ;
11+
12+ /**
13+ * Created by Administrator on 2018/8/29.
14+ */
15+
16+ public class LogInterceptor implements Interceptor {
17+ @ Override
18+ public Response intercept (Chain chain ) throws IOException
19+ {
20+ Response originalResponse = chain .proceed (chain .request ());
21+ if (RetrofitManager .getInstence ().isDebug ())
22+ Log .d ("response" ,originalResponse .body ().string ());
23+ return originalResponse ;
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments