Browse Source

[설정][New] 약관 전체 선택 모듈 추가

hyodong.min 7 năm trước cách đây
mục cha
commit
91da774262

+ 0 - 26
app/src/main/java/kr/co/zumo/app/lifeplus/model/module/APIMemberPolicyAllUpdateModule.java

@@ -1,26 +0,0 @@
-/*
- * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
- */
-package kr.co.zumo.app.lifeplus.model.module;
-
-import io.reactivex.Single;
-import kr.co.zumo.app.lifeplus.bean.api.LifeplusAPIBean;
-import kr.co.zumo.app.lifeplus.bean.api.MemberPolicyAllRequestBean;
-
-/**
- * APIMemberPolicyUpdateModule
- * <pre>
- * </pre>
- *
- * @author 민효동
- * @version 1.0
- * @history 민효동   [2018. 11. 9.]   [최초 작성]
- * @since 2018. 11. 9.
- */
-public class APIMemberPolicyAllUpdateModule extends APIModule<MemberPolicyAllRequestBean, LifeplusAPIBean> {
-  @Override
-  protected Single<LifeplusAPIBean> getAPI(MemberPolicyAllRequestBean requestBean) {
-    return null;
-  }
-}
-

+ 49 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/model/module/APIMemberPolicyUpdateAllModule.java

@@ -0,0 +1,49 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.model.module;
+
+import io.reactivex.Observable;
+import io.reactivex.ObservableSource;
+import io.reactivex.Single;
+import io.reactivex.functions.Function;
+import io.reactivex.schedulers.Schedulers;
+import kr.co.zumo.app.lifeplus.bean.api.LifeplusAPIBean;
+import kr.co.zumo.app.lifeplus.bean.api.LifeplusData;
+import kr.co.zumo.app.lifeplus.bean.api.MemberPolicyAllRequestBean;
+import kr.co.zumo.app.lifeplus.bean.api.MemberPolicyRequestBean;
+import kr.co.zumo.app.lifeplus.bean.api.PolicyBean;
+import kr.co.zumo.app.lifeplus.network.api.LifeplusAPIRepository;
+
+/**
+ * APIMemberPolicyUpdateAllModule
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018. 11. 9.]   [최초 작성]
+ * @since 2018. 11. 9.
+ */
+public class APIMemberPolicyUpdateAllModule extends APIModule<MemberPolicyAllRequestBean, LifeplusAPIBean> {
+  @Override
+  protected Single<LifeplusAPIBean> getAPI(MemberPolicyAllRequestBean requestBean) {
+    return Observable.fromIterable(requestBean.getInfoAgreeList())   // 배열에서 가져옴
+      .concatMap((Function<PolicyBean, ObservableSource<LifeplusAPIBean>>) policyBean -> {  // 개별 API 를 호출한다.
+        MemberPolicyRequestBean policyRequestBean = new MemberPolicyRequestBean(policyBean.getPolicyNumber(), LifeplusData.booleanOf(requestBean.isChecked()));
+        return new LifeplusAPIRepository().setMemberPolicyAgree(policyRequestBean).subscribeOn(Schedulers.io()).toObservable();
+      })
+      .toList()   // 결과를 배열로.
+      .map(lifeplusAPIBeans -> {    // 에러가 없으면 성공.
+        int result = LifeplusAPIBean.RETURN_SUCCESS;
+        for (LifeplusAPIBean lifeplusAPIBean : lifeplusAPIBeans) {
+          if (lifeplusAPIBean.isSuccess() == false) {
+            result = LifeplusAPIBean.RETURN_PARAMETER_ERROR;
+            break;
+          }
+        }
+        return new LifeplusAPIBean(result, result == LifeplusAPIBean.RETURN_SUCCESS ? "" : "하나 이상 에러 있음.");
+      });
+  }
+}
+

+ 1 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/setting/common/SettingMemberInfoFragment.java

@@ -291,6 +291,7 @@ public class SettingMemberInfoFragment extends FragmentBase<SettingMemberInfoPre
   @Override
   public void setPolicyCheckAll(boolean isChecked) {
     checkBoxAllDriver.applyCheckAll(isChecked);
+    checkBoxAllDriver.check();
   }
 
   @Override

+ 35 - 30
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/setting/common/SettingMemberInfoModel.java

@@ -3,16 +3,9 @@
  */
 package kr.co.zumo.app.lifeplus.view.screen.setting.common;
 
-import android.util.Log;
+import java.util.ArrayList;
 
-import java.util.List;
-
-import io.reactivex.Observable;
-import io.reactivex.ObservableSource;
 import io.reactivex.disposables.Disposable;
