皇甫睿欣 6 vuotta sitten
vanhempi
commit
32728c65c6

+ 6 - 2
app/src/main/java/com/kuxuan/fastbrowser/App.java

@@ -22,13 +22,17 @@ public class App extends Application {
22 22
     public void onCreate() {
23 23
         super.onCreate();
24 24
         Laraver.init(this)
25
+                //配置Host
25 26
                 .withApiHost("http://114.67.235.114/RestServer/api/")
27
+                //配置 字体库,
26 28
                 .withIcon(new FontAwesomeModule())
29
+                //配置js native 互调
27 30
                 .withJavascriptInterface("Laraver")
28
-                .withWeChatAppId("wxfcdcecd9df8e0faa")
29
-                .withWeChatAppSecret("a0560f75335b06e33bea70f29ff219bf")
31
+                //配置js native 互调
30 32
                 .withWebEvent("Laraver",new TextEvent())
33
+                //配置网络拦截器,需要自己复写
31 34
                 .withInterceptor(new ReleaseInterceptor())
35
+
32 36
                 .withWebHost("https://wwww.baidu.com/")
33 37
                 .configure();
34 38
         DatabaseManager.getInstance().init(this);

+ 27 - 17
app/src/main/java/com/kuxuan/fastbrowser/ExampleDelegate.java

@@ -3,14 +3,19 @@ package com.kuxuan.fastbrowser;
3 3
 import android.os.Bundle;
4 4
 import android.support.annotation.Nullable;
5 5
 import android.view.View;
6
+import android.widget.Toast;
6 7
 
8
+import com.kuxuan.laraver.app.Laraver;
7 9
 import com.kuxuan.laraver.delegates.LaraverDelegate;
8 10
 import com.kuxuan.laraver.net.RestClient;
9 11
 import com.kuxuan.laraver.net.RestCreator;
10 12
 import com.kuxuan.laraver.net.callback.IError;
11 13
 import com.kuxuan.laraver.net.callback.IFailure;
12 14
 import com.kuxuan.laraver.net.callback.ISuccess;
15
+import com.kuxuan.laraver.net.callback.RxCallBack;
13 16
 import com.kuxuan.laraver.net.rx.RxRestClient;
17
+import com.kuxuan.laraver.ui.loader.LoaderStyle;
18
+import com.kuxuan.laraver.util.log.LaraverLogger;
14 19
 
15 20
 import java.util.WeakHashMap;
16 21
 
@@ -27,6 +32,7 @@ import io.reactivex.schedulers.Schedulers;
27 32
  */
28 33
 
29 34
 public class ExampleDelegate extends LaraverDelegate {
35
+    String a = null;
30 36
     @Override
31 37
     public Object setLayout() {
32 38
         return R.layout.delegate_example;
@@ -34,13 +40,13 @@ public class ExampleDelegate extends LaraverDelegate {
34 40
 
35 41
     @Override
36 42
     public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
37
-       testRestClient();
43
+        testRestClient();
38 44
     }
39 45
 
40 46
     private void testRestClient(){
41 47
         RestClient.builder()
42 48
                 .url("http://news.baidu.com")
43
-                .loader(getContext())
49
+                .loader(getContext(), LoaderStyle.BallClipRotateIndicator)
44 50
                 .success(new ISuccess() {
45 51
                     @Override
46 52
                     public void onSuccess(String response) {
@@ -66,45 +72,49 @@ public class ExampleDelegate extends LaraverDelegate {
66 72
 
67 73
     // TODO: 2017/12/6 RX JAVA  网络请求实例   第一种
68 74
     void onCallRxget(){
69
-        final String url = "index.php";
75
+        final String url = "home/newlist";
70 76
         final WeakHashMap<String,Object> params = new WeakHashMap<>();
71
-
77
+        params.put("pageId",1);
78
+        params.put("type","recomment");
79
+//        pageId=1&type=recomment
72 80
         final Observable<String> observable  = RestCreator.getRxRestService().get(url,params);
73 81
         observable.subscribeOn(Schedulers.io())
74 82
                 .observeOn(AndroidSchedulers.mainThread())
75
-                .subscribe(new Observer<String>() {
76
-                    @Override
77
-                    public void onSubscribe(Disposable d) {
78
-
79
-                    }
80
-
83
+                .subscribe(new RxCallBack() {
81 84
                     @Override
82 85
                     public void onNext(String s) {
83
-
86
+                        super.onNext(s);
87
+                        a = s;
88
+                        showToast(a);
89
+                        LaraverLogger.json("ok",s);
90
+                        //Toast.makeText(Laraver.getApplicationContext(), s, Toast.LENGTH_SHORT).show();
84 91
                     }
85 92
 
93
+                    //解除绑定
86 94
                     @Override
87
-                    public void onError(Throwable e) {
88
-
89
-                    }
90
-
91
-                    @Override
92
-                    public void onComplete() {
95
+                    public void onSubscribe(Disposable d) {
96
+                        super.onSubscribe(d);
93 97
 
94 98
                     }
95 99
                 });
96 100
 
97 101
     }
102
+    public void showToast(String s){
103
+        Toast.makeText(_mActivity, s, Toast.LENGTH_SHORT).show();
104
+    }
98 105
 
99 106
     // TODO: 2017/12/6 RX JAVA  网络请求实例 第二种
100 107
     private void onCallRxRestClient(){
101 108
         final String url = "index.php";
102 109
         RxRestClient.builder()
103 110
                 .url(url)
111
+                .params("id","id")
112
+                .params("id","id")
104 113
                 .build()
105 114
                 .get()
106 115
                 .subscribeOn(Schedulers.io())
107 116
                 .observeOn(AndroidSchedulers.mainThread())
117
+
108 118
                 .subscribe(new Observer<String>() {
109 119
                     @Override
110 120
                     public void onSubscribe(Disposable d) {

+ 1 - 1
app/src/main/java/com/kuxuan/fastbrowser/MainActivity.java

@@ -38,7 +38,7 @@ public class MainActivity extends ProxyActivity{
38 38
 
39 39
     @Override
40 40
     public LaraverDelegate setRootDelegate() {
41
-        return new EcBottomDelegate();
41
+        return new ExampleDelegate();
42 42
     }
43 43
 
44 44
 }

+ 8 - 0
laraver-browser/src/main/java/com/kuxuan/laraver/browser/main/EcBottomDelegate.java

@@ -31,11 +31,19 @@ public class EcBottomDelegate extends BaseBottomDelegate {
31 31
         return builder.addItems(items).build();
32 32
     }
33 33
 
34
+    /**
35
+     * 第一个显示的delegate
36
+     * @return
37
+     */
34 38
     @Override
35 39
     public int setIndexDelegate() {
36 40
         return 0;
37 41
     }
38 42
 
43
+    /**
44
+     * delegate 点击变换的颜色
45
+     * @return
46
+     */
39 47
     @Override
40 48
     public int setClickedColor() {
41 49
         return Color.parseColor("#ffff8800");

+ 1 - 0
laraver-browser/src/main/java/com/kuxuan/laraver/browser/main/discover/DiscoverDelegate.java

@@ -30,6 +30,7 @@ public class DiscoverDelegate extends BottomItemDelegate {
30 30
         super.onLazyInitView(savedInstanceState);
31 31
         final WebDelegateImpl delegate = WebDelegateImpl.create("index.html");
32 32
         delegate.setTopDelegate(this.getParentDelegate());
33
+        //加载根Fragment, 即Activity内的第一个Fragment 或 Fragment内的第一个子Fragment
33 34
         getSupportDelegate().loadRootFragment(R.id.web_discovery_container,delegate);
34 35
     }
35 36
 }

+ 0 - 3
laraver-browser/src/main/java/com/kuxuan/laraver/browser/main/index/IndexDelegate.java

@@ -42,9 +42,6 @@ public class IndexDelegate extends BottomItemDelegate implements View.OnFocusCha
42 42
 
43 43
     private RefreshHandler mRefreshHandler = null;
44 44
 
45
-
46
-
47
-
48 45
     @Override
49 46
     public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
50 47
         mRefreshHandler = RefreshHandler.create(mRefreshLayout, mRecyclerView, new IndexDataConverter());

+ 3 - 0
laraver-browser/src/main/java/com/kuxuan/laraver/browser/main/sort/content/ContentDelegate.java

@@ -11,6 +11,8 @@ import com.kuxuan.laraver.browser.R;
11 11
 import com.kuxuan.laraver.browser.R2;
12 12
 import com.kuxuan.laraver.delegates.LaraverDelegate;
13 13
 import com.kuxuan.laraver.net.RestClient;
14
+import com.kuxuan.laraver.net.callback.IError;
15
+import com.kuxuan.laraver.net.callback.IFailure;
14 16
 import com.kuxuan.laraver.net.callback.ISuccess;
15 17
 
16 18
 import java.util.List;
@@ -66,6 +68,7 @@ public class ContentDelegate extends LaraverDelegate {
66 68
                         mRecyclerView.setAdapter(sectionAdapter);
67 69
                     }
68 70
                 })
71
+
69 72
                 .build()
70 73
                 .get();
71 74
     }

+ 11 - 35
laraver-core/src/main/java/com/kuxuan/laraver/delegates/bottom/BottomItemDelegate.java

@@ -6,6 +6,7 @@ import android.view.View;
6 6
 import android.widget.Toast;
7 7
 
8 8
 import com.kuxuan.laraver.R;
9
+import com.kuxuan.laraver.app.Laraver;
9 10
 import com.kuxuan.laraver.delegates.LaraverDelegate;
10 11
 
11 12
 /**
@@ -14,43 +15,18 @@ import com.kuxuan.laraver.delegates.LaraverDelegate;
14 15
  * @date 2017/12/9
15 16
  */
16 17
 
17
-public abstract class BottomItemDelegate extends LaraverDelegate implements View.OnKeyListener {
18
-    private long mExitTime = 0;
19
-    private static final int EXIT_TIME = 2000;
18
+public abstract class BottomItemDelegate extends LaraverDelegate {
19
+    private static final long WAIT_TIME = 2000L;
20
+    private long TOUCH_TIME = 0;
20 21
 
21 22
     @Override
22
-    public void onResume() {
23
-        super.onResume();
24
-        final View rootView = getView();
25
-        if(rootView !=null){
26
-            rootView.setFocusableInTouchMode(true);
27
-            rootView.requestFocus();
28
-            rootView.setOnKeyListener(this);
23
+    public boolean onBackPressedSupport() {
24
+        if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME) {
25
+            _mActivity.finish();
26
+        } else {
27
+            TOUCH_TIME = System.currentTimeMillis();
28
+            Toast.makeText(_mActivity, "双击退出" + Laraver.getApplicationContext().getString(R.string.app_name), Toast.LENGTH_SHORT).show();
29 29
         }
30
-
31
-    }
32
-
33
-    /**
34
-     * 双击退出应用
35
-     * @param v
36
-     * @param keyCode
37
-     * @param keyEvent
38
-     * @return
39
-     */
40
-    @Override
41
-    public boolean onKey(View v, int keyCode, KeyEvent keyEvent) {
42
-        if(keyCode == KeyEvent.KEYCODE_BACK&& keyEvent.getAction() == KeyEvent.ACTION_DOWN){
43
-            if((System.currentTimeMillis() - mExitTime) > EXIT_TIME){
44
-                Toast.makeText(getContext(), "双击退出" + getString(R.string.app_name) , Toast.LENGTH_SHORT).show();
45
-                mExitTime = System.currentTimeMillis();
46
-            }else{
47
-                _mActivity.finish();
48
-                if(mExitTime !=0){
49
-                    mExitTime = 0;
50
-                }
51
-            }
52
-            return true;
53
-        }
54
-        return false;
30
+        return true;
55 31
     }
56 32
 }

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

@@ -1,71 +0,0 @@
1
-package com.kuxuan.laraver.ui;
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
-}

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

@@ -1,51 +0,0 @@
1
-package com.kuxuan.laraver.ui;
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
-}

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

@@ -1,40 +0,0 @@
1
-package com.kuxuan.laraver.ui;
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
-}