Commit 977b33471c6bef542a90e38605d51f805d432db7

Authored by 朱显松
1 parent 08615c24

repair resource file for errors

.idea/modules.xml
@@ -3,11 +3,8 @@ @@ -3,11 +3,8 @@
3 <component name="ProjectModuleManager"> 3 <component name="ProjectModuleManager">
4 <modules> 4 <modules>
5 <module fileurl="file://$PROJECT_DIR$/CNLiveLibs.iml" filepath="$PROJECT_DIR$/CNLiveLibs.iml" /> 5 <module fileurl="file://$PROJECT_DIR$/CNLiveLibs.iml" filepath="$PROJECT_DIR$/CNLiveLibs.iml" />
6 - <module fileurl="file://$PROJECT_DIR$/CNLiveLibs.iml" filepath="$PROJECT_DIR$/CNLiveLibs.iml" />  
7 <module fileurl="file://$PROJECT_DIR$/OPenCNLive_BaseLib.iml" filepath="$PROJECT_DIR$/OPenCNLive_BaseLib.iml" /> 6 <module fileurl="file://$PROJECT_DIR$/OPenCNLive_BaseLib.iml" filepath="$PROJECT_DIR$/OPenCNLive_BaseLib.iml" />
8 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> 7 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
9 - <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />  
10 - <module fileurl="file://$PROJECT_DIR$/cnlive/cnlive.iml" filepath="$PROJECT_DIR$/cnlive/cnlive.iml" />  
11 <module fileurl="file://$PROJECT_DIR$/cnlive/cnlive.iml" filepath="$PROJECT_DIR$/cnlive/cnlive.iml" /> 8 <module fileurl="file://$PROJECT_DIR$/cnlive/cnlive.iml" filepath="$PROJECT_DIR$/cnlive/cnlive.iml" />
12 </modules> 9 </modules>
13 </component> 10 </component>
app/src/main/AndroidManifest.xml
@@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.cnlive.libs.demo"> 3 package="com.cnlive.libs.demo">
4 4
  5 +
5 <application 6 <application
  7 + android:name=".App"
6 android:allowBackup="true" 8 android:allowBackup="true"
7 android:icon="@mipmap/ic_launcher" 9 android:icon="@mipmap/ic_launcher"
8 android:label="@string/app_name" 10 android:label="@string/app_name"
app/src/main/java/com/cnlive/libs/demo/App.java 0 → 100644
  1 +package com.cnlive.libs.demo;
  2 +
  3 +import android.app.Application;
  4 +
  5 +/**
  6 + * Created by xiansong on 2017/8/22.
  7 + */
  8 +
  9 +public class App extends Application {
  10 + @Override
  11 + public void onCreate() {
  12 + super.onCreate();
  13 + }
  14 +}