-import io.reactivex.functions.Consumer;
-import io.reactivex.functions.Function;
-import io.reactivex.schedulers.Schedulers;
 import kr.co.zumo.app.lifeplus.bean.api.LifeplusAPIBean;
 import kr.co.zumo.app.lifeplus.bean.api.LifeplusData;
 import kr.co.zumo.app.lifeplus.bean.api.MemberEmailRequestBean;
@@ -24,10 +17,10 @@ import kr.co.zumo.app.lifeplus.bean.api.SettingMemberBean;
 import kr.co.zumo.app.lifeplus.model.Model;
 import kr.co.zumo.app.lifeplus.model.module.APIMemberEmailUpdateModule;
 import kr.co.zumo.app.lifeplus.model.module.APIMemberMarketingUpdateModule;
+import kr.co.zumo.app.lifeplus.model.module.APIMemberPolicyUpdateAllModule;
 import kr.co.zumo.app.lifeplus.model.module.APIMemberPolicyUpdateModule;
 import kr.co.zumo.app.lifeplus.model.module.IAPIModuleListener;
 import kr.co.zumo.app.lifeplus.model.verify.Verifier;
-import kr.co.zumo.app.lifeplus.network.api.LifeplusAPIRepository;
 import kr.co.zumo.app.lifeplus.util.StringUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.screen.setting.SettingModelHelper;
@@ -180,28 +173,40 @@ public class SettingMemberInfoModel extends Model {
    * @param isChecked
    */
   public void updatePolicyAll(boolean isChecked) {
+    if (null == settingMemberBean || null == settingMemberBean.getInfoAgreeList()) {
+      onResult(new Event.Builder(Event.ERROR).integer(Event.MEMBER_UPDATE_POLICY_ALL).bool(isChecked).string("").build());
+      return;
+    }
+    setCheckAll(isChecked);
     MemberPolicyAllRequestBean requestBean = new MemberPolicyAllRequestBean(settingMemberBean.getInfoAgreeList(), isChecked);
-    disposablePolicyAll = Observable.fromIterable(requestBean.getInfoAgreeList())
-      .concatMap(new Function<PolicyBean, ObservableSource<LifeplusAPIBean>>() {
-        @Override
-        public ObservableSource<LifeplusAPIBean> apply(PolicyBean policyBean) throws Exception {
-          Log.w("APP# APIMemberPolicyAllUpdateModule | apply", "| int: " + policyBean.toJson());
-          MemberPolicyRequestBean policyRequestBean = new MemberPolicyRequestBean(policyBean.getPolicyNumber(), LifeplusData.booleanOf(requestBean.isChecked()));
-          return new LifeplusAPIRepository().setMemberPolicyAgree(policyRequestBean).subscribeOn(Schedulers.io()).toObservable();
-        }
-      })
-      .toList()
-      .subscribe(new Consumer<List<LifeplusAPIBean>>() {
-        @Override
-        public void accept(List<LifeplusAPIBean> lifeplusAPIBeans) throws Exception {
-          Log.e("APP#  SettingMemberInfoModel | accept", "|" + lifeplusAPIBeans.size());
-          for (Object object : lifeplusAPIBeans) {
-            Log.w("APP# SettingMemberInfoModel | accept", "|" + object.toString());
-          }
-        }
-      });
-
-    // fixme 3개 결과는 옴...........
+
+    disposablePolicyAll = new APIMemberPolicyUpdateAllModule().call(requestBean, new IAPIModuleListener<LifeplusAPIBean>() {
+      @Override
+      public void onApiSuccess(LifeplusAPIBean resultBean) {
+        onResult(new Event.Builder(Event.RESULT).integer(Event.MEMBER_UPDATE_POLICY_ALL).build());
+      }
+
+      @Override
+      public void onApiReason(LifeplusAPIBean resultBean) {
+        setCheckAll(!isChecked);
+        onResult(new Event.Builder(Event.ERROR).integer(Event.MEMBER_UPDATE_POLICY_ALL).bool(isChecked).string(resultBean.getReturnMessage()).build());
+
+      }
+
+      @Override
+      public void onApiError(String errorMessage) {
+        setCheckAll(!isChecked);
+        onResult(new Event.Builder(Event.ERROR).integer(Event.MEMBER_UPDATE_POLICY_ALL).bool(isChecked).string(errorMessage).build());
+
+      }
+    });
+  }
+
+  private void setCheckAll(boolean isChecked) {
+    ArrayList<PolicyBean> beans = settingMemberBean.getInfoAgreeList();
+    for (PolicyBean bean : beans) {
+      bean.setChecked(isChecked);
+    }
   }
 
   /**