Commit ff2a99c42a7f6e1a342c358d2880c59a192f58e9

Authored by 朱显松
1 parent db12e777

增加拦截器接口

app/src/main/java/com/cnlive/libs/demo/Java8Test.java
... ... @@ -15,10 +15,11 @@ import static com.cnlive.libs.base.util.LambdaUtil.stream;
15 15 */
16 16  
17 17 public class Java8Test {
18   - public static void test(Activity activity){
  18 + public static void test(Activity activity) {
19 19  
20 20  
21 21 List<String> list = Arrays.asList("1", "2", "3");
  22 + List<String> list2 = Arrays.asList("1", "3", "4");
22 23  
23 24 activity.findViewById(R.id.textView).setOnClickListener(view -> Log.e("DemoView", "view " + view.getClass().getName()));
24 25  
... ...
cnlive/build.gradle
... ... @@ -78,7 +78,7 @@ ext {
78 78 siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo'
79 79 gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo.git'
80 80  
81   - libraryVersion = '0.3.3'
  81 + libraryVersion = '0.3.4'
82 82  
83 83 developerId = 'CNlive'
84 84 developerName = 'Granzon'
... ...
cnlive/src/main/java/com/cnlive/libs/base/data/network/RetrofitUtil.java
... ... @@ -17,6 +17,7 @@ import javax.net.ssl.TrustManagerFactory;
17 17 import javax.net.ssl.X509TrustManager;
18 18  
19 19 import okhttp3.Cache;
  20 +import okhttp3.Interceptor;
20 21 import okhttp3.OkHttpClient;
21 22 import okhttp3.logging.HttpLoggingInterceptor;
22 23 import retrofit2.Retrofit;
... ... @@ -45,7 +46,7 @@ public class RetrofitUtil {
45 46 return getRestAPI(null, false, showLog, 5000, 5000, endpoint, service);
46 47 }
47 48  
48   - public static <T> T getRestAPI(Context context, boolean hasCache, boolean showLog, int readTimeout, int connectTimeout, String endpoint, Class<T> service) {
  49 + public static <T> T getRestAPI(Context context, boolean hasCache, boolean showLog, int readTimeout, int connectTimeout, String endpoint, Class<T> service, Interceptor... interceptors) {
49 50 RetrofitUtil.context = context;
50 51 OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient().newBuilder();
51 52  
... ... @@ -80,6 +81,11 @@ public class RetrofitUtil {
80 81 okHttpClientBuilder.cache(new Cache(context.getCacheDir(), 10 * 1024 * 1024));
81 82 }
82 83  
  84 + if (interceptors != null && interceptors.length > 0) {
  85 + for (Interceptor interceptor : interceptors)
  86 + okHttpClientBuilder.addInterceptor(interceptor);
  87 + }
  88 +
83 89 if (showLog) {
84 90 HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
85 91 httpLoggingInterceptor.setLevel(DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
... ...