app/src/main/java/com/cnlive/libs/demo/Java8Test.java
@@ -27,5 +27,6 @@ public class Java8Test { @@ -27,5 +27,6 @@ public class Java8Test {
27 stream(list).forEach(item -> Log.e("DemoView", "n item " + item)); 27 stream(list).forEach(item -> Log.e("DemoView", "n item " + item));
28 28
29 String str = stream(list).map(x -> x.toUpperCase()).collect(Collectors.joining(", ")); 29 String str = stream(list).map(x -> x.toUpperCase()).collect(Collectors.joining(", "));
  30 + Log.e("DemoView", "n item " + str);
30 } 31 }
31 } 32 }
app/src/main/java/com/cnlive/libs/demo/RequestTest.java
1 package com.cnlive.libs.demo; 1 package com.cnlive.libs.demo;
2 2
3 import android.content.Context; 3 import android.content.Context;
4 -import android.content.res.Resources;  
5 4
6 -import com.cnlive.libs.base.model.IBaseInfo;  
7 import com.cnlive.libs.base.network.RetrofitUtil; 5 import com.cnlive.libs.base.network.RetrofitUtil;
8 import com.cnlive.libs.base.network.Subscriber; 6 import com.cnlive.libs.base.network.Subscriber;
9 import com.cnlive.libs.demo.data.model.AppInfo; 7 import com.cnlive.libs.demo.data.model.AppInfo;
@@ -11,44 +9,38 @@ import com.cnlive.libs.demo.data.network.testapi.ApiRequest; @@ -11,44 +9,38 @@ import com.cnlive.libs.demo.data.network.testapi.ApiRequest;
11 import com.cnlive.libs.demo.data.network.testapi.ApiService; 9 import com.cnlive.libs.demo.data.network.testapi.ApiService;
12 10
13 import io.reactivex.disposables.Disposable; 11 import io.reactivex.disposables.Disposable;
14 -import okhttp3.RequestBody;  
15 12
16 13
17 public class RequestTest { 14 public class RequestTest {
18 15
19 //---- Api Config Start --- 16 //---- Api Config Start ---
20 public static final String success_code = "200"; 17 public static final String success_code = "200";
21 - private static final String success_message = Resources.getSystem().getString(com.cnlive.libs.base.R.string.load_success_message); 18 + private static final String success_message = "数据加载成功";
22 19
23 private static final String custom_error = "401"; 20 private static final String custom_error = "401";
24 - private static final String custom_response_message = Resources.getSystem().getString(com.cnlive.libs.base.R.string.custom_response_message); 21 + private static final String custom_response_message = "自定义事件";
25 22
26 static { 23 static {
27 RetrofitUtil.setDebug(com.cnlive.libs.demo.Config.debug); 24 RetrofitUtil.setDebug(com.cnlive.libs.demo.Config.debug);
28 } 25 }
29 26
30 - private static final Subscriber.CustomLoadResponse customLoadResponse = new Subscriber.CustomLoadResponse() {  
31 - @Override  
32 - public void onCustomEvent(String code, IBaseInfo pageData) {  
33 - switch (code) {  
34 - case custom_error:  
35 - //Custom Error Event  
36 - break;  
37 - } 27 + private static final Subscriber.CustomLoadResponse customLoadResponse = (code, message, pageData) -> {
  28 + switch (code) {
  29 + case custom_error:
  30 + //Custom Error Event
  31 + break;
38 } 32 }
39 }; 33 };
40 34
41 - private static final Subscriber.Config subscriberBuild = Subscriber.newConfig() 35 + public static final Subscriber.Config subscriberBuild = Subscriber.newConfig()
42 .putCustomResponse(custom_error, custom_response_message) 36 .putCustomResponse(custom_error, custom_response_message)
43 .putInfo(Subscriber.Config.response_success, success_code, success_message) 37 .putInfo(Subscriber.Config.response_success, success_code, success_message)
44 .setCustomLoadResponse(customLoadResponse); 38 .setCustomLoadResponse(customLoadResponse);
45 39
46 //---- Api Config End --- 40 //---- Api Config End ---
47 public void test(Context context) { 41 public void test(Context context) {
48 - RequestBody requestBody = ApiRequest.getRequestJsonBody("");  
49 -  
50 - Disposable subscription = ApiRequest.subscribe(  
51 - ApiRequest.getService(ApiService.class).appInfo(com.cnlive.libs.demo.Config.APP_ID), 42 + Disposable disposable = ApiRequest.subscribe(
  43 + ApiRequest.service(ApiService.class).appInfo(Config.APP_ID),
52 new Subscriber<AppInfo>(context, subscriberBuild) { 44 new Subscriber<AppInfo>(context, subscriberBuild) {
53 @Override 45 @Override
54 public void onStart() { 46 public void onStart() {
@@ -60,13 +52,13 @@ public class RequestTest { @@ -60,13 +52,13 @@ public class RequestTest {
60 switch (code) { 52 switch (code) {
61 case success_code: 53 case success_code:
62 break; 54 break;
63 - case Config.default_error_code: 55 + case Subscriber.Config.default_error_code:
64 break; 56 break;
65 - case Config.default_failure_code: 57 + case Subscriber.Config.default_failure_code:
66 break; 58 break;
67 - case Config.default_unknown_error_code: 59 + case Subscriber.Config.default_unknown_error_code:
68 break; 60 break;
69 - case Config.default_no_network_code: 61 + case Subscriber.Config.default_no_network_code:
70 break; 62 break;
71 } 63 }
72 } 64 }
@@ -75,9 +67,10 @@ public class RequestTest { @@ -75,9 +67,10 @@ public class RequestTest {
75 public void onCompleted(String code, String message, AppInfo data) { 67 public void onCompleted(String code, String message, AppInfo data) {
76 68
77 } 69 }
78 - }  
79 - ); 70 + });
80 71
81 - subscription.dispose(); 72 + disposable.dispose();
82 } 73 }
  74 +
  75 +
83 } 76 }
app/src/main/java/com/cnlive/libs/demo/data/network/testapi/ApiRequest.java
@@ -14,19 +14,23 @@ import okhttp3.MediaType; @@ -14,19 +14,23 @@ import okhttp3.MediaType;
14 import okhttp3.RequestBody; 14 import okhttp3.RequestBody;
15 import retrofit2.adapter.rxjava2.Result; 15 import retrofit2.adapter.rxjava2.Result;
16 16
  17 +import static com.cnlive.libs.demo.data.network.testapi.ApiService.URL_DEBUG;
  18 +import static com.cnlive.libs.demo.data.network.testapi.ApiService.URL_RELEASE;
  19 +
17 20
18 public class ApiRequest { 21 public class ApiRequest {
19 22
20 - private static final String BASE_URL_DEBUG = "https://ymzx.asia-cloud.com/api/";  
21 - private static final String BASE_URL_RELEASE = "https://ymzx.asia-cloud.com/api/"; 23 + private static <T> String getUrl(Class<T> clazz) {
  24 + String url = "";
  25 +
  26 + if (clazz == ApiService.class) url = Config.debug ? URL_DEBUG : URL_RELEASE;
22 27
23 - private static String getBaseUrl() {  
24 - return Config.debug ? BASE_URL_DEBUG : BASE_URL_RELEASE; 28 + return url;
25 } 29 }
26 30
27 31
28 - public static <T> T getService(Class<T> clazz) {  
29 - return RetrofitUtil.getRestAPI(getBaseUrl(), clazz); 32 + public static <T> T service(Class<T> clazz) {
  33 + return RetrofitUtil.getRestAPI(getUrl(clazz), clazz);
30 } 34 }
31 35
32 public static <T extends IBaseInfo> Disposable subscribe(Observable<Result<T>> observable, Subscriber<T> subscriber) { 36 public static <T extends IBaseInfo> Disposable subscribe(Observable<Result<T>> observable, Subscriber<T> subscriber) {
@@ -39,4 +43,5 @@ public class ApiRequest { @@ -39,4 +43,5 @@ public class ApiRequest {
39 public static RequestBody getRequestJsonBody(String content) { 43 public static RequestBody getRequestJsonBody(String content) {
40 return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), content); 44 return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), content);
41 } 45 }
  46 +
42 } 47 }
app/src/main/java/com/cnlive/libs/demo/data/network/testapi/ApiService.java
@@ -9,8 +9,8 @@ import retrofit2.http.GET; @@ -9,8 +9,8 @@ import retrofit2.http.GET;
9 import retrofit2.http.Query; 9 import retrofit2.http.Query;
10 10
11 public interface ApiService { 11 public interface ApiService {
12 -  
13 - //--应用程序-- 12 + String URL_DEBUG = "https://ymzx.asia-cloud.com/api/";
  13 + String URL_RELEASE = "https://ymzx.asia-cloud.com/api/";
14 14
15 /** 15 /**
16 * 获取应用程序信息 16 * 获取应用程序信息
app/src/main/java/com/cnlive/libs/demo/mvptest/frame/presenter/LaunchPresenter.java
@@ -2,14 +2,21 @@ package com.cnlive.libs.demo.mvptest.frame.presenter; @@ -2,14 +2,21 @@ package com.cnlive.libs.demo.mvptest.frame.presenter;
2 2
3 import android.content.Context; 3 import android.content.Context;
4 4
  5 +import com.cnlive.libs.base.network.Subscriber;
5 import com.cnlive.libs.base.util.LogUtil; 6 import com.cnlive.libs.base.util.LogUtil;
6 import com.cnlive.libs.base.util.TimerUtil; 7 import com.cnlive.libs.base.util.TimerUtil;
  8 +import com.cnlive.libs.demo.Config;
  9 +import com.cnlive.libs.demo.data.model.AppInfo;
  10 +import com.cnlive.libs.demo.data.network.testapi.ApiRequest;
  11 +import com.cnlive.libs.demo.data.network.testapi.ApiService;
7 import com.cnlive.libs.demo.mvptest.frame.ILaunchView; 12 import com.cnlive.libs.demo.mvptest.frame.ILaunchView;
8 import com.cnlive.libs.demo.mvptest.frame.view.LaunchView; 13 import com.cnlive.libs.demo.mvptest.frame.view.LaunchView;
9 import com.hannesdorfmann.mosby.mvp.MvpBasePresenter; 14 import com.hannesdorfmann.mosby.mvp.MvpBasePresenter;
10 15
11 import io.reactivex.disposables.Disposable; 16 import io.reactivex.disposables.Disposable;
12 17
  18 +import static com.cnlive.libs.demo.RequestTest.subscriberBuild;
  19 +
13 public class LaunchPresenter extends MvpBasePresenter<LaunchView> { 20 public class LaunchPresenter extends MvpBasePresenter<LaunchView> {
14 21
15 private TimerUtil timerUtil; //计时工具类 22 private TimerUtil timerUtil; //计时工具类
@@ -21,8 +28,27 @@ public class LaunchPresenter extends MvpBasePresenter&lt;LaunchView&gt; { @@ -21,8 +28,27 @@ public class LaunchPresenter extends MvpBasePresenter&lt;LaunchView&gt; {
21 public void initData(Context context) { 28 public void initData(Context context) {
22 if (subscription != null) subscription.dispose(); 29 if (subscription != null) subscription.dispose();
23 30
24 - ILaunchView view = getView();  
25 - if (view != null) view.onLoadDataComplete(null); 31 + subscription = ApiRequest.subscribe(
  32 + ApiRequest.service(ApiService.class).appInfo(Config.APP_ID),
  33 + new Subscriber<AppInfo>(context, subscriberBuild) {
  34 + @Override
  35 + public void onCompleted(String code, String message, AppInfo data) {
  36 + ILaunchView view = getView();
  37 + if (view != null) view.onLoadDataComplete(null);
  38 + }
  39 +
  40 + @Override
  41 + public void onError(String code, String message) {
  42 + ILaunchView view = getView();
  43 + if (view != null) view.onLoadDataError(code, message);
  44 + }
  45 +
  46 + @Override
  47 + public void onStart() {
  48 + ILaunchView view = getView();
  49 + if (view != null) view.onLoadDataStart();
  50 + }
  51 + });
26 } 52 }
27 53
28 /** 54 /**
cnlive/src/main/AndroidManifest.xml
@@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
2 2
3 package="com.cnlive.libs.base"> 3 package="com.cnlive.libs.base">
4 4
  5 + <uses-permission android:name="android.permission.INTERNET" />
  6 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  7 +
5 <application android:allowBackup="true" android:label="@string/app_name" 8 <application android:allowBackup="true" android:label="@string/app_name"
6 android:supportsRtl="true"> 9 android:supportsRtl="true">
7 10
cnlive/src/main/java/com/cnlive/libs/base/activity/MvpActivity.java 0 → 100644
  1 +package com.cnlive.libs.base.activity;
  2 +
  3 +import android.os.Bundle;
  4 +import android.support.annotation.NonNull;
  5 +
  6 +import com.cnlive.libs.base.util.ReflectUtil;
  7 +import com.hannesdorfmann.mosby.mvp.MvpPresenter;
  8 +import com.hannesdorfmann.mosby.mvp.MvpView;
  9 +
  10 +/**
  11 + * MVP Databinding Base Activity
  12 + * @param <V> MVP View {@link MvpView}
  13 + * @param <P> MVP Presenter {@link MvpPresenter}
  14 + */
  15 +public abstract class MvpActivity<V extends MvpView, P extends MvpPresenter<V>> extends com.hannesdorfmann.mosby.mvp.MvpActivity<V, P> {
  16 +
  17 + public V view;
  18 +
  19 + @Override
  20 + protected void onCreate(Bundle savedInstanceState) {
  21 + super.onCreate(savedInstanceState);
  22 + setContentView(getLayoutId());
  23 + }
  24 +
  25 + protected abstract int getLayoutId();
  26 +
  27 + @NonNull
  28 + public V createView() {
  29 + return ReflectUtil.instance(0, this.getClass(), this);
  30 + }
  31 +
  32 + @NonNull
  33 + @Override
  34 + public P createPresenter() {
  35 + return ReflectUtil.instance(1, this);
  36 + }
  37 +
  38 + @NonNull
  39 + @Override
  40 + public V getMvpView() {
  41 + if (view == null) view = createView();
  42 + return view;
  43 + }
  44 +
  45 +}
cnlive/src/main/java/com/cnlive/libs/base/activity/MvpBindingActivity.java
@@ -27,13 +27,13 @@ public abstract class MvpBindingActivity&lt;V extends MvpView, P extends MvpPresent @@ -27,13 +27,13 @@ public abstract class MvpBindingActivity&lt;V extends MvpView, P extends MvpPresent
27 protected void onCreate(Bundle savedInstanceState) { 27 protected void onCreate(Bundle savedInstanceState) {
28 super.onCreate(savedInstanceState); 28 super.onCreate(savedInstanceState);
29 binding = DataBindingUtil.setContentView(this, getLayoutId()); 29 binding = DataBindingUtil.setContentView(this, getLayoutId());
30 - ReflectUtil.invoke(binding, "setData", getLayoutData()); 30 + ReflectUtil.invoke(binding, "setData", getViewData());
31 } 31 }
32 32
33 protected abstract int getLayoutId(); 33 protected abstract int getLayoutId();
34 34
35 - protected D getLayoutData() {  
36 - return data = ReflectUtil.instance(2, this); 35 + protected D initLayoutData() {
  36 + return ReflectUtil.instance(2, this);
37 } 37 }
38 38
39 @NonNull 39 @NonNull
@@ -54,4 +54,9 @@ public abstract class MvpBindingActivity&lt;V extends MvpView, P extends MvpPresent @@ -54,4 +54,9 @@ public abstract class MvpBindingActivity&lt;V extends MvpView, P extends MvpPresent
54 return view; 54 return view;
55 } 55 }
56 56
  57 + @NonNull
  58 + public D getViewData() {
  59 + if(data == null) data = initLayoutData();
  60 + return data;
  61 + }
57 } 62 }
cnlive/src/main/java/com/cnlive/libs/base/fragment/MvpBindingFragment.java
@@ -31,14 +31,14 @@ public abstract class MvpBindingFragment&lt;V extends MvpView, P extends MvpPresent @@ -31,14 +31,14 @@ public abstract class MvpBindingFragment&lt;V extends MvpView, P extends MvpPresent
31 @Override 31 @Override
32 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 32 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
33 binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false); 33 binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
34 - ReflectUtil.invoke(binding, "setData", getLayoutData()); 34 + ReflectUtil.invoke(binding, "setData", getViewData());
35 return binding.getRoot(); 35 return binding.getRoot();
36 } 36 }
37 37
38 protected abstract int getLayoutId(); 38 protected abstract int getLayoutId();
39 39
40 - protected D getLayoutData() {  
41 - return data = ReflectUtil.instance(2, this); 40 + protected D initLayoutData() {
  41 + return ReflectUtil.instance(2, this);
42 } 42 }
43 43
44 @NonNull 44 @NonNull
@@ -60,4 +60,9 @@ public abstract class MvpBindingFragment&lt;V extends MvpView, P extends MvpPresent @@ -60,4 +60,9 @@ public abstract class MvpBindingFragment&lt;V extends MvpView, P extends MvpPresent
60 } 60 }
61 61
62 62
  63 + @NonNull
  64 + public D getViewData() {
  65 + if(data == null) data = initLayoutData();
  66 + return data;
  67 + }
