浏览代码

[공통][New] 다중 접속 로직 추가

hyodong.min 6 年之前
父节点
当前提交
05a5416d6e

+ 16 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/bean/api/LifeplusAPIBean.java

@@ -22,6 +22,7 @@ public class LifeplusAPIBean extends JsonBeanBase implements APIBean {
   public static int RETURN_DEFAULT = -1000;
   public static int RETURN_SUCCESS = 0;
   public static int RETURN_PARAMETER_ERROR = -1;
+  public static int RETURN_MULTI_DEVICE = -2222;
   public static int RETURN_MOBILE_AUTH_ERROR_UNDER_14_YEARS = -2;
   public static int RETURN_MOBILE_AUTH_ERROR_NEED_FOR_30_DAYS = -900;
   public static int RETURN_MOBILE_AUTH_ERROR_ALREADY_MEMBER = -400;
@@ -68,4 +69,19 @@ public class LifeplusAPIBean extends JsonBeanBase implements APIBean {
   public boolean isSuccess() {
     return code == RETURN_SUCCESS;
   }
+
+  /**
+   * 응급 상황 판단
+   *
+   * @return
+   */
+  @Override
+  public boolean isEmergency() {
+    return code == RETURN_MULTI_DEVICE;
+  }
+  
+  @Override
+  public int getEmergencyCode() {
+    return code;
+  }
 }

+ 11 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/bean/api/coop/CoopAPIBean.java

@@ -57,7 +57,18 @@ public class CoopAPIBean extends JsonBeanBase implements APIBean {
    *
    * @return
    */
+  @Override
   public boolean isSuccess() {
     return RETURN_SUCCESS.equals(code);
   }
+
+  @Override
+  public boolean isEmergency() {
+    return false;
+  }
+
+  @Override
+  public int getEmergencyCode() {
+    return 0;
+  }
 }

+ 6 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/model/module/APIModule.java

@@ -62,6 +62,9 @@ public abstract class APIModule<T extends JsonBeanBase, B extends APIBean> imple
       if (resultBean.isSuccess()) {
         listener.onApiSuccess(resultBean);
       }
+      else if (resultBean.isEmergency()) {
+        APIModuleHelper.dispatchEmergencyEvent(resultBean);
+      }
       else {
         listener.onApiReason(resultBean);
       }
@@ -89,6 +92,9 @@ public abstract class APIModule<T extends JsonBeanBase, B extends APIBean> imple
       if (resultBean.isSuccess()) {
         listener.onApiSuccess(resultBean);
       }
+      else if (resultBean.isEmergency()) {
+        APIModuleHelper.dispatchEmergencyEvent(resultBean);
+      }
       else {
         listener.onApiError(resultBean.getReturnMessage(), new APIError(APIError.ERROR_REASON));
       }

+ 64 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/model/module/APIModuleHelper.java

@@ -0,0 +1,64 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.model.module;
+
+import kr.co.zumo.app.lifeplus.bean.api.APIBean;
+
+/**
+ * APIModuleHelper
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 1. 30.]   [최초 작성]
+ * @since 2019. 1. 30.
+ */
+public class APIModuleHelper {
+  private static IModuleEmergencyHandler emergencyHandler;
+
+  /**
+   * handler 지정
+   *
+   * @param handler
+   */
+  public static void setEmergencyHandler(IModuleEmergencyHandler handler) {
+    emergencyHandler = handler;
+  }
+
+  /**
+   * handler 제거
+   * - 이미 다른 핸들러가 지정되어 있다면 제거하지 못한다.
+   *
+   * @param handler
+   */
+  public static void clearEmergencyHandler(IModuleEmergencyHandler handler) {
+    if (emergencyHandler.equals(handler)) {
+      emergencyHandler = null;
+    }
+  }
+
+  /**
+   * handler 반환
+   *
+   * @return
+   */
+  public static IModuleEmergencyHandler getEmergencyHandler() {
+    return emergencyHandler;
+  }
+
+  /**
+   * emergency event 송출
+   *
+   * @param apiBean
+   */
+  public static void dispatchEmergencyEvent(APIBean apiBean) throws Exception {
+    if (null != emergencyHandler) {
+      emergencyHandler.onApiEmergency(apiBean);
+    }
+    else {
+      throw new Exception("Unhandled emergency event");
+    }
+  }
+}

+ 20 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/model/module/IModuleEmergencyHandler.java

@@ -0,0 +1,20 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.model.module;
+
+import kr.co.zumo.app.lifeplus.bean.api.APIBean;
+
+/**
+ * IModuleEmergencyHandler
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 1. 30.]   [최초 작성]
+ * @since 2019. 1. 30.
+ */
+public interface IModuleEmergencyHandler {
+  void onApiEmergency(APIBean resultBean);
+}

+ 19 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/ConfirmDialog.java

@@ -28,6 +28,8 @@ public class ConfirmDialog extends TextDialog<ICustomConfirmListener<ConfirmDial
   protected int positiveButtonLabel = R.string.empty_string;
   @StringRes
   protected int negativeButtonLabel = R.string.empty_string;
+  @StringRes
+  protected int titleStringId = R.string.empty_string;
 
   /**
    * 표시할 positiveButtonLabel 지정
@@ -38,10 +40,24 @@ public class ConfirmDialog extends TextDialog<ICustomConfirmListener<ConfirmDial
     this.positiveButtonLabel = stringId;
   }
 
+  /**
+   * 표시할 negativeButtonLabel 지정
+   *
+   * @param stringId
+   */
   public void setNegativeButtonLabelId(@StringRes int stringId) {
     this.negativeButtonLabel = stringId;
   }
 
+  /**
+   * Title string id
+   *
+   * @param stringId
+   */
+  public void setTitleId(@StringRes int stringId) {
+    this.titleStringId = stringId;
+  }
+
   @NonNull
   @Override
   public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -71,6 +87,9 @@ public class ConfirmDialog extends TextDialog<ICustomConfirmListener<ConfirmDial
           }
         }
       });
