3 Ревизии 883f264b20 ... fddba6f661

Автор SHA1 Съобщение Дата
  皇甫睿欣 fddba6f661 提交loading的查漏补缺 преди 7 години
  皇甫睿欣 ed064ce26d 提交拦截器修改 преди 7 години
  皇甫睿欣 4f24fd8b96 提交rxjava修改 преди 7 години

+ 1 - 0
laraver-core/build.gradle

@@ -82,4 +82,5 @@ dependencies {
82 82
     compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
83 83
     compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
84 84
 
85
+
85 86
 }

+ 2 - 1
laraver-core/src/main/java/com/kuxuan/laraver/delegates/web/client/WebViewClientImpl.java

@@ -10,7 +10,8 @@ import com.kuxuan.laraver.app.Laraver;
10 10
 import com.kuxuan.laraver.delegates.IPageLoadListener;
11 11
 import com.kuxuan.laraver.delegates.web.WebDelegate;
12 12
 import com.kuxuan.laraver.delegates.web.route.Router;
13
-import com.kuxuan.laraver.ui.LaraverLoader;
13
+
14
+import com.kuxuan.laraver.ui.loader.LaraverLoader;
14 15
 import com.kuxuan.laraver.util.log.LaraverLogger;
15 16
 import com.kuxuan.laraver.util.storage.LaraverPreference;
16 17
 

+ 3 - 2
laraver-core/src/main/java/com/kuxuan/laraver/net/RestClient.java

@@ -9,8 +9,9 @@ import com.kuxuan.laraver.net.callback.IRequest;
9 9
 import com.kuxuan.laraver.net.callback.ISuccess;
10 10
 import com.kuxuan.laraver.net.callback.RequestCallbacks;
11 11
 import com.kuxuan.laraver.net.download.DownloadHandler;
12
-import com.kuxuan.laraver.ui.LaraverLoader;
13
-import com.kuxuan.laraver.ui.LoaderStyle;
12
+import com.kuxuan.laraver.ui.loader.LaraverLoader;
13
+import com.kuxuan.laraver.ui.loader.LoaderStyle;
14
+
14 15
 
15 16
 import okhttp3.MediaType;
16 17
 import okhttp3.MultipartBody;

+ 2 - 1
laraver-core/src/main/java/com/kuxuan/laraver/net/RestClientBuilder.java

@@ -6,7 +6,8 @@ import com.kuxuan.laraver.net.callback.IError;
6 6
 import com.kuxuan.laraver.net.callback.IFailure;
7 7
 import com.kuxuan.laraver.net.callback.IRequest;
8 8
 import com.kuxuan.laraver.net.callback.ISuccess;
9
-import com.kuxuan.laraver.ui.LoaderStyle;
9
+import com.kuxuan.laraver.ui.loader.LoaderStyle;
10
+
10 11
 
11 12
 import java.io.File;
12 13
 import java.util.Map;

+ 12 - 1
laraver-core/src/main/java/com/kuxuan/laraver/net/RestCreator.java

@@ -2,6 +2,7 @@ package com.kuxuan.laraver.net;
2 2
 
3 3
 import com.kuxuan.laraver.app.ConfigKeys;
4 4
 import com.kuxuan.laraver.app.Laraver;
5
+import com.kuxuan.laraver.net.interceptors.ReleaseInterceptor;
5 6
 import com.kuxuan.laraver.net.rx.RxRestService;
6 7
 
7 8
 import java.util.ArrayList;