63 } 68 }
64 \ No newline at end of file 69 \ No newline at end of file
cnlive/src/main/java/com/cnlive/libs/base/fragment/MvpFragment.java 0 → 100644
  1 +package com.cnlive.libs.base.fragment;
  2 +
  3 +import android.os.Bundle;
  4 +import android.support.annotation.NonNull;
  5 +import android.support.annotation.Nullable;
  6 +import android.view.LayoutInflater;
  7 +import android.view.View;
  8 +import android.view.ViewGroup;
  9 +
  10 +import com.cnlive.libs.base.util.ReflectUtil;
  11 +import com.hannesdorfmann.mosby.mvp.MvpPresenter;
  12 +import com.hannesdorfmann.mosby.mvp.MvpView;
  13 +
  14 +/**
  15 + * MVP Databinding Base Fragment
  16 + *
  17 + * @param <V> MVP View {@link MvpView}
  18 + * @param <P> MVP Presenter {@link MvpPresenter}
  19 + */
  20 +public abstract class MvpFragment<V extends MvpView, P extends MvpPresenter<V>> extends com.hannesdorfmann.mosby.mvp.MvpFragment<V, P> {
  21 +
  22 + public V view;
  23 +
  24 + @Nullable
  25 + @Override
  26 + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  27 + return inflater.inflate(getLayoutId(), container, false);
  28 + }
  29 +
  30 + protected abstract int getLayoutId();
  31 +
  32 +
  33 + @NonNull
  34 + public V createView() {
  35 + return ReflectUtil.instance(0, this.getClass(), this);
  36 + }
  37 +
  38 + @NonNull
  39 + @Override
  40 + public P createPresenter() {
  41 + return ReflectUtil.instance(1, this);
  42 + }
  43 +
  44 + @NonNull
  45 + @Override
  46 + public V getMvpView() {
  47 + if (view == null) view = createView();
  48 + return view;
  49 + }
  50 +
  51 +}
