Forráskód Böngészése

[회원가입][New] 탈퇴 버튼 및 API 연동

hyodong.min 7 éve
szülő
commit
3958841f5a

+ 13 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/activity/MainActivity.java

@@ -43,8 +43,8 @@ public class MainActivity extends ActivityBase<MainPresenter> implements IMainVi
     button.setOnClickListener(v -> {
       SuperModel.getInstance().getPreferences().setPermissionInfoDone(false);
       SuperModel.getInstance().getPreferences().setTutorialDone(false);
-      SuperModel.getInstance().getPreferences().setUserId("");
-      SuperModel.getInstance().getPreferences().setDeviceUuid("");
+      SuperModel.getInstance().setUserId("");
+      SuperModel.getInstance().setDeviceUuid("");
       SuperModel.getInstance().getPreferences().setEncryptedPin("");
       SuperModel.getInstance().getPreferences().setZumoUserUpdateCompleted(false);
       SuperModel.getInstance().getPreferences().setEncryptionUserNo("");
@@ -75,6 +75,17 @@ public class MainActivity extends ActivityBase<MainPresenter> implements IMainVi
       presenter.onEvent(new Event.Builder(Event.INPUT_PIN).build());
     });
 
+    button = findViewById(R.id.button_delete_account);
+    button.setOnClickListener(v -> {
+      presenter.onEvent(new Event.Builder(Event.DELETE).build());
+    });
+
+    button = findViewById(R.id.button_set_account);
+    button.setOnClickListener(v -> {
+      SuperModel.getInstance().setUserId("201507090000000279");
+    });
+
+
   }
 
   @Override

+ 4 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/bean/api/UserIDBean.java

