|
|
@@ -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);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|