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

[공통][New] 좋아요/북마크 체크박스 리팩토링

hyodong.min 7 éve
szülő
commit
2e9b817eec

+ 69 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/AbstractCheckbox.java

@@ -0,0 +1,69 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.custom;
+
+import android.content.Context;
+import android.support.constraint.ConstraintLayout;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.Checkable;
+import android.widget.ImageView;
+
+/**
+ * LikeCheckbox
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2019-01-15]   [최초 작성]
+ * @since 2019-01-15
+ */
+public abstract class AbstractCheckbox extends ConstraintLayout implements Checkable {
+
+  protected LayoutInflater inflater;
+  protected ImageView checkImage;
+  protected boolean isChecked;
+
+  public AbstractCheckbox(Context context) {
+    this(context, null);
+  }
+
+  public AbstractCheckbox(Context context, AttributeSet attrs) {
+    super(context, attrs);
+    init(context);
+    attachEvent();
+  }
+
+  protected abstract void init(Context context);
+
+  protected final void attachEvent() {
+    this.setOnTouchListener(new OnTouchListener() {
+      @Override
+      public boolean onTouch(View v, MotionEvent event) {
+        if (event.getAction() == MotionEvent.ACTION_DOWN) {
+          setChecked(!isChecked, true);
+        }
+        return false;
+      }
+    });
+  }
+
+  @Override
+  public final void setChecked(boolean isChecked) {
+    setChecked(isChecked, false);
+  }
+
+  protected abstract void setChecked(boolean isChecked, boolean isAnim);
+
+  @Override
+  public final boolean isChecked() {
+    return isChecked;
+  }
+
+  @Override
+  public final void toggle() { }
+}

+ 3 - 35
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/BookmarkCheckbox.java

@@ -4,13 +4,9 @@
 package kr.co.zumo.app.lifeplus.view.custom;
 
 import android.content.Context;
-import android.support.constraint.ConstraintLayout;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
-import android.view.MotionEvent;
 import android.view.View;
-import android.widget.Checkable;
-import android.widget.ImageView;
 
 import kr.co.zumo.app.R;
 
@@ -24,44 +20,25 @@ import kr.co.zumo.app.R;
  * @history 하세미   [2019-01-15]   [최초 작성]
  * @since 2019-01-15
  */
-public class BookmarkCheckbox extends ConstraintLayout implements Checkable {
-
-  private LayoutInflater inflater;
-  private ImageView checkImage;
-  private boolean isChecked;
+public class BookmarkCheckbox extends AbstractCheckbox {
 
   public BookmarkCheckbox(Context context) {
     super(context);
-    init(context);
   }
 
   public BookmarkCheckbox(Context context, AttributeSet attrs) {
     super(context, attrs);
-    init(context);
   }
 
-  private void init(Context context) {
+  @Override
+  protected void init(Context context) {
     if (null != context) {
       inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       View view = inflater.inflate(R.layout.checkbox_bookmark, this);
       checkImage = view.findViewById(R.id.icon_bookmark);
-      checkImage.setOnTouchListener(new View.OnTouchListener() {
-        @Override
-        public boolean onTouch(View v, MotionEvent event) {
-          if (event.getAction() == MotionEvent.ACTION_DOWN) {
-            setChecked(!isChecked, true);
-          }
-          return false;
-        }
-      });
     }
   }
 
-  @Override
-  public void setChecked(boolean isChecked) {
-    setChecked(isChecked, false);
-  }
-
   public void setChecked(boolean isChecked, boolean isAnim) {
     this.isChecked = isChecked;
     if (isChecked) {
@@ -79,13 +56,4 @@ public class BookmarkCheckbox extends ConstraintLayout implements Checkable {
 
   }
 
-  @Override
-  public boolean isChecked() {
-    return isChecked;
-  }
-
-  @Override
-  public void toggle() {
-    //nothing
-  }
 }

+ 4 - 37
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/LikeCheckbox.java

@@ -4,13 +4,9 @@
 package kr.co.zumo.app.lifeplus.view.custom;
 
 import android.content.Context;
-import android.support.constraint.ConstraintLayout;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
-import android.view.MotionEvent;
 import android.view.View;
-import android.widget.Checkable;
-import android.widget.ImageView;
 
 import kr.co.zumo.app.R;
 
@@ -24,45 +20,27 @@ import kr.co.zumo.app.R;
  * @history 하세미   [2019-01-15]   [최초 작성]
  * @since 2019-01-15
  */
-public class LikeCheckbox extends ConstraintLayout implements Checkable {
-
-  private LayoutInflater inflater;
-  private ImageView checkImage;
-  private boolean isChecked;
+public class LikeCheckbox extends AbstractCheckbox {
 
   public LikeCheckbox(Context context) {
     super(context);
-    init(context);
   }
 
   public LikeCheckbox(Context context, AttributeSet attrs) {
     super(context, attrs);
-    init(context);
   }
 
-  private void init(Context context) {
+  @Override
+  protected void init(Context context) {
     if (null != context) {
       inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       View view = inflater.inflate(R.layout.checkbox_like, this);
       checkImage = view.findViewById(R.id.icon_like);
-      checkImage.setOnTouchListener(new View.OnTouchListener() {
-        @Override
-        public boolean onTouch(View v, MotionEvent event) {
-          if (event.getAction() == MotionEvent.ACTION_DOWN) {
-            setChecked(!isChecked, true);
-          }
-          return false;
-        }
-      });
     }
   }
 
   @Override
-  public void setChecked(boolean isChecked) {
-    setChecked(isChecked, false);
-  }
-
-  private void setChecked(boolean isChecked, boolean isAnim) {
+  protected void setChecked(boolean isChecked, boolean isAnim) {
     this.isChecked = isChecked;
 
     if (isChecked) {
@@ -79,15 +57,4 @@ public class LikeCheckbox extends ConstraintLayout implements Checkable {
     }
 
   }
-
-
-  @Override
-  public boolean isChecked() {
-    return isChecked;
-  }
-
-  @Override
-  public void toggle() {
-
-  }
 }