Browse Source

[공통][Common] alert 과 confim dialog 통합

hyodong.min 6 years ago
parent
commit
773962d3fa

+ 17 - 115
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/AlertDialog.java

@@ -3,16 +3,12 @@
  */
 package kr.co.zumo.app.lifeplus.view.dialog;
 
-import android.app.Dialog;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.StringRes;
+import android.support.constraint.ConstraintLayout;
+import android.support.constraint.ConstraintSet;
 import android.view.KeyEvent;
 import android.view.View;
-import android.widget.ImageView;
-import android.widget.TextView;
 
-import kr.co.zumo.app.R;
+import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
 
 /**
@@ -25,85 +21,7 @@ import kr.co.zumo.app.lifeplus.view.Event;
  * @history 민효동   [2018. 9. 23.]   [최초 작성]
  * @since 2018. 9. 23.
  */
-public class AlertDialog extends TextDialog<ICustomDialogListener<AlertDialog>> {
-
-  protected boolean isCancelable = true;
-
-  protected boolean isTransparent;
-
-  @StringRes
-  protected int positiveButtonLabel = R.string.empty_string;
-  @StringRes
-  protected int titleStringId = R.string.empty_string;
-
-  private TextView textViewPositiveButton;
-
-  private boolean isVisibleCloseButton;
-
-  /**
-   * 표시할 positiveButtonLabel 지정
-   *
-   * @param stringId
-   */
-  public void setPositiveButtonLabelId(@StringRes int stringId) {
-    this.positiveButtonLabel = stringId;
-  }
-
-
-  /**
-   * 표시할 title 지정
-   *
-   * @param stringId
-   */
-  public void setTitleId(@StringRes int stringId) {this.titleStringId = stringId;}
-
-  /**
-   * back key 가능 여부 설정
-   *
-   * @param cancelable
-   */
-  @Override
-  public void setCancelable(boolean cancelable) {
-    super.setCancelable(cancelable);
-    isCancelable = cancelable;
-  }
-
-  /**
-   * 닫기 버튼 표시
-   *
-   * @param isVisibleCloseButton
-   */
-  public void setVisibleCloseButton(boolean isVisibleCloseButton) {this.isVisibleCloseButton = isVisibleCloseButton;}
-
-
-  /**
-   * todo 배경 투명 설정?
-   *
-   * @param isTransparent
-   */
-  public void setTransparent(boolean isTransparent) {
-    this.isTransparent = isTransparent;
-  }
-
-  @NonNull
-  @Override
-  public Dialog onCreateDialog(Bundle savedInstanceState) {
-    // Use the Builder class for convenient dialog construction
-    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity(), R.style.DialogTheme);
-    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_alert, null);
-    setupView(view);
-    builder.setView(view);
-    builder.setCancelable(isCancelable);
-    Dialog dialog = builder.create();
-    dialog.setCancelable(isCancelable);
-    dialog.setCanceledOnTouchOutside(isCancelable);
-    if (isTransparent) {
-      dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
-    }
-    // Create the AlertDialog object and return it
-    return dialog;
-
-  }
+public class AlertDialog extends ConfirmBaseDialog<ICustomDialogListener<AlertDialog>> {
 
   //onStart() is where dialog.show() is actually called on
   //the underlying dialog, so we have to do it there or
@@ -112,17 +30,12 @@ public class AlertDialog extends TextDialog<ICustomDialogListener<AlertDialog>>
   //environment that skips onStart then the dialog will still be functioning
   //properly after a rotation.
   @Override
-  public void onResume() {
-    super.onResume();
-
+  protected void attachEvent() {
     final android.support.v7.app.AlertDialog d = (android.support.v7.app.AlertDialog) getDialog();
     if (d != null) {
-      textViewPositiveButton.setOnClickListener(new View.OnClickListener() {
-        @Override
-        public void onClick(View v) {
-          if (null != getCustomListener()) {
-            getCustomListener().onDialogResult(AlertDialog.this, new Event.Builder(Event.CONFIRM).build());
-          }
+      textViewPositiveButton.setOnClickListener(v -> {
+        if (null != getCustomListener()) {
+          getCustomListener().onDialogResult(AlertDialog.this, new Event.Builder(Event.CONFIRM).build());
         }
       });
 
@@ -136,30 +49,19 @@ public class AlertDialog extends TextDialog<ICustomDialogListener<AlertDialog>>
     }
   }
 
-  private void setupView(View view) {
-    textViewPositiveButton = view.findViewById(R.id.text_view_write_app_review);
-    TextView textViewTitle = view.findViewById(R.id.text_view_title);
-    TextView textViewContents = view.findViewById(R.id.text_view_dialog_message);
-    ImageView imageViewClose = view.findViewById(R.id.image_view_close);
+  @Override
+  protected void setupView(View view) {
+    super.setupView(view);
 
-    imageViewClose.setVisibility(isVisibleCloseButton ? View.VISIBLE : View.GONE);
-    textViewTitle.setVisibility(titleStringId == R.string.empty_string ? View.GONE : View.VISIBLE);
-    textViewPositiveButton.setText(positiveButtonLabel == R.string.empty_string ? R.string.confirm : positiveButtonLabel);
+    //
+    textViewNegativeButton.setVisibility(View.GONE);
 
-    if (titleStringId != R.string.empty_string) {
-      textViewTitle.setText(titleStringId);
-    }
+    ConstraintSet constraintSet = new ConstraintSet();
+    constraintSet.clone((ConstraintLayout) textViewPositiveButton.getParent());
 
-    textViewContents.setText(text);
+    constraintSet.connect(textViewPositiveButton.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START, ResourceUtil.dpToPx(10));
 
-    //닫기버튼 클릭
-    imageViewClose.setOnClickListener(view1 -> {
-      getCustomListener().onDialogCanceled(AlertDialog.this);
-    });
+    constraintSet.applyTo((ConstraintLayout) textViewPositiveButton.getParent());
   }
 
-  @Override
-  protected void onActivityCreatedInternal() {
-
-  }
 }

+ 141 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/ConfirmBaseDialog.java

@@ -0,0 +1,141 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.dialog;
+
+import android.app.Dialog;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.StringRes;
+import android.view.View;
+import android.view.Window;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import kr.co.zumo.app.R;
+
+/**
+ * ConfirmDialog
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018. 10. 11.]   [최초 작성]
+ * @since 2018. 10. 11.
+ */
+public abstract class ConfirmBaseDialog<L extends ICustomDialogCancelListener> extends TextDialog<L> {
+
+  protected boolean isCancelable = true;
+  @StringRes
+  protected int positiveButtonLabel = R.string.empty_string;
+  @StringRes
+  protected int negativeButtonLabel = R.string.empty_string;
+  @StringRes
+  protected int titleStringId = R.string.empty_string;
+
+  protected boolean isVisibleCloseButton;
+
+  protected TextView textViewPositiveButton;
+  protected TextView textViewNegativeButton;
+  protected ImageView imageViewClose;
+
+  /**
+   * back key 가능 여부 설정
+   *
+   * @param cancelable
+   */
+  @Override
+  public void setCancelable(boolean cancelable) {
+    super.setCancelable(cancelable);
+    isCancelable = cancelable;
+  }
+
+  /**
+   * 표시할 positiveButtonLabel 지정
+   *
+   * @param stringId
+   */
+  public void setPositiveButtonLabelId(@StringRes int stringId) {
+    this.positiveButtonLabel = stringId;
+  }
+
+  /**
+   * 표시할 negativeButtonLabel 지정
+   *
+   * @param stringId
+   */
+  public void setNegativeButtonLabelId(@StringRes int stringId) {
+    this.negativeButtonLabel = stringId;
+  }
+
+
+  /**
+   * 표시할 title 지정
+   *
+   * @param stringId
+   */
+  public void setTitleId(@StringRes int stringId) {this.titleStringId = stringId;}
+
+  /**
+   * 닫기 버튼 표시
+   *
+   * @param isVisibleCloseButton
+   */
+  public void setVisibleCloseButton(boolean isVisibleCloseButton) {this.isVisibleCloseButton = isVisibleCloseButton;}
+
+  @NonNull
+  @Override
+  public Dialog onCreateDialog(Bundle savedInstanceState) {
+
+    // Use the Builder class for convenient dialog construction
+    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity(), R.style.DialogTheme);
+    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_confirm, null);
+    setupView(view);
+
+    builder.setView(view);
+
+    Dialog dialog = builder.create();
+    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
+
+    builder.setCancelable(isCancelable);
+    dialog.setCancelable(isCancelable);
+    dialog.setCanceledOnTouchOutside(isCancelable);
+
+    return dialog;
+
+  }
+
+  @Override
+  public void onResume() {
+    super.onResume();
+
+    attachEvent();
+  }
+
+  protected abstract void attachEvent();
+
+  protected void setupView(View view) {
+    TextView textViewTitle = view.findViewById(R.id.text_view_title);
+    TextView textViewContents = view.findViewById(R.id.text_view_dialog_message);
+    textViewNegativeButton = view.findViewById(R.id.text_view_negative);
+    textViewPositiveButton = view.findViewById(R.id.text_view_positive);
+    imageViewClose = view.findViewById(R.id.image_view_close);
+
+    imageViewClose.setVisibility(isVisibleCloseButton ? View.VISIBLE : View.GONE);
+    textViewTitle.setVisibility(titleStringId == R.string.empty_string ? View.GONE : View.VISIBLE);
+
+    textViewNegativeButton.setText(negativeButtonLabel == R.string.empty_string ? R.string.cancel : negativeButtonLabel);
+    textViewPositiveButton.setText(positiveButtonLabel == R.string.empty_string ? R.string.confirm : positiveButtonLabel);
+
+    if (titleStringId != R.string.empty_string) {
+      textViewTitle.setText(titleStringId);
+    }
+    textViewContents.setText(text);
+
+  }
+
+  @Override
+  protected void onActivityCreatedInternal() { }
+}

+ 22 - 126
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/ConfirmDialog.java

@@ -3,16 +3,6 @@
  */
 package kr.co.zumo.app.lifeplus.view.dialog;
 
-import android.app.Dialog;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.StringRes;
-import android.view.View;
-import android.view.Window;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.view.Event;
 
 /**
@@ -25,125 +15,31 @@ import kr.co.zumo.app.lifeplus.view.Event;
  * @history 민효동   [2018. 10. 11.]   [최초 작성]
  * @since 2018. 10. 11.
  */
-public class ConfirmDialog extends TextDialog<ICustomConfirmListener<ConfirmDialog>> {
-
-  protected boolean isCancelable = true;
-  @StringRes
-  protected int positiveButtonLabel = R.string.empty_string;
-  @StringRes
-  protected int negativeButtonLabel = R.string.empty_string;
-  @StringRes
-  protected int titleStringId = R.string.empty_string;
-
-  private boolean isVisibleCloseButton;
-
-  /**
-   * back key 가능 여부 설정
-   *
-   * @param cancelable
-   */
-  @Override
-  public void setCancelable(boolean cancelable) {
-    super.setCancelable(cancelable);
-    isCancelable = cancelable;
-  }
-
-  /**
-   * 표시할 positiveButtonLabel 지정
-   *
-   * @param stringId
-   */
-  public void setPositiveButtonLabelId(@StringRes int stringId) {
-    this.positiveButtonLabel = stringId;
-  }
+public class ConfirmDialog extends ConfirmBaseDialog<ICustomConfirmListener<ConfirmDialog>> {
 
-  /**
-   * 표시할 negativeButtonLabel 지정
-   *
-   * @param stringId
-   */
-  public void setNegativeButtonLabelId(@StringRes int stringId) {
-    this.negativeButtonLabel = stringId;
-  }
-
-
-  /**
-   * 표시할 title 지정
-   *
-   * @param stringId
-   */
-  public void setTitleId(@StringRes int stringId) {this.titleStringId = stringId;}
-
-  /**
-   * 닫기 버튼 표시
-   *
-   * @param isVisibleCloseButton
-   */
-  public void setVisibleCloseButton(boolean isVisibleCloseButton) {this.isVisibleCloseButton = isVisibleCloseButton;}
-
-  @NonNull
   @Override
-  public Dialog onCreateDialog(Bundle savedInstanceState) {
-
-    // Use the Builder class for convenient dialog construction
-    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity(), R.style.DialogTheme);
-    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_confirm, null);
-    setupView(view);
-
-    builder.setView(view);
-
-    Dialog dialog = builder.create();
-    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
-    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
-
-    builder.setCancelable(isCancelable);
-    dialog.setCancelable(isCancelable);
-    dialog.setCanceledOnTouchOutside(isCancelable);
-
-    return dialog;
-
-  }
-
-  private void setupView(View view) {
-    TextView textViewTitle = view.findViewById(R.id.text_view_title);
-    TextView textViewContents = view.findViewById(R.id.text_view_dialog_message);
-    TextView textViewNegativeButtonText = view.findViewById(R.id.text_view_next_time);
-    TextView textViewPositiveButtonText = view.findViewById(R.id.text_view_write_app_review);
-    ImageView imageViewClose = view.findViewById(R.id.image_view_close);
-
-    imageViewClose.setVisibility(isVisibleCloseButton ? View.VISIBLE : View.GONE);
-    textViewTitle.setVisibility(titleStringId == R.string.empty_string ? View.GONE : View.VISIBLE);
-
-    textViewPositiveButtonText.setText(positiveButtonLabel == R.string.empty_string ? R.string.confirm : positiveButtonLabel);
-    textViewNegativeButtonText.setText(negativeButtonLabel == R.string.empty_string ? R.string.cancel : negativeButtonLabel);
-
-    if (titleStringId != R.string.empty_string) {
-      textViewTitle.setText(titleStringId);
+  protected void attachEvent() {
+    final android.support.v7.app.AlertDialog d = (android.support.v7.app.AlertDialog) getDialog();
+    if (d != null) {
+
+      //왼쪽 클릭
+      textViewNegativeButton.setOnClickListener(v -> {
+        if (null != getCustomListener()) {
+          getCustomListener().onNegativeResult(ConfirmDialog.this, new Event.Builder(Event.CANCEL).build());
+        }
+
+      });
+
+      //오른쪽
+      textViewPositiveButton.setOnClickListener(v -> {
+        getCustomListener().onPositiveResult(ConfirmDialog.this, new Event.Builder(Event.CONFIRM).build());
+      });
+
+      //닫기버튼 클릭
+      imageViewClose.setOnClickListener(v -> {
+        getCustomListener().onDialogCanceled(ConfirmDialog.this);
+      });
     }
-    textViewContents.setText(text);
-
-    //왼쪽 클릭
-    textViewNegativeButtonText.setOnClickListener(view1 -> {
-      if (null != getCustomListener()) {
-        getCustomListener().onNegativeResult(ConfirmDialog.this, new Event.Builder(Event.CANCEL).build());
-      }
-
-    });
-
-    //오른쪽
-    textViewPositiveButtonText.setOnClickListener(view1 -> {
-      getCustomListener().onPositiveResult(ConfirmDialog.this, new Event.Builder(Event.CONFIRM).build());
-    });
-
-
-    //닫기버튼 클릭
-    imageViewClose.setOnClickListener(view1 -> {
-      getCustomListener().onDialogCanceled(ConfirmDialog.this);
-    });
   }
 
-  @Override
-  protected void onActivityCreatedInternal() {
-
-  }
 }

+ 0 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/contents/ContentsPresenter.java

@@ -725,7 +725,6 @@ public class ContentsPresenter extends ContentsBasePresenter<ContentsModel, ICon
         }
       })
       .attribute(dialog -> {
-        dialog.setTransparent(true);
         dialog.setCancelable(false);
         dialog.setText(R.string.access_right_message);
       })

+ 0 - 34
app/src/main/res/layout/alert_dialog.xml

@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout
-  xmlns:android="http://schemas.android.com/apk/res/android"
-  xmlns:app="http://schemas.android.com/apk/res-auto"
-  xmlns:tools="http://schemas.android.com/tools"
-  android:layout_width="match_parent"
-  android:layout_height="match_parent"
-  android:background="#BBFFFFFF"
-  android:gravity="center"
-  android:orientation="vertical">
-
-  <TextView
-    android:id="@+id/text_alert_message"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:layout_margin="20dp"
-    android:background="@drawable/button_background"
-    android:padding="20dp"
-    android:textColor="@color/C000000"
-    tools:text="@string/tutorial_title_last"/>
-
-  <Space
-    android:layout_width="match_parent"
-    android:layout_height="20dp"
-    />
-
-  <Button
-    android:id="@+id/button_confirm"
-    style="@style/SignUpButton"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:text="@string/confirm"
-    />
-</LinearLayout>

+ 0 - 107
app/src/main/res/layout/dialog_alert.xml

@@ -1,107 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout
-  xmlns:android="http://schemas.android.com/apk/res/android"
-  xmlns:app="http://schemas.android.com/apk/res-auto"
-  xmlns:tools="http://schemas.android.com/tools"
-  android:layout_width="match_parent"
-  android:layout_height="wrap_content"
-  tools:background="@color/C888888">
-
-  <android.support.constraint.ConstraintLayout
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:background="@drawable/dialog_inset"
-    app:layout_constraintBottom_toBottomOf="parent"
-    app:layout_constraintEnd_toEndOf="parent"
-    app:layout_constraintStart_toStartOf="parent"
-    app:layout_constraintTop_toTopOf="parent">
-
-    <TextView
-      android:id="@+id/text_view_title"
-      android:layout_width="0dp"
-      android:layout_height="wrap_content"
-      android:layout_marginTop="35dp"
-      android:layout_marginEnd="10dp"
-      android:lineSpacingExtra="7sp"
-      android:textColor="@color/C000000"
-      android:textSize="18sp"
-      android:textStyle="bold"
-      app:layout_constrainedWidth="true"
-      app:layout_constraintBottom_toTopOf="@+id/text_view_dialog_message"
-      app:layout_constraintHorizontal_chainStyle="packed"
-      app:layout_constraintStart_toStartOf="@+id/text_view_dialog_message"
-      app:layout_constraintTop_toTopOf="parent"
-      tools:text="title"
-      tools:visibility="visible"/>
-
-    <ImageView
-      android:id="@+id/image_view_close"
-      android:layout_width="wrap_content"
-      android:layout_height="wrap_content"
-      android:layout_marginTop="22dp"
-      android:layout_marginEnd="22dp"
-      android:background="?android:attr/selectableItemBackground"
-      android:padding="10dp"
-      android:visibility="gone"
-      app:layout_constraintEnd_toEndOf="parent"
-      app:layout_constraintTop_toTopOf="parent"
-      app:srcCompat="@drawable/icon_h_close"
-      tools:visibility="visible"/>
-
-
-    <TextView 
-      android:id="@+id/text_view_dialog_message"
-      android:layout_width="0dp"
-      android:layout_height="wrap_content"
-      android:layout_marginStart="25dp"
-      android:layout_marginTop="20dp"
-      android:layout_marginEnd="25dp"
-      android:layout_marginBottom="20dp"
-      android:lineSpacingExtra="6sp"
-      android:textColor="@color/C000000"
-      app:layout_constrainedWidth="true"
-      app:layout_constraintBottom_toTopOf="@+id/button_layout"
-      app:layout_constraintEnd_toEndOf="parent"
-      app:layout_constraintStart_toStartOf="parent"
-      app:layout_constraintTop_toBottomOf="@+id/text_view_title"
-      app:layout_goneMarginTop="35dp"
-      tools:text="@string/network_disconnected_message_detail_dialog"
-      />
-
-    <android.support.constraint.ConstraintLayout
-      android:id="@+id/button_layout"
-      android:layout_width="match_parent"
-      android:layout_height="wrap_content"
-      android:layout_marginBottom="9dp"
-      app:layout_constraintBottom_toBottomOf="parent"
-      app:layout_constraintEnd_toEndOf="parent"
-      app:layout_constraintStart_toStartOf="parent"
-      app:layout_constraintTop_toBottomOf="@+id/text_view_dialog_message">
-
-
-      <TextView
-        android:id="@+id/text_view_write_app_review"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="24dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="24dp"
-        android:layout_marginBottom="8dp"
-        android:background="?android:attr/selectableItemBackground"
-        android:gravity="center"
-        android:includeFontPadding="false"
-        android:minWidth="100dp"
-        android:padding="7dp"
-        android:textColor="@color/C000000"
-        android:textSize="14sp"
-        android:textStyle="bold"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
-        tools:text="abcdabcdabcdabcdabcd"
-        />
-
-    </android.support.constraint.ConstraintLayout>
-  </android.support.constraint.ConstraintLayout>
-</android.support.constraint.ConstraintLayout>

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

@@ -77,7 +77,7 @@
       app:layout_constraintTop_toBottomOf="@+id/text_view_dialog_message">
 
       <TextView
-        android:id="@+id/text_view_next_time"
+        android:id="@+id/text_view_negative"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="10dp"
@@ -112,7 +112,7 @@
         app:layout_constraintStart_toStartOf="parent"/>
 
       <TextView
-        android:id="@+id/text_view_write_app_review"
+        android:id="@+id/text_view_positive"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="10dp"