0 \ No newline at end of file 52 \ No newline at end of file
cnlive/src/main/java/com/cnlive/libs/base/network/Subscriber.java
1 package com.cnlive.libs.base.network; 1 package com.cnlive.libs.base.network;
2 2
3 import android.content.Context; 3 import android.content.Context;
4 -import android.content.res.Resources;  
5 import android.support.annotation.IntDef; 4 import android.support.annotation.IntDef;
  5 +import android.text.TextUtils;
6 6
7 import com.cnlive.libs.base.R; 7 import com.cnlive.libs.base.R;
8 import com.cnlive.libs.base.model.IBaseInfo; 8 import com.cnlive.libs.base.model.IBaseInfo;
@@ -22,18 +22,32 @@ import retrofit2.adapter.rxjava2.Result; @@ -22,18 +22,32 @@ import retrofit2.adapter.rxjava2.Result;
22 22
23 public abstract class Subscriber<T extends IBaseInfo> { 23 public abstract class Subscriber<T extends IBaseInfo> {
24 24
25 - private T pageData; 25 + private Response<T> response;
26 private Context context; 26 private Context context;
27 private Config config; 27 private Config config;
28 28
29 - public Subscriber(Context context) { 29 + public Subscriber(@NonNull Context context) {
30 this.context = context; 30 this.context = context;
31 this.config = new Config(); 31 this.config = new Config();
  32 + init();
32 } 33 }
33 34
34 - public Subscriber(Context context, Config config) { 35 + public Subscriber(@NonNull Context context, @NonNull Config config) {
35 this.context = context; 36 this.context = context;
36 this.config = config; 37 this.config = config;
  38 + init();
  39 + }
  40 +
  41 + private String reloadString(String str, int defRes) {
  42 + return TextUtils.isEmpty(str) ? context.getString(defRes) : str;
  43 + }
  44 +
  45 + private void init() {
  46 + config.load_success_message = reloadString(config.load_success_message, R.string.load_success_message);
  47 + config.load_failure_message = reloadString(config.load_failure_message, R.string.load_failure_message);
  48 + config.load_error_message = reloadString(config.load_error_message, R.string.load_error_message);
  49 + config.no_network_message = reloadString(config.no_network_message, R.string.no_network_message);
  50 + config.unknown_error_message = reloadString(config.no_network_message, R.string.no_network_message);
37 } 51 }
38 52
39 public static Config newConfig() { 53 public static Config newConfig() {
@@ -43,10 +57,7 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; { @@ -43,10 +57,7 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; {
43 public Consumer<Result<T>> next = new Consumer<Result<T>>() { 57 public Consumer<Result<T>> next = new Consumer<Result<T>>() {
44 @Override 58 @Override
45 public void accept(Result<T> data) throws Exception { 59 public void accept(Result<T> data) throws Exception {
46 - Response<T> response = data.response();  
47 - if (response != null) pageData = response.body();  
48 - else if (!NetworkUtil.isConnectInternet(context)) onNetworkNoConnected();  
49 - else onError(config.load_failure_code, config.load_failure_message); 60 + response = data == null ? null : data.response();
50 } 61 }
51 }; 62 };
52 63
@@ -64,21 +75,20 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; { @@ -64,21 +75,20 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; {
64 public Action complete = new Action() { 75 public Action complete = new Action() {
65 @Override 76 @Override
66 public void run() throws Exception { 77 public void run() throws Exception {
67 - if (pageData != null && config.load_success_code.equals(pageData.getCode())) {  
68 - onCompleted(config.load_success_code, config.load_success_message, pageData);  
69 - } else if (pageData != null) {  
70 - if (config.custom_map.containsKey(pageData.getCode())) {  
71 - onError(pageData.getCode(), config.custom_map.get(pageData.getCode()));  
72 -  
73 - if (config.customLoadResponse != null)  
74 - config.customLoadResponse.onCustomEvent(pageData.getCode(), pageData);  
75 - } else {  
76 - onError(pageData.getCode(), pageData.getMessage());  
77 - }  
78 - } else {  
79 - if (context != null && !NetworkUtil.isConnectInternet(context))  
80 - onNetworkNoConnected(); 78 + if (response == null) {
  79 + if (!NetworkUtil.isConnectInternet(context)) onNetworkNoConnected();
81 else onError(config.unknown_error_code, config.unknown_error_message); 80 else onError(config.unknown_error_code, config.unknown_error_message);
  81 + } else {
  82 + T pageData = response.body();
  83 +
  84 + if (pageData != null && config.load_success_code.equals(pageData.getCode()))
  85 + onCompleted(config.load_success_code, config.load_success_message, pageData);
  86 + else if (pageData != null)
  87 + if (config.customLoadResponse != null && config.custom_map.containsKey(pageData.getCode()))
  88 + config.customLoadResponse.onCustomEvent(pageData.getCode(), pageData.getMessage(), pageData);
  89 + else onError(pageData.getCode(), pageData.getMessage());
  90 + else if (context != null && !NetworkUtil.isConnectInternet(context)) onNetworkNoConnected();
  91 + else onError(config.load_failure_code, config.load_failure_message);
82 } 92 }
83 } 93 }
84 }; 94 };
@@ -102,7 +112,7 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; { @@ -102,7 +112,7 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; {
102 } 112 }
103 113
104 public interface CustomLoadResponse { 114 public interface CustomLoadResponse {
105 - void onCustomEvent(String code, IBaseInfo pageData); 115 + void onCustomEvent(String code, String message, IBaseInfo pageData);
106 } 116 }
107 117
108 public static class Config { 118 public static class Config {
@@ -125,19 +135,19 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; { @@ -125,19 +135,19 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; {
125 public static final String default_unknown_error_code = "-4"; 135 public static final String default_unknown_error_code = "-4";
126 136
127 private String load_success_code = default_success_code; 137 private String load_success_code = default_success_code;
128 - private String load_success_message = Resources.getSystem().getString(R.string.load_success_message); 138 + private String load_success_message;
129 139
130 private String load_failure_code = default_failure_code; 140 private String load_failure_code = default_failure_code;
131 - private String load_failure_message = Resources.getSystem().getString(R.string.load_failure_message); 141 + private String load_failure_message;
132 142
133 private String load_error_code = default_error_code; 143 private String load_error_code = default_error_code;
134 - private String load_error_message = Resources.getSystem().getString(R.string.load_error_message); 144 + private String load_error_message;
135 145
136 private String no_network_code = default_no_network_code; 146 private String no_network_code = default_no_network_code;
137 - private String no_network_message = Resources.getSystem().getString(R.string.no_network_message); 147 + private String no_network_message;
138 148
139 private String unknown_error_code = default_unknown_error_code; 149 private String unknown_error_code = default_unknown_error_code;
140 - private String unknown_error_message = Resources.getSystem().getString(R.string.no_network_message); 150 + private String unknown_error_message;
141 151
142 /** 152 /**
143 * Custom event map , value{code : message} 153 * Custom event map , value{code : message}
@@ -183,24 +193,24 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; { @@ -183,24 +193,24 @@ public abstract class Subscriber&lt;T extends IBaseInfo&gt; {
183 public Config removeInfo(@RESPONSE_TYPE int type) { 193 public Config removeInfo(@RESPONSE_TYPE int type) {
184 switch (type) { 194 switch (type) {
185 case response_success: 195 case response_success:
186 - this.load_success_code = "0";  
187 - this.load_success_message = Resources.getSystem().getString(R.string.load_success_message); 196 + this.load_success_code = default_success_code;
  197 + this.load_success_message = null;
188 break; 198 break;
189 case response_failure: 199 case response_failure:
190 - this.load_failure_code = "-1";  
191 - this.load_failure_message = Resources.getSystem().getString(R.string.load_failure_message); 200 + this.load_failure_code = default_failure_code;
  201 + this.load_failure_message = null;
192 break; 202 break;
193 case response_error: 203 case response_error:
194 - this.load_error_code = "-2";  
195 - this.load_error_message = Resources.getSystem().getString(R.string.load_error_message); 204 + this.load_error_code = default_error_code;
  205 + this.load_error_message = null;
196 break; 206 break;
197 case response_no_network: 207 case response_no_network:
198 - this.no_network_code = "-3";  
199 - this.no_network_message = Resources.getSystem().getString(R.string.no_network_message); 208 + this.no_network_code = default_no_network_code;
  209 + this.no_network_message = null;
200 break; 210 break;
201 case response_unknown: 211 case response_unknown:
202 - this.unknown_error_code = "-4";  
203 - this.unknown_error_message = Resources.getSystem().getString(R.string.no_network_message); 212 + this.unknown_error_code = default_unknown_error_code;
  213 + this.unknown_error_message = null;
204 break; 214 break;
205 } 215 }
206 return this; 216 return this;
cnlive/src/main/res/values/strings.xml
@@ -6,6 +6,4 @@ @@ -6,6 +6,4 @@
6 <string name="load_error_message">数据加载错误</string> 6 <string name="load_error_message">数据加载错误</string>
7 <string name="no_network_message">未检测到网络</string> 7 <string name="no_network_message">未检测到网络</string>
8 <string name="unknown_error_message">未知错误</string> 8 <string name="unknown_error_message">未知错误</string>
9 -  
10 - <string name="custom_response_message">自定义响应</string>  
11 </resources> 9 </resources>