@@ -21,6 +21,10 @@ public class UserIDBean extends JsonBeanBase {
   @SerializedName("user_no")
   private String userId;
 
+  public UserIDBean(String userId) {
+    this.userId = userId;
+  }
+
   public String getUserId() {
     return userId;
   }

+ 5 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/Event.java

@@ -55,13 +55,17 @@ public class Event {
   public static final int UNLOCK = 27;
   public static final int RESET = 28;
   public static final int FAQ = 29;
+  public static final int DELETE = 30;
+  public static final int MEMBER_DELETE_COMPLETED = 31;
+  public static final int MEMBER_DELETE_ERROR = 32;
 
 
   @Retention(RetentionPolicy.SOURCE)
   @IntDef({
     NONE, CLICK, BACK, SIGN_UP, LOGIN, CHECK, UNCHECK, JOINED, TUTORIAL_LEFT, TUTORIAL_RIGHT,
     RETRY, INPUT_PIN, NETWORK_CONNECTED, CHANGED, INIT, DETAIL, ERROR, UNLOCK, RESET,
-    SUCCESS, FAIL, CANCEL, EMAIL_CLICK, SPECIAL_CODE_CLICK, CONFIRM, RESULT, FAQ
+    SUCCESS, FAIL, CANCEL, EMAIL_CLICK, SPECIAL_CODE_CLICK, CONFIRM, RESULT, FAQ, DELETE,
+    MEMBER_DELETE_COMPLETED, MEMBER_DELETE_ERROR,
   })
   public @interface ID {}
 

+ 69 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/command/DeleteAccountCommand.java

@@ -0,0 +1,69 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.command;
+
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.disposables.Disposable;
+import io.reactivex.schedulers.Schedulers;
+import kr.co.zumo.app.lifeplus.bean.api.UserIDBean;
+import kr.co.zumo.app.lifeplus.model.Model;
+import kr.co.zumo.app.lifeplus.network.api.LifeplusAPIService;
+import kr.co.zumo.app.lifeplus.view.Event;
+import kr.co.zumo.app.lifeplus.view.IView;
+import kr.co.zumo.app.lifeplus.view.presenter.Presenter;
+
+/**
+ * ExitCommand
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018-09-22]   [최초 작성]
+ * @since 2018-09-22
+ */
+public class DeleteAccountCommand extends Command<Model, IView, Presenter> {
+
+  private Disposable disposable;
+  private String userId;
+
+  public DeleteAccountCommand(String userId) {
+    this.userId = userId;
+  }
+
+  @Override
+  public void preExecute(Model model, IView view, Presenter presenter) {
+
+  }
+
+  @Override
+  public void execute(Model model, IView view, Presenter presenter) {
+    disposable = new LifeplusAPIService().deleteMember(new UserIDBean(userId))
+      .subscribeOn(Schedulers.io())
+      .observeOn(AndroidSchedulers.mainThread())
+      .subscribe(resultBean -> {
+        if (resultBean.isSuccess()) {
+          presenter.onEvent(new Event.Builder(Event.MEMBER_DELETE_COMPLETED).build());
+        }
+        else {
+          presenter.onEvent(new Event.Builder(Event.MEMBER_DELETE_ERROR).string(resultBean.getReturnMessage()).build());
+        }
+      }, e -> {
+        presenter.onEvent(new Event.Builder(Event.MEMBER_DELETE_ERROR).string(e.getLocalizedMessage()).build());
+      });
+  }
+
+  @Override
+  public void postExecute(Model model, IView view, Presenter presenter) {
+
+  }
+
+  @Override
+  public void dispose() {
+    if (null != disposable) {
+      disposable.dispose();
+      disposable = null;
+    }
+  }
+}

+ 38 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/presenter/MainPresenter.java

@@ -4,11 +4,19 @@
 package kr.co.zumo.app.lifeplus.view.presenter;
 
 import kr.co.zumo.app.lifeplus.model.MainModel;
+import kr.co.zumo.app.lifeplus.model.SuperModel;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
 import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.IMainView;
 import kr.co.zumo.app.lifeplus.view.command.ActivityChangeCommand;
+import kr.co.zumo.app.lifeplus.view.command.DeleteAccountCommand;
 import kr.co.zumo.app.lifeplus.view.command.ExitCommand;
+import kr.co.zumo.app.lifeplus.view.dialog.AlertDialog;
+import kr.co.zumo.app.lifeplus.view.dialog.DialogBase;
+import kr.co.zumo.app.lifeplus.view.dialog.DialogBuilder;
+import kr.co.zumo.app.lifeplus.view.dialog.DialogID;
+import kr.co.zumo.app.lifeplus.view.dialog.IAttribute;
+import kr.co.zumo.app.lifeplus.view.dialog.IDialogResultListener;
 
 /**
  * MainPresenter
@@ -75,8 +83,38 @@ public class MainPresenter extends Presenter<MainModel, IMainView> {
       case Event.INPUT_PIN:
         onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_PIN, ScreenID.DIRECTION_NEXT));
         break;
+      case Event.DELETE:
+        onCommand(new DeleteAccountCommand(SuperModel.getInstance().getUserId()));
+        break;
+      case Event.MEMBER_DELETE_COMPLETED:
+        showAlert("탈퇴 완료");
+        break;
+      case Event.MEMBER_DELETE_ERROR:
+        showAlert("탈퇴 에러 발생 - " + event.getString());
+        break;
       default:
         break;
     }
   }
+
+  private void showAlert(String str) {
+
+    DialogBuilder.create(DialogID.ALERT)
+      .listener(new IDialogResultListener() {
+        @Override
+        public void onDialogResult(DialogBase dialog, Event event) {
+          if (event.getEventId() == Event.CONFIRM) {
+            dialog.dismiss();
+          }
+        }
+
+        @Override
+        public void onDialogCanceled(DialogBase dialog) {
+        }
+      })
+      .attribute((IAttribute<AlertDialog>) dialog -> {
+        dialog.setText(str);
+      })
+      .show();
+  }
 }

+ 32 - 0
app/src/main/res/layout/activity_main.xml

@@ -15,6 +15,38 @@
     android:gravity="bottom"
     android:orientation="vertical">
 
+    <LinearLayout
+      android:layout_width="match_parent"
+      android:layout_height="wrap_content"
+      android:gravity="bottom"
+      android:orientation="horizontal"
+      android:paddingStart="20dp"
+      android:paddingTop="10dp"
+      android:paddingEnd="20dp"
+      android:paddingBottom="10dp"
+      >
+
+      <Button
+        android:id="@+id/button_set_account"
+        style="@style/SignUpButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="Set Dummy Account"/>
+
+      <Button
+        android:id="@+id/button_delete_account"
+        style="@style/SignUpButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="Delete Account"/>
+
+      <Space
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"/>
+
+    </LinearLayout>
+
     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"

+ 2 - 2
app/src/main/res/layout/alert_dialog.xml

@@ -5,13 +5,13 @@
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
-  android:alpha="0.8"
-  android:background="@color/CFFFFFF"
+  android:background="#BBFFFFFF"
   android:gravity="center"
   android:orientation="vertical">
 
   <TextView
     tools:text="@string/tutorial_title_last"
+    android:textColor="@color/C000000"
     android:id="@+id/text_alert_message"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>