@@ -38,7 +39,17 @@ public final class RestCreator {
38 39
     private static final class OKHttpHolder {
39 40
         private static final int TIME_OUT = 60;
40 41
         private static final OkHttpClient.Builder BUILDER = new OkHttpClient.Builder();
41
-        private static final ArrayList<Interceptor> INTERCEPTORS = Laraver.getConfiguration(ConfigKeys.INTERCEPTOR);
42
+        //private static final ArrayList<Interceptor> INTERCEPTORS = Laraver.getConfiguration(ConfigKeys.INTERCEPTOR);
43
+        private static  ArrayList<Interceptor> INTERCEPTORS =null;
44
+
45
+        {
46
+            if(Laraver.getConfiguration(ConfigKeys.INTERCEPTOR)!=null){
47
+                INTERCEPTORS = Laraver.getConfiguration(ConfigKeys.INTERCEPTOR);
48
+            }else{
49
+                INTERCEPTORS = new ArrayList<>();
50
+                INTERCEPTORS.add(new ReleaseInterceptor());
51
+            }
52
+        }
42 53
 
43 54
         private static OkHttpClient.Builder addInterceptor() {
44 55
             if (INTERCEPTORS != null && !INTERCEPTORS.isEmpty()) {

+ 5 - 8
laraver-core/src/main/java/com/kuxuan/laraver/net/callback/RequestCallbacks.java

@@ -3,8 +3,8 @@ package com.kuxuan.laraver.net.callback;
3 3
 import android.os.Handler;
4 4
 
5 5
 
6
-import com.kuxuan.laraver.ui.LaraverLoader;
7
-import com.kuxuan.laraver.ui.LoaderStyle;
6
+import com.kuxuan.laraver.ui.loader.LaraverLoader;
7
+import com.kuxuan.laraver.ui.loader.LoaderStyle;
8 8
 
9 9
 import retrofit2.Call;
10 10
 import retrofit2.Callback;
@@ -63,12 +63,9 @@ public final class RequestCallbacks implements Callback<String> {
63 63
 
64 64
     private void stopLoading() {
65 65
         if (LOADER_STYLE != null) {
66
-            HANDLER.postDelayed(new Runnable() {
67
-                @Override
68
-                public void run() {
69
-                    LaraverLoader.stopLoading();
70
-                }
71
-            }, 1000);
66
+
67
+            LaraverLoader.stopLoading();
68
+
72 69
         }
73 70
     }
74 71
 

+ 40 - 0
laraver-core/src/main/java/com/kuxuan/laraver/net/callback/RxCallBack.java

@@ -0,0 +1,40 @@
1
+package com.kuxuan.laraver.net.callback;
2
+
3
+import android.widget.Toast;
4
+
5
+import com.kuxuan.laraver.app.Laraver;
6
+import com.kuxuan.laraver.ui.loader.LaraverLoader;
7
+
8
+
9
+import io.reactivex.Observer;
10
+import io.reactivex.disposables.Disposable;
11
+
12
+/**
13
+ *
14
+ * @author huangfuruixin
15
+ * @date 2017/12/13
16
+ */
17
+
18
+public class RxCallBack implements Observer<String> {
19
+
20
+    @Override
21
+    public void onSubscribe(Disposable d) {
22
+
23
+    }
24
+
25
+    @Override
26
+    public void onNext(String s) {
27
+
28
+    }
29
+
30
+    @Override
31
+    public void onError(Throwable e) {
32
+        Toast.makeText(Laraver.getApplicationContext(),e.getMessage() , Toast.LENGTH_SHORT).show();
33
+    }
34
+
35
+    @Override
36
+    public void onComplete() {
37
+
38
+        LaraverLoader.stopLoading();
39
+    }
40
+}

+ 1 - 0
laraver-core/src/main/java/com/kuxuan/laraver/net/interceptors/ReleaseInterceptor.java

@@ -5,6 +5,7 @@ import com.kuxuan.laraver.util.storage.LaraverPreference;
5 5
 import java.io.IOException;
6 6
 
7 7
 import io.reactivex.functions.Consumer;
8
+import okhttp3.Interceptor;
8 9
 import okhttp3.Request;
9 10
 import okhttp3.Response;
10 11
 

+ 4 - 10
laraver-core/src/main/java/com/kuxuan/laraver/net/rx/RxRestClient.java

@@ -3,17 +3,11 @@ package com.kuxuan.laraver.net.rx;
3 3
 import android.content.Context;
4 4
 
5 5
 import com.kuxuan.laraver.net.HttpMethod;
6
-import com.kuxuan.laraver.net.RestClientBuilder;
6
+
7 7
 import com.kuxuan.laraver.net.RestCreator;
8
-import com.kuxuan.laraver.net.RestService;
9
-import com.kuxuan.laraver.net.callback.IError;
10
-import com.kuxuan.laraver.net.callback.IFailure;
11
-import com.kuxuan.laraver.net.callback.IRequest;
12
-import com.kuxuan.laraver.net.callback.ISuccess;
13
-import com.kuxuan.laraver.net.callback.RequestCallbacks;
14
-import com.kuxuan.laraver.net.download.DownloadHandler;
15
-import com.kuxuan.laraver.ui.LaraverLoader;
16
-import com.kuxuan.laraver.ui.LoaderStyle;
8
+import com.kuxuan.laraver.ui.loader.LaraverLoader;
9
+import com.kuxuan.laraver.ui.loader.LoaderStyle;
10
+
17 11
 
18 12
 import java.io.File;
19 13
 import java.util.Map;

+ 3 - 6
laraver-core/src/main/java/com/kuxuan/laraver/net/rx/RxRestClientBuilder.java

@@ -2,13 +2,10 @@ package com.kuxuan.laraver.net.rx;
2 2
 
3 3
 import android.content.Context;
4 4
 
5
-import com.kuxuan.laraver.net.RestClient;
5
+
6 6
 import com.kuxuan.laraver.net.RestCreator;
7
-import com.kuxuan.laraver.net.callback.IError;
8
-import com.kuxuan.laraver.net.callback.IFailure;
9
-import com.kuxuan.laraver.net.callback.IRequest;
10
-import com.kuxuan.laraver.net.callback.ISuccess;
11
-import com.kuxuan.laraver.ui.LoaderStyle;
7
+import com.kuxuan.laraver.ui.loader.LoaderStyle;
8
+
12 9
 
13 10
 import java.io.File;
14 11
 import java.util.WeakHashMap;

+ 71 - 0
laraver-core/src/main/java/com/kuxuan/laraver/ui/loader/LaraverLoader.java

@@ -0,0 +1,71 @@
1
+package com.kuxuan.laraver.ui.loader;
2
+
3
+import android.content.Context;
4
+import android.support.v7.app.AppCompatDialog;
5
+import android.view.Gravity;
6
+import android.view.Window;
7
+import android.view.WindowManager;
8
+
9
+import com.kuxuan.laraver.R;
10
+import com.kuxuan.laraver.util.dimen.DimenUtil;
11
+import com.wang.avi.AVLoadingIndicatorView;
12
+
13
+import java.util.ArrayList;
14
+
15
+
16
+/**
17
+ *
18
+ * @author huangfuruixin
19
+ * @date 2017/12/6
20
+ */
21
+
22
+public class LaraverLoader {
23
+    private static final int LOADER_SIZE_SCALE = 8;
24
+    private static final int LOADER_OFFSET_SCALE = 10;
25
+
26
+    private static final ArrayList<AppCompatDialog> LOADERS = new ArrayList<>();
27
+
28
+    private static final String DEFAULT_LOADER = LoaderStyle.BallClipRotatePulseIndicator.name();
29
+
30
+    public static void showLoading(Context context, Enum<LoaderStyle> type) {
31
+        showLoading(context, type.name());
32
+    }
33
+
34
+    public static void showLoading(Context context, String type) {
35
+
36
+        final AppCompatDialog dialog = new AppCompatDialog(context, R.style.dialog);
37
+
38
+        final AVLoadingIndicatorView avLoadingIndicatorView = LoaderCreator.create(type, context);
39
+        dialog.setContentView(avLoadingIndicatorView);
40
+
41
+        int deviceWidth = DimenUtil.getScreenWidth();
42
+        int deviceHeight = DimenUtil.getScreenHeight();
43
+
44
+        final Window dialogWindow = dialog.getWindow();
45
+
46
+        if (dialogWindow != null) {
47
+            final WindowManager.LayoutParams lp = dialogWindow.getAttributes();
48
+            lp.width = deviceWidth / LOADER_SIZE_SCALE;
49
+            lp.height = deviceHeight / LOADER_SIZE_SCALE;
50
+            lp.height = lp.height + deviceHeight / LOADER_OFFSET_SCALE;
51
+            lp.gravity = Gravity.CENTER;
52
+        }
53
+        LOADERS.add(dialog);
54
+        dialog.show();
55
+    }
56
+
57
+    public static void showLoading(Context context) {
58
+        showLoading(context, DEFAULT_LOADER);
59
+    }
60
+
61
+    public static void stopLoading() {
62
+        for (AppCompatDialog dialog : LOADERS) {
63
+            if (dialog != null) {
64
+                if (dialog.isShowing()) {
65
+                    dialog.cancel();
66
+                }
67
+            }
68
+        }
69
+    }
70
+
71
+}

+ 51 - 0
laraver-core/src/main/java/com/kuxuan/laraver/ui/loader/LoaderCreator.java

@@ -0,0 +1,51 @@
1
+package com.kuxuan.laraver.ui.loader;
2
+
3
+import android.content.Context;
4
+
5
+import com.wang.avi.AVLoadingIndicatorView;
6
+import com.wang.avi.Indicator;
7
+
8
+import java.util.WeakHashMap;
9
+
10
+/**
11
+ * 为反射创建缓存,提高性能
12
+ * @author huangfuruixin
13
+ * @date 2017/12/6
14
+ */
15
+
16
+public class LoaderCreator {
17
+    private static final WeakHashMap<String,Indicator> LOADING_MAP = new WeakHashMap<>();
18
+
19
+
20
+    static AVLoadingIndicatorView create(String type,Context context){
21
+        final AVLoadingIndicatorView avLoadingIndicatorView = new AVLoadingIndicatorView(context);
22
+        if (LOADING_MAP.get(type) == null){
23
+            final Indicator indicator = getIndicator(type);
24
+            LOADING_MAP.put(type,indicator);
25
+        }
26
+        avLoadingIndicatorView.setIndicator(LOADING_MAP.get(type));
27
+        return avLoadingIndicatorView;
28
+    }
29
+
30
+    private static Indicator getIndicator(String name){
31
+        if(name ==null||name.isEmpty()){
32
+            return null;
33
+        }
34
+        final StringBuilder drawableClassName = new StringBuilder();
35
+        if(!name.contains(".")){
36
+            final String defaultPackName = AVLoadingIndicatorView.class.getPackage().getName();
37
+            drawableClassName.append(defaultPackName)
38
+                    .append(".indicators")
39
+                    .append(".");
40
+        }
41
+
42
+        drawableClassName.append(name);
43
+        try {
44
+            final Class<?> drawableClass = Class.forName(drawableClassName.toString());
45
+            return (Indicator) drawableClass.newInstance();
46
+        } catch (Exception e) {
47
+            e.printStackTrace();
48
+            return null;
49
+        }
50
+    }
51
+}

+ 40 - 0
laraver-core/src/main/java/com/kuxuan/laraver/ui/loader/LoaderStyle.java

@@ -0,0 +1,40 @@
1
+package com.kuxuan.laraver.ui.loader;
2
+
3
+/**
4
+ *
5
+ * @author huangfuruixin
6
+ * @date 2017/12/6
7
+ */
8
+
9
+@SuppressWarnings("unused")
10
+public enum LoaderStyle {
11
+    BallPulseIndicator,
12
+    BallGridPulseIndicator,
13
+    BallClipRotateIndicator,
14
+    BallClipRotatePulseIndicator,
15
+    SquareSpinIndicator,
16
+    BallClipRotateMultipleIndicator,
17
+    BallPulseRiseIndicator,
18
+    BallRotateIndicator,
19
+    CubeTransitionIndicator,
20
+    BallZigZagIndicator,
21
+    BallZigZagDeflectIndicator,
22
+    BallTrianglePathIndicator,
23
+    BallScaleIndicator,
24
+    LineScaleIndicator,
25
+    LineScalePartyIndicator,
26
+    BallScaleMultipleIndicator,
27
+    BallPulseSyncIndicator,
28
+    BallBeatIndicator,
29
+    LineScalePulseOutIndicator,
30
+    LineScalePulseOutRapidIndicator,
31
+    BallScaleRippleIndicator,
32
+    BallScaleRippleMultipleIndicator,
33
+    BallSpinFadeLoaderIndicator,
34
+    LineSpinFadeLoaderIndicator,
35
+    TriangleSkewSpinIndicator,
36
+    PacmanIndicator,
37
+    BallGridBeatIndicator,
38
+    SemiCircleSpinIndicator,
39
+    CustomIndicator
40
+}