Ver Código Fonte

提交loading的查漏补缺

皇甫睿欣 7 anos atrás
pai
commit
fddba6f661

+ 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;

+ 2 - 2
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;

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

@@ -3,8 +3,8 @@ package com.kuxuan.laraver.net.callback;
3 3
 import android.widget.Toast;
4 4
 
5 5
 import com.kuxuan.laraver.app.Laraver;
6
-import com.kuxuan.laraver.ui.LaraverLoader;
7
-import com.kuxuan.laraver.ui.LoaderStyle;
6
+import com.kuxuan.laraver.ui.loader.LaraverLoader;
7
+
8 8
 
9 9
 import io.reactivex.Observer;
10 10
 import io.reactivex.disposables.Disposable;

+ 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
+}