+    if (titleStringId != R.string.empty_string) {
+      builder.setTitle(titleStringId);
+    }
     // Create the AlertDialog object and return it
     return builder.create();
 

+ 58 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/presenter/Presenter.java

@@ -18,6 +18,8 @@ import kr.co.zumo.app.lifeplus.bean.BucketDeliveryBean;
 import kr.co.zumo.app.lifeplus.bean.ContentsDeliveryBean;
 import kr.co.zumo.app.lifeplus.bean.ContentsWebDeliveryBean;
 import kr.co.zumo.app.lifeplus.bean.UtilityActivityBean;
+import kr.co.zumo.app.lifeplus.bean.api.APIBean;
+import kr.co.zumo.app.lifeplus.bean.api.LifeplusAPIBean;
 import kr.co.zumo.app.lifeplus.bean.api.LifeplusContentsBean;
 import kr.co.zumo.app.lifeplus.bean.api.LinkBean;
 import kr.co.zumo.app.lifeplus.helper.Helper;
@@ -25,6 +27,8 @@ import kr.co.zumo.app.lifeplus.helper.IHelperProvider;
 import kr.co.zumo.app.lifeplus.helper.NavigationBar;
 import kr.co.zumo.app.lifeplus.model.IModelResult;
 import kr.co.zumo.app.lifeplus.model.Model;
+import kr.co.zumo.app.lifeplus.model.module.APIModuleHelper;
+import kr.co.zumo.app.lifeplus.model.module.IModuleEmergencyHandler;
 import kr.co.zumo.app.lifeplus.network.INetworkReceiverListener;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
 import kr.co.zumo.app.lifeplus.supervisor.screen.Screen;
@@ -33,12 +37,12 @@ import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.IEventListener;
 import kr.co.zumo.app.lifeplus.view.IView;
 import kr.co.zumo.app.lifeplus.view.IWaiterCallable;
+import kr.co.zumo.app.lifeplus.view.animation.Loading;
 import kr.co.zumo.app.lifeplus.view.command.Command;
 import kr.co.zumo.app.lifeplus.view.command.EmailSendingCommand;
 import kr.co.zumo.app.lifeplus.view.command.ExitCommand;
 import kr.co.zumo.app.lifeplus.view.command.FinishActivityCommand;
 import kr.co.zumo.app.lifeplus.view.command.ScreenCommand;
-import kr.co.zumo.app.lifeplus.view.animation.Loading;
 import kr.co.zumo.app.lifeplus.view.dialog.AlertDialog;
 import kr.co.zumo.app.lifeplus.view.dialog.ConfirmDialog;
 import kr.co.zumo.app.lifeplus.view.dialog.DialogBase;
@@ -59,7 +63,7 @@ import kr.co.zumo.app.lifeplus.view.screen.main.SystemPopupModelHelper;
  * @history 민효동   [2018. 9. 21.]   [최초 작성]
  * @since 2018. 9. 21.
  */
-public abstract class Presenter<M extends Model, V extends IView> implements ILifeCycle, INetworkReceiverListener, IModelResult, IEventListener, IHelperProvider, IWaiterCallable {
+public abstract class Presenter<M extends Model, V extends IView> implements ILifeCycle, INetworkReceiverListener, IModelResult, IEventListener, IHelperProvider, IWaiterCallable, IModuleEmergencyHandler {
 
   protected M model;
   protected V view;
@@ -81,6 +85,8 @@ public abstract class Presenter<M extends Model, V extends IView> implements ILi
     this.model.setNetworkListener(this);
     this.model.setHelperProvider(this);
     this.model.setWaiterCaller(this);
+
+    APIModuleHelper.setEmergencyHandler(this);
   }
 
   @Override
@@ -489,6 +495,42 @@ public abstract class Presenter<M extends Model, V extends IView> implements ILi
       .show();
   }
 
+  /***********************************
+   * Popup - multi device
+   ***********************************/
+  protected void showPopupMultiDevice() {
+    new DialogBuilder<ConfirmDialog, ICustomConfirmListener>(getFragmentManager(), DialogID.CONFIRM)
+      .listener(new ICustomConfirmListener<ConfirmDialog>() {
+        @Override
+        public void onPositiveResult(ConfirmDialog dialog, Event event) {
+          dialog.dispose();
+          // 잠금 화면으로 이동
+          go(ScreenID.MAIN_PIN_UNLOCK);
+        }
+
+        @Override
+        public void onNegativeResult(ConfirmDialog dialog, Event event) {
+          dialog.dispose();
+          // 앱 종료
+          onCommand(new ExitCommand());
+        }
+
+        @Override
+        public void onDialogCanceled(ConfirmDialog dialog) {
+          dialog.dispose();
+          // 앱 종료
+          onCommand(new ExitCommand());
+        }
+      })
+      .attribute(dialog -> {
+        dialog.setTitleId(R.string.emergency_multi_device_title);
+        dialog.setText(ResourceUtil.getString(R.string.emergency_multi_device));
+        dialog.setNegativeButtonLabelId(R.string.emergency_multi_device_button_negative);
+        dialog.setPositiveButtonLabelId(R.string.emergency_multi_device_button_positive);
+      })
+      .show();
+  }
+
   /***********************************
    * navigation
    ***********************************/
@@ -597,6 +639,20 @@ public abstract class Presenter<M extends Model, V extends IView> implements ILi
     }
   }
 
+  /***********************************
+   * IModuleEmergencyHandler
+   ***********************************/
+  @Override
+  public void onApiEmergency(APIBean resultBean) {
+    /*
+    멀티 디바이스 사용 등의 경우 api 호출 시 특정 값을 반환하므로 이를 처리한다.
+     */
+    if (resultBean.getEmergencyCode() == LifeplusAPIBean.RETURN_MULTI_DEVICE) {
+      // 멀티 디바이스
+      showPopupMultiDevice();
+    }
+  }
+
   /***********************************
    * IWaiterCallable
    ***********************************/

+ 5 - 0
app/src/main/res/values/strings.xml

@@ -600,6 +600,11 @@
   <string name="menu_check_message2">상황에 따라 점검 시간이 단축/연장될 수 있습니다.</string>
   <string name="not_show_today">오늘 하루 보지 않기</string>
 
+  <string name="emergency_multi_device_title">동시접속 감지</string>
+  <string name="emergency_multi_device_button_negative">앱 종료</string>
+  <string name="emergency_multi_device_button_positive">계속 사용</string>
+  <string name="emergency_multi_device">새로운 기기에서 동일한 계정 접속이 감지되었습니다. 현재 기기를 계속 사용하시겠어요?</string>
+
   <string name="kakaotalk">카카오톡</string>
   <string name="facebook">페이스북</string>
   <string name="url">URL 복사</string>