Browse Source

[공통][New] 체크박스 그룹을 관리하는 클래스
- 전체 선택, 선택 취소 등

hyodong.min 7 years ago
parent
commit
1995d6693f

+ 85 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/CheckBoxAllDriver.java

@@ -0,0 +1,85 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view;
+
+import android.widget.CheckBox;
+
+import java.util.ArrayList;
+
+/**
+ * CheckBoxAllDriver
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018. 9. 18.]   [최초 작성]
+ * @since 2018. 9. 18.
+ */
+public class CheckBoxAllDriver {
+
+  CheckBox allBox;
+  ArrayList<CheckBox> boxes;
+
+  public CheckBoxAllDriver(CheckBox allBox) {
+    this.allBox = allBox;
+    boxes = new ArrayList<>();
+  }
+
+  /**
+   * 체크 박스 추가
+   *
+   * @param box
+   */
+  public void addChildBox(CheckBox box) {
+    boxes.add(box);
+  }
+
+  /**
+   * 모든 버튼 체크
+   *
+   * @param isChecked true|false
+   */
+  private void checkAll(boolean isChecked) {
+    CheckBox checkBox;
+    int len = boxes.size();
+    for (int i = 0; i < len; ++i) {
+      checkBox = boxes.get(i);
+      checkBox.setChecked(isChecked);
+    }
+  }
+
+  /**
+   * 모든 버튼이 체크되어있다면 올박스를 체크한다.
+   */
+  private void applyCheckAll() {
+    CheckBox checkBox;
+    boolean isCheckedAll = true;
+    int len = boxes.size();
+    for (int i = 0; i < len; ++i) {
+      checkBox = boxes.get(i);
+      isCheckedAll = isCheckedAll & checkBox.isChecked();
+    }
+
+    allBox.setChecked(isCheckedAll);
+  }
+
+  /**
+   * 모든 버튼이 체크되어있다면 올박스를 체크한다.
+   */
+  public void check() {
+    applyCheckAll();
+  }
+
+  /**
+   * 모든 버튼이 체크되어있다면 올박스를 체크한다.
+   * - OnClickListener 에서 사용해야 제대로 작동함
+   */
+  public void applyCheckAll(boolean isChecked) {
+    checkAll(isChecked);
+
+    applyCheckAll();
+  }
+
+}

+ 6 - 6
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/IMobileAuthorizationDialog.java

@@ -13,42 +13,42 @@ package kr.co.zumo.app.lifeplus.view.dialog;
 public interface IMobileAuthorizationDialog {
   /**
    * name validation check
+   *
    * @param inputName
    */
   void doNameValidationMessage(String inputName);
 
   /**
    * nationality validation check
+   *
    * @param inputNationality
    */
   void doNationalityValidationMessage(String inputNationality);
 
   /**
    * birth date validation check
+   *
    * @param inputBirthDate
    */
   void doBirthDateValidationMessage(String inputBirthDate);
 
   /**
    * gender validation check
+   *
    * @param inputGender
    */
   void doGenderValidationMessage(String inputGender);
 
-  /**
-   * 전체 동의 체크 버튼  클릭 event
-   * @param isAllChecked
-   */
-  void onAllAgreedCheckBoxChecked(boolean isAllChecked);
-
   /**
    * 핸드폰 번호 validation check
+   *
    * @param inputPhoneNumber
    */
   void doPhoneNumberCheckedValidationMessage(String inputPhoneNumber);
 
   /**
    * 인증번호 validation check
+   *
    * @param inputAuthorizedNumber
    */
   void doAuthorizedNumberValidationMessage(String inputAuthorizedNumber);

+ 19 - 22
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/MobileAuthorizationDialog.java

@@ -21,6 +21,7 @@ import android.widget.Spinner;
 import android.widget.TextView;
 
 import kr.co.zumo.app.R;
+import kr.co.zumo.app.lifeplus.view.CheckBoxAllDriver;
 
 /**
  * MobileAuthorizationDialog
@@ -55,6 +56,7 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
   private TextView textViewPhoneIdentifyTime;
 
   private MobileAuthorizationPresenter presenter;
+  CheckBoxAllDriver checkBoxAllDriver;
 
 
   public MobileAuthorizationDialog() {
@@ -70,7 +72,7 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
   public void onCreate(Bundle savedInstanceState) {
     setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);
     presenter = new MobileAuthorizationPresenter(this);
-    if(null != resultListener) {
+    if (null != resultListener) {
       presenter.setResultListener(resultListener);
     }
     super.onCreate(savedInstanceState);
@@ -80,7 +82,7 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
   public void setResultListener(IDialogResultListener resultListener) {
     super.setResultListener(resultListener);
 
-    if(null != presenter) {
+    if (null != presenter) {
       presenter.setResultListener(resultListener);
     }
   }
@@ -159,6 +161,12 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
     editTextAuthorizedNumber = view.findViewById(R.id.edit_text_authorized_number);
     textViewPhoneIdentifyTime = view.findViewById(R.id.text_view_phone_identify_time);
 
+    checkBoxAllDriver = new CheckBoxAllDriver(checkBoxAllAgree);
+    checkBoxAllDriver.addChildBox(checkBoxAgree1);
+    checkBoxAllDriver.addChildBox(checkBoxAgree2);
+    checkBoxAllDriver.addChildBox(checkBoxAgree3);
+    checkBoxAllDriver.addChildBox(checkBoxAgree4);
+
     buttonConfirm.setOnClickListener(this);
     buttonTimeDelay.setOnClickListener(this);
     buttonIdentifyNumberSend.setOnClickListener(this);
@@ -269,17 +277,21 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
       }
     });
 
-    checkBoxAllAgree.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+    checkBoxAllAgree.setOnClickListener(new View.OnClickListener() {
       @Override
-      public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+      public void onClick(View v) {
+        boolean b = checkBoxAllAgree.isChecked();
+        checkBoxAllDriver.applyCheckAll(b);
         presenter.onAllAgreeCheckedChanged(b);
         Log.e("APP#  MobileAuthorizationDialog | onCheckedChanged", "|" + b);
+
       }
     });
 
     checkBoxAgree1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+        checkBoxAllDriver.check();
         Log.e("APP#  MobileAuthorizationDialog | onCheckedChanged", "|" + b);
         presenter.onAgree1CheckedChanged(b);
 
@@ -289,6 +301,7 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
     checkBoxAgree2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+        checkBoxAllDriver.check();
         Log.e("APP#  MobileAuthorizationDialog | onCheckedChanged", "|" + b);
         presenter.onAgree2CheckedChanged(b);
       }
@@ -297,6 +310,7 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
     checkBoxAgree3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+        checkBoxAllDriver.check();
         Log.e("APP#  MobileAuthorizationDialog | onCheckedChanged", "|" + b);
         presenter.onAgree3CheckedChanged(b);
       }
@@ -305,6 +319,7 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
     checkBoxAgree4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+        checkBoxAllDriver.check();
         Log.e("APP#  MobileAuthorizationDialog | onCheckedChanged", "|" + b);
         presenter.onAgree4CheckedChanged(b);
       }
@@ -352,24 +367,6 @@ public class MobileAuthorizationDialog extends DialogBase implements View.OnClic
 
   }
 
-  @Override
-  public void onAllAgreedCheckBoxChecked(boolean isAllChecked) {
-    if (isAllChecked) {
-      checkBoxAgree1.setChecked(true);
-      checkBoxAgree2.setChecked(true);
-      checkBoxAgree3.setChecked(true);
-      checkBoxAgree4.setChecked(true);
-
-    }
-    else {
-      checkBoxAgree1.setChecked(false);
-      checkBoxAgree2.setChecked(false);
-      checkBoxAgree3.setChecked(false);
-      checkBoxAgree4.setChecked(false);
-    }
-
-  }
-
   @Override
   public void doPhoneNumberCheckedValidationMessage(String inputPhoneNumber) {
 

+ 30 - 4
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/MobileAuthorizationPresenter.java

@@ -4,10 +4,11 @@ import android.util.Log;
 
 import java.util.Calendar;
 
+import kr.co.zumo.app.lifeplus.util.DateUtil;
 import kr.co.zumo.app.lifeplus.view.presenter.bean.SignUpUserBean;
 
 /**
- * IdentifyViewModel
+ * MobileAuthorizationPresenter
  * <pre>
  * </pre>
  *
@@ -48,6 +49,34 @@ public class MobileAuthorizationPresenter {
    */
   public void onBirthDateTextChanged(String inputBirthDate) {
     Log.e("APP#  MobileAuthorizationPresenter | onBirthDateTextChanged", "|" + inputBirthDate);
+
+    // 8자리 인지 확인
+    if (inputBirthDate.length() == 8) {
+      // 년 월 일 확인
+      int year = Integer.valueOf(inputBirthDate.substring(0, 4));
+      int month = Integer.valueOf(inputBirthDate.substring(4, 6));
+      int date = Integer.valueOf(inputBirthDate.substring(6, 8));
+
+      if (year > 0 && month <= 12 && month > 0 && date <= 31 && date > 0) {
+        Log.i("APP# MobileAuthorizationPresenter | onBirthDateTextChanged", "|" + year + " " + month + " " + date);
+
+        Calendar birthday = Calendar.getInstance();
+        birthday.set(year, month - 1, date);
+        boolean isOverAge = DateUtil.minAge(14, birthday.getTimeInMillis());
+
+        Log.i("APP# MobileAuthorizationPresenter | onBirthDateTextChanged", "| isOverAge: " + isOverAge);
+
+        if(isOverAge) {
+          // 14 세 이상 가입 가능
+        }
+        else {
+          // 14 세 미만 가입 불가 알림
+          // todo 14세 미만 알림
+        }
+
+      }
+    }
+
     userBean.setBirthDate(inputBirthDate);
   }
 
@@ -127,9 +156,6 @@ public class MobileAuthorizationPresenter {
   public void onAllAgreeCheckedChanged(boolean isChecked) {
     Log.e("APP#  MobileAuthorizationPresenter | onAllAgreeCheckedChanged", "|" + isChecked);
     userBean.setAllAgreed(isChecked);
-    view.onAllAgreedCheckBoxChecked(isChecked);
-
-
   }
 
   /**

+ 11 - 19
app/src/main/java/kr/co/zumo/app/lifeplus/view/fragment/signup/SignUpAgreeHolder.java

@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.model.SuperModel;
 import kr.co.zumo.app.lifeplus.util.ResourceUtil;
+import kr.co.zumo.app.lifeplus.view.CheckBoxAllDriver;
 import kr.co.zumo.app.lifeplus.view.presenter.Event;
 import kr.co.zumo.app.lifeplus.view.presenter.bean.SignUpAgreeItemBean;
 import kr.co.zumo.app.lifeplus.view.presenter.signup.SignUpItem;
@@ -30,9 +31,9 @@ import kr.co.zumo.app.lifeplus.view.presenter.signup.SignUpPresenter;
 public class SignUpAgreeHolder extends BaseViewHolder {
 
   ISignUpHolderEventListener listener;
-  private boolean isAgreeAll;
   ArrayList<SignUpAgreeItemBean> items;
   CheckBox checkBoxAll;
+  CheckBoxAllDriver checkBoxAllDriver;
   int len;
 
   public SignUpAgreeHolder(View itemView) {
@@ -42,29 +43,34 @@ public class SignUpAgreeHolder extends BaseViewHolder {
   @Override
   void draw(SignUpItem item) {
     items = ((SignUpPresenter) SuperModel.getInstance().getPresenter()).getAgreeItems();
-    isAgreeAll = false;
     listener = item.getEventListener();
 
-    checkBoxAll = (CheckBox) itemView.findViewById(R.id.agree_check_all);
+    checkBoxAll = itemView.findViewById(R.id.agree_check_all);
+
+    checkBoxAllDriver = new CheckBoxAllDriver(checkBoxAll);
+
     checkBoxAll.setText(R.string.all_agree);
     checkBoxAll.setOnClickListener(v -> {
+      checkBoxAllDriver.applyCheckAll(checkBoxAll.isChecked());
       checkAll(checkBoxAll.isChecked());
-      judgeAgreeAll();
       notifyAgreeChanged();
     });
 
+
     len = items.size();
     CheckBox checkBox;
     View view; //maybe image view
     for (int i = 0; i < len; ++i) {
       checkBox = getCheckBoxByIndex(i);
+      checkBoxAllDriver.addChildBox(checkBox);
+
       SignUpAgreeItemBean bean = items.get(i);
       checkBox.setText(new StringBuilder().append(bean.isRequired() ? ResourceUtil.getString(R.string.agree_required) : ResourceUtil.getString(R.string.agree_option)).append(bean.getText()).toString());
       checkBox.setChecked(bean.isChecked());
       checkBox.setEnabled(bean.isEnabled());
       checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
         bean.setChecked(isChecked);
-        judgeAgreeAll();
+        checkBoxAllDriver.check();
         notifyAgreeChanged();
       });
       int index = i;
@@ -98,17 +104,6 @@ public class SignUpAgreeHolder extends BaseViewHolder {
     return itemView.findViewById(ResourceUtil.getId("agree_check" + index));
   }
 
-  private void judgeAgreeAll() {
-    CheckBox checkBox;
-    isAgreeAll = true;
-    for (int i = 0; i < len; ++i) {
-      checkBox = getCheckBoxByIndex(i);
-      isAgreeAll = isAgreeAll & checkBox.isChecked();
-    }
-
-    checkBoxAll.setChecked(isAgreeAll);
-  }
-
   private void notifyAgreeChanged() {
     listener.onSignUpHolderEvent(this, Event.HOLDER_AGREE_CHANGED);
   }
@@ -119,13 +114,10 @@ public class SignUpAgreeHolder extends BaseViewHolder {
   }
 
   private void checkAll(boolean isChecked) {
-    CheckBox checkBox;
     SignUpAgreeItemBean bean;
     for (int i = 0; i < len; ++i) {
       bean = items.get(i);
       bean.setChecked(isChecked);
-      checkBox = getCheckBoxByIndex(i);
-      checkBox.setChecked(isChecked);
     }
   }
 

+ 1 - 0
app/src/main/res/layout/sign_up_phone_identify_dialog.xml

@@ -125,6 +125,7 @@
         android:layout_weight="2"
         android:background="@drawable/input_border"
         android:hint="@string/phone_identify_birth_hint"
+        android:maxLength="8"
         android:inputType="number"
         android:padding="3pt"/>
 

+ 5 - 0
app/src/test/java/kr/co/zumo/app/lifeplus/util/DateUtilTest.java

@@ -42,6 +42,11 @@ public class DateUtilTest {
     birthdayMillis = birthday.getTimeInMillis();
 
     assertFalse(DateUtil.minAge(14, birthdayMillis));
+    birthday = Calendar.getInstance();
+    birthday.set(2105, Calendar.APRIL, 22);
+    birthdayMillis = birthday.getTimeInMillis();
+
+    assertFalse(DateUtil.minAge(14, birthdayMillis));
 
   }
 }