Jelajahi Sumber

Merge branch 'develop' of https://github.com/swict/LifePlusAndroid into develop

# Conflicts:
#	app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/my/bucketlist/BucketListWithTagDetailPresenter.java
Hasemi 7 tahun lalu
induk
melakukan
31334c2e20

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/bean/api/BucketBean.java

@@ -36,7 +36,7 @@ public class BucketBean extends JsonBeanBase {
   }
 
   public String getTitle() {
-    return title;
+    return title.replace("\r\n", "\n");
   }
 
   public void setTitle(String title) {

+ 3 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/my/bucketlist/BucketListDefaultDetailPresenter.java

@@ -118,6 +118,9 @@ public class BucketListDefaultDetailPresenter extends Presenter<BucketListDefaul
         // 삭제 완료
         showDeleteResultDialog();
         break;
+      case Event.ERROR:
+        showErrorDialog(event.getString());
+        break;
       default:
         break;
     }

+ 10 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/my/bucketlist/BucketListWithTagDetailFragment.java

@@ -77,7 +77,7 @@ public class BucketListWithTagDetailFragment extends FragmentBase<BucketListWith
 
     setTagTitle(0);
 
-    imageBucket.setOnClickListener(view -> presenter.onEvent(new Event.Builder(Event.UPDATE).build()));
+    textTagTitle.setOnClickListener(view -> presenter.onEvent(new Event.Builder(Event.UPDATE).build()));
 
     if (appBarLayout.getLayoutParams() != null) {
       CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
@@ -106,7 +106,7 @@ public class BucketListWithTagDetailFragment extends FragmentBase<BucketListWith
 
   @Override
   protected BucketListWithTagDetailPresenter definePresenter() {
-    return new BucketListWithTagDetailPresenter(getModel(BucketListDetailModel.class), this);
+    return new BucketListWithTagDetailPresenter(getModel(BucketListWithTagDetailModel.class), this);
   }
 
   @Override
@@ -195,6 +195,14 @@ public class BucketListWithTagDetailFragment extends FragmentBase<BucketListWith
   @Override
   public void setCompleted(boolean isCompleted) {
     imageChecker.setVisibility(isCompleted ? View.VISIBLE : View.GONE);
+//    Drawable checkImageResource = getActivity().getResources().getDrawable(R.drawable.icon_bucket_complete_white);
+//    if (isCompleted) {
+//      textTagTitle.setCompoundDrawablesWithIntrinsicBounds(checkImageResource, null, null, null);
+//    }
+//    else {
+//      textTagTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
+//    }
+    getHelper(ActionBarHelper.class).setCompleted(isCompleted);
   }
 
   @Override

+ 70 - 10
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/my/bucketlist/BucketListDetailModel.java

@@ -7,15 +7,20 @@ import java.util.ArrayList;
 import java.util.List;
 
 import io.reactivex.disposables.Disposable;
+import kr.co.zumo.app.lifeplus.bean.api.BucketCompleteRequestBean;
 import kr.co.zumo.app.lifeplus.bean.api.BucketListTagResultBean;
-import kr.co.zumo.app.lifeplus.bean.api.BucketMyBean;
+import kr.co.zumo.app.lifeplus.bean.api.BucketNumberRequestBean;
+import kr.co.zumo.app.lifeplus.bean.api.BucketWithTagBean;
+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.LifeplusData;
 import kr.co.zumo.app.lifeplus.bean.api.TagBean;
 import kr.co.zumo.app.lifeplus.bean.api.TagRelatedContentsRequestBean;
 import kr.co.zumo.app.lifeplus.bean.api.TagRelatedContentsResultBean;
 import kr.co.zumo.app.lifeplus.bean.api.TagTitleBean;
 import kr.co.zumo.app.lifeplus.bean.api.TitleRequestBean;
 import kr.co.zumo.app.lifeplus.model.Model;
+import kr.co.zumo.app.lifeplus.model.module.APIBucketDeleteModule;
 import kr.co.zumo.app.lifeplus.model.module.APIBucketTagListModule;
 import kr.co.zumo.app.lifeplus.model.module.APIBucketTagRelatedListModule;
 import kr.co.zumo.app.lifeplus.model.module.APIError;
@@ -23,7 +28,7 @@ import kr.co.zumo.app.lifeplus.model.module.APIModuleSimpleListener;
 import kr.co.zumo.app.lifeplus.view.Event;
 
 /**
- * BucketListDetailModel
+ * BucketListWithTagDetailModel
  * <pre>
  * </pre>
  *
@@ -32,9 +37,11 @@ import kr.co.zumo.app.lifeplus.view.Event;
  * @history 민효동   [2018. 11. 13.]   [최초 작성]
  * @since 2018. 11. 13.
  */
-public class BucketListDetailModel extends Model {
-  private BucketMyBean bucketMyBean;
+public class BucketListWithTagDetailModel extends Model {
+  private BucketWithTagBean bucketWithTagBean;
 
+  private Disposable disposableAchieve;
+  private Disposable disposableDelete;
   private Disposable disposableTag;
   private List<TagBean> tags;
 
@@ -43,7 +50,7 @@ public class BucketListDetailModel extends Model {
 
   private List<Integer> tagIndices;
 
-  public BucketListDetailModel() {
+  public BucketListWithTagDetailModel() {
   }
 
   @Override
@@ -79,16 +86,16 @@ public class BucketListDetailModel extends Model {
 
   }
 
-  public BucketMyBean getBucketMyBean() {
-    return bucketMyBean;
+  public BucketWithTagBean getBucketWithTagBean() {
+    return bucketWithTagBean;
   }
 
-  public void setBucketMyBean(BucketMyBean bucketMyBean) {
-    this.bucketMyBean = bucketMyBean;
+  public void setBucketWithTagBean(BucketWithTagBean bucketMyBean) {
+    this.bucketWithTagBean = bucketMyBean;
   }
 
   public void loadTag() {
-    disposableTag = new APIBucketTagListModule().call(new TitleRequestBean(bucketMyBean.getTitle()), new APIModuleSimpleListener<BucketListTagResultBean>(waiterCaller) {
+    disposableTag = new APIBucketTagListModule().call(new TitleRequestBean(bucketWithTagBean.getTitle()), new APIModuleSimpleListener<BucketListTagResultBean>(waiterCaller) {
       @Override
       public void onApiSuccess(BucketListTagResultBean resultBean) {
         tags = resultBean.getData();
@@ -116,6 +123,15 @@ public class BucketListDetailModel extends Model {
       disposableRelatedContents.dispose();
       disposableRelatedContents = null;
     }
+
+    if (null != disposableAchieve) {
+      disposableAchieve.dispose();
+      disposableAchieve = null;
+    }
+    if (null != disposableDelete) {
+      disposableDelete.dispose();
+      disposableDelete = null;
+    }
   }
 
   public void addSearchTag(int index) {
@@ -179,4 +195,48 @@ public class BucketListDetailModel extends Model {
   public List<LifeplusContentsBean> getContentsBeans() {
     return contentsBeans;
   }
+
+
+  /**
+   * 버킷 달성
+   */
+  public void completeBucket() {
+    // 달성 미달성 데이터 토글
+    boolean bool = bucketWithTagBean.isCompleted();
+    String yn = LifeplusData.valueOf(!bool);
+    disposableAchieve = BucketListModelHelper.getInstance().completeBucket(new BucketCompleteRequestBean(getUserName(), bucketWithTagBean.getBucketNumber(), yn), new APIModuleSimpleListener<LifeplusAPIBean>(waiterCaller) {
+      @Override
+      public void onApiSuccess(LifeplusAPIBean resultBean) {
+
+        bucketWithTagBean.setCompleted(yn);
+
+        onResult(new Event.Builder(Event.COMPLETED).build());
+      }
+
+      @Override
+      public void onApiError(String errorMessage, APIError error) {
+        onResult(new Event.Builder(Event.ERROR).string(errorMessage).build());
+      }
+    });
+  }
+
+  /**
+   * 버킷 삭제
+   */
+  public void deleteBucket() {
+    disposableDelete = new APIBucketDeleteModule().call(new BucketNumberRequestBean(getUserName(), bucketWithTagBean.getBucketNumber()), new APIModuleSimpleListener<LifeplusAPIBean>(waiterCaller) {
+      @Override
+      public void onApiSuccess(LifeplusAPIBean resultBean) {
+        BucketListModelHelper.getInstance().removeBucketByNumber(bucketWithTagBean.getBucketNumber());
+
+        onResult(new Event.Builder(Event.DELETE).build());
+      }
+
+      @Override
+      public void onApiError(String errorMessage, APIError error) {
+        onResult(new Event.Builder(Event.ERROR).string(errorMessage).build());
+      }
+    });
+  }
+
 }

+ 113 - 11
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/my/bucketlist/BucketListWithTagDetailPresenter.java

@@ -2,15 +2,23 @@ package kr.co.zumo.app.lifeplus.view.screen.my.bucketlist;
 
 import android.util.Log;
 
+import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.bean.ContentsDeliveryBean;
-import kr.co.zumo.app.lifeplus.bean.api.BucketMyBean;
 import kr.co.zumo.app.lifeplus.bean.api.BucketWithTagBean;
 import kr.co.zumo.app.lifeplus.bean.api.LifeplusContentsBean;
-import kr.co.zumo.app.lifeplus.bean.api.LifeplusData;
+import kr.co.zumo.app.lifeplus.helper.NavigationBar;
 import kr.co.zumo.app.lifeplus.model.SuperModel;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
+import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 import kr.co.zumo.app.lifeplus.view.DoubleChecker;
 import kr.co.zumo.app.lifeplus.view.Event;
+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.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.ICustomConfirmListener;
+import kr.co.zumo.app.lifeplus.view.dialog.ICustomDialogListener;
 import kr.co.zumo.app.lifeplus.view.presenter.Presenter;
 
 /**
@@ -23,19 +31,19 @@ import kr.co.zumo.app.lifeplus.view.presenter.Presenter;
  * @history 하세미   [2018-10-19]   [최초 작성]
  * @since 2018-10-19
  */
-public class BucketListWithTagDetailPresenter extends Presenter<BucketListDetailModel, IBucketListWithTagDetailView> {
+public class BucketListWithTagDetailPresenter extends Presenter<BucketListWithTagDetailModel, IBucketListWithTagDetailView> {
 
   private DoubleChecker doubleCheckerTag;
   private DoubleChecker doubleCheckerContents;
 
-  public BucketListWithTagDetailPresenter(BucketListDetailModel model, IBucketListWithTagDetailView view) {
+  public BucketListWithTagDetailPresenter(BucketListWithTagDetailModel model, IBucketListWithTagDetailView view) {
     super(model, view);
 
     // 나의 버킷 정보 가져옴
     BucketWithTagBean bucketMyBean = model.getDeliveryPackaging(BucketWithTagBean.class);
     if (null != bucketMyBean) {
-      Log.w("APP# BucketListDetailModel | BucketListDetailModel", "|" + bucketMyBean.toPrettyJson());
-      model.setBucketMyBean(bucketMyBean);
+      Log.w("APP# BucketListWithTagDetailModel | BucketListWithTagDetailModel", "|" + bucketMyBean.toPrettyJson());
+      model.setBucketWithTagBean(bucketMyBean);
       model.clearDeliveryPackaging();
     }
 
@@ -72,7 +80,7 @@ public class BucketListWithTagDetailPresenter extends Presenter<BucketListDetail
 
   @Override
   protected void startInternalOnce() {
-    if (null != this.model.getBucketMyBean()) {
+    if (null != this.model.getBucketWithTagBean()) {
       this.model.loadTag();
       if (false == SuperModel.getInstance().getPreferences().isTutorialBucketListTagDone()) {
         view.showTutorialBucketTag();
@@ -109,8 +117,7 @@ public class BucketListWithTagDetailPresenter extends Presenter<BucketListDetail
     switch (event.getEventId()) {
       case Event.UPDATE:
         // 상단 버킷 클릭 시
-        model.setDeliveryPackaging(model.getBucketMyBean());
-        go(ScreenID.BUCKET_MY_EDIT);
+        edit();
         break;
       case Event.TAG:
         // 태그 하나 누름
@@ -137,6 +144,11 @@ public class BucketListWithTagDetailPresenter extends Presenter<BucketListDetail
     }
   }
 
+  private void edit() {
+    model.setDeliveryPackaging(model.getBucketWithTagBean());
+    go(ScreenID.BUCKET_MY_EDIT);
+  }
+
   @Override
   public void onResult(Event event) {
     switch (event.getEventId()) {
@@ -162,6 +174,18 @@ public class BucketListWithTagDetailPresenter extends Presenter<BucketListDetail
           doubleCheckerContents.checkSecond();
         }
         break;
+
+      case Event.COMPLETED:
+        // 달성 갱신 완료;
+        view.setCompleted(model.getBucketWithTagBean().isCompleted());
+        break;
+      case Event.DELETE:
+        // 삭제 완료
+        showDeleteResultDialog();
+        break;
+      case Event.ERROR:
+        showErrorDialog(event.getString());
+        break;
       default:
         break;
     }
@@ -172,11 +196,89 @@ public class BucketListWithTagDetailPresenter extends Presenter<BucketListDetail
     doubleCheckerTag.checkFirst();
     doubleCheckerContents.checkFirst();
 
-    BucketMyBean bean = model.getBucketMyBean();
+    BucketWithTagBean bean = model.getBucketWithTagBean();
     if (null != bean) {
-      view.setCompleted(LifeplusData.isTrue(bean.getCompleted()));
+      view.setCompleted(bean.isCompleted());
       view.setBucketTitle(bean.getTitle());
       view.setBackground(bean.getImageUrl());
     }
   }
+
+  /**
+   * 확인 클릭
+   *
+   * @param navigationBar
+   */
+  public void onNavigationClickConfirm(NavigationBar navigationBar) {
+    model.completeBucket();
+  }
+
+  /**
+   * 수정 클릭
+   *
+   * @param navigationBar
+   */
+  public void onNavigationClickEdit(NavigationBar navigationBar) {
+    edit();
+  }
+
+  /**
+   * 휴지통 클릭
+   *
+   * @param navigationBar
+   */
+  public void onNavigationClickTrash(NavigationBar navigationBar) {
+    // 버킷 리스트 삭제
+    new DialogBuilder<ConfirmDialog, ICustomConfirmListener>(getFragmentManager(), DialogID.CONFIRM)
+      .listener(new ICustomConfirmListener<ConfirmDialog>() {
+        @Override
+        public void onPositiveResult(ConfirmDialog dialog, Event event) {
+          dialog.dispose();
+          model.deleteBucket();
+        }
+
+        @Override
+        public void onNegativeResult(ConfirmDialog dialog, Event event) {
+        }
+
+        @Override
+        public void onDialogCanceled(ConfirmDialog dialog) {
+          dialog.dispose();
+        }
+      })
+      .attribute(dialog -> {
+        dialog.setText(ResourceUtil.getString(R.string.best_bucket_delete_guide));
+      })
+      .show();
+  }
+
+  protected void showDeleteResultDialog() {
+    new DialogBuilder<AlertDialog, ICustomDialogListener>(getFragmentManager(), DialogID.ALERT)
+      .listener(new ICustomDialogListener<AlertDialog>() {
+        @Override
+        public void onDialogResult(AlertDialog dialog, Event event) {
+          if (event.getEventId() == Event.CONFIRM) {
+            dialog.dispose();
+            if (BucketListModelHelper.getInstance().getCountOfBucket() == 0) {
+              jump(ScreenID.MY_MAIN);
+            }
+            else {
+              back(ScreenID.MY_BUCKET_LIST);
+            }
+          }
+        }
+
+        @Override
+        public void onDialogCanceled(AlertDialog dialog) {
+          dialog.dispose();
+        }
+      })
+      .attribute(new IAttribute<AlertDialog>() {
+        @Override
+        public void onAttribute(AlertDialog dialog) {
+          dialog.setText(R.string.delete_message);
+        }
+      })
+      .show();
+  }
 }