Просмотр исходного кода

[공통][New] DeliveryResultHelper 추가
- 이전(상위) 액티비티에서 결과를 반환하는 구조

hyodong.min 7 лет назад
Родитель
Сommit
a432a45023

+ 10 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/activity/ActivityBase.java

@@ -20,11 +20,13 @@ import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.application.App;
 import kr.co.zumo.app.lifeplus.helper.ActionBarHelper;
 import kr.co.zumo.app.lifeplus.helper.ActionButtonHelper;
+import kr.co.zumo.app.lifeplus.helper.DeliveryResultHelper;
 import kr.co.zumo.app.lifeplus.helper.FacebookHelper;
 import kr.co.zumo.app.lifeplus.helper.Helper;
 import kr.co.zumo.app.lifeplus.helper.IHelperProvider;
 import kr.co.zumo.app.lifeplus.helper.ScreenChangerHelper;
 import kr.co.zumo.app.lifeplus.model.SuperModel;
+import kr.co.zumo.app.lifeplus.supervisor.ActivityDeliveryResultHelper;
 import kr.co.zumo.app.lifeplus.supervisor.FragmentSkipBackChanger;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenChanger;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
@@ -164,6 +166,10 @@ public abstract class ActivityBase extends AppCompatActivity implements IHelperP
 
   @Override
   protected final void onRestart() {
+
+    // 이전(상위) 액티비티로부터 전달된 결과를 저장
+    ActivityDeliveryResultHelper.getInstance().shipTo(getHelper(DeliveryResultHelper.class));
+
     Log.w("APP# ActivityBase | onRestart", "| >>>> " + this.getClass().getSimpleName() + " HC: " + this.hashCode());
     super.onRestart();
   }
@@ -182,6 +188,10 @@ public abstract class ActivityBase extends AppCompatActivity implements IHelperP
 
   @Override
   protected final void onPause() {
+
+    // 결과를 이전(하위) 액티비티로 전달
+    getHelper(DeliveryResultHelper.class).shipTo(ActivityDeliveryResultHelper.getInstance());
+
     Log.w("APP# ActivityBase | onPause", "| <<<<<<-- " + this.getClass().getSimpleName() + " HC: " + this.hashCode());
     super.onPause();
   }

+ 18 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/helper/DeliveryResultHelper.java

@@ -0,0 +1,18 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.helper;
+
+/**
+ * DeliveryResultHelper
+ * - 스크린 간 데이터 공유를 위해서 Activity 에 저장되어 있는 helper
+ * - 이전 스크린으로 데이터를 전달할 때 사용
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 1. 16.]   [최초 작성]
+ * @since 2019. 1. 16.
+ */
+public class DeliveryResultHelper extends DeliveryHelper {}

+ 35 - 9
app/src/main/java/kr/co/zumo/app/lifeplus/model/Model.java

@@ -15,6 +15,7 @@ import kr.co.zumo.app.lifeplus.application.App;
 import kr.co.zumo.app.lifeplus.bean.api.BucketListRequestBean;
 import kr.co.zumo.app.lifeplus.bean.api.BucketListResultBean;
 import kr.co.zumo.app.lifeplus.helper.DeliveryHelper;
+import kr.co.zumo.app.lifeplus.helper.DeliveryResultHelper;
 import kr.co.zumo.app.lifeplus.helper.Helper;
 import kr.co.zumo.app.lifeplus.helper.IHelperProvider;
 import kr.co.zumo.app.lifeplus.model.module.APIError;
@@ -222,34 +223,59 @@ public abstract class Model extends ViewModel implements ILifeCycle, IHelperProv
   }
 
   /**
-   * 화면(Fragment) 간 전달 할 데이터를 등록한다.
+   * 다음 화면(Fragment)으로 전달 할 데이터를 등록한다.
    *
    * @param packaging
    */
   public void setDeliveryPackaging(Object packaging) {
-    DeliveryHelper helper = getHelper(DeliveryHelper.class);
-    helper.setPackaging(packaging);
+    getHelper(DeliveryHelper.class).setPackaging(packaging);
   }
 
   /**
-   * 화면(Fragment) 간 전달 할 데이터를 반환 @Nullable
+   * 다음 화면(Fragment)으로 전달 할 데이터를 반환 @Nullable
    *
    * @param nameClass
    * @return
    */
   @Nullable
   public <T> T getDeliveryPackaging(Class<T> nameClass) {
-    DeliveryHelper helper = getHelper(DeliveryHelper.class);
-
-    return helper.getPackaging(nameClass);
+    return getHelper(DeliveryHelper.class).getPackaging(nameClass);
   }
 
   /**
    * DeliveryHelper clearPackaging()
    */
   public void clearDeliveryPackaging() {
-    DeliveryHelper helper = getHelper(DeliveryHelper.class);
-    helper.clearPackaging();
+    getHelper(DeliveryHelper.class).clearPackaging();
+  }
+
+  /**
+   * 이전 화면(상위)에서 되돌아온 결과 데이터 등록
+   *
+   * @param packaging
+   */
+  public void setResultPackaging(Object packaging) {
+    Log.e("APP#  Model | setResultPackaging", "|" + " =============> " + packaging);
+    getHelper(DeliveryResultHelper.class).setPackaging(packaging);
+  }
+
+  /**
+   * 이전 화면(상위)에서 되돌아온 결과 데이터 반환
+   *
+   * @param nameClass
+   * @param <T>
+   * @return
+   */
+  @Nullable
+  public <T> T getResultPackaging(Class<T> nameClass) {
+    return getHelper(DeliveryResultHelper.class).getPackaging(nameClass);
+  }
+
+  /**
+   * 이전 화면(상위)에서 되돌아온 결과 데이터 clear
+   */
+  public void clearResultPackaging() {
+    getHelper(DeliveryResultHelper.class).clearPackaging();
   }
 
   /**

+ 1 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/supervisor/ActivityDeliveryHelper.java

@@ -22,6 +22,5 @@ public class ActivityDeliveryHelper extends DeliveryHelper {
     return ourInstance;
   }
 
-  private ActivityDeliveryHelper() {
-  }
+  private ActivityDeliveryHelper() { }
 }

+ 26 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/supervisor/ActivityDeliveryResultHelper.java

@@ -0,0 +1,26 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.supervisor;
+
+import kr.co.zumo.app.lifeplus.helper.DeliveryHelper;
+
+/**
+ * ActivityDeliveryResultHelper
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018-11-22]   [최초 작성]
+ * @since 2018-11-22
+ */
+public class ActivityDeliveryResultHelper extends DeliveryHelper {
+  private static ActivityDeliveryResultHelper ourInstance = new ActivityDeliveryResultHelper();
+
+  public static ActivityDeliveryResultHelper getInstance() {
+    return ourInstance;
+  }
+
+  private ActivityDeliveryResultHelper() { }
+}

+ 2 - 3
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/contents/ContentsModel.java

@@ -19,7 +19,6 @@ import kr.co.zumo.app.lifeplus.model.SuperModel;
 import kr.co.zumo.app.lifeplus.model.module.APIContentsDetailModule;
 import kr.co.zumo.app.lifeplus.model.module.APIError;
 import kr.co.zumo.app.lifeplus.model.module.APIModuleSimpleListener;
-import kr.co.zumo.app.lifeplus.supervisor.ActivityDeliveryHelper;
 import kr.co.zumo.app.lifeplus.supervisor.ContentsFlagHelper;
 import kr.co.zumo.app.lifeplus.tool.ReviewCounter;
 import kr.co.zumo.app.lifeplus.util.StringUtil;
@@ -266,7 +265,7 @@ public class ContentsModel extends ContentsBaseModel {
    * @return
    */
   public int getDeliveredIndex() {
-    Integer index = ActivityDeliveryHelper.getInstance().getPackaging(Integer.class);
+    Integer index = getResultPackaging(Integer.class);
     if (null == index) {
       index = -1;
     }
@@ -277,7 +276,7 @@ public class ContentsModel extends ContentsBaseModel {
    * 전체보기에서 선택된 인덱스 클리어.
    */
   public void clearDeliveredIndex() {
-    ActivityDeliveryHelper.getInstance().clearPackaging();
+    clearResultPackaging();
   }
 
   public boolean hasFlagChanged() {

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

@@ -3,13 +3,12 @@ package kr.co.zumo.app.lifeplus.view.screen.contents;
 import java.util.List;
 
 import io.reactivex.disposables.Disposable;
-import kr.co.zumo.app.lifeplus.bean.api.ContentsItemBean;
 import kr.co.zumo.app.lifeplus.bean.api.ContentsDetailResultBean;
+import kr.co.zumo.app.lifeplus.bean.api.ContentsItemBean;
 import kr.co.zumo.app.lifeplus.bean.api.StringRequestBean;
 import kr.co.zumo.app.lifeplus.model.module.APIContentsDetailModule;
 import kr.co.zumo.app.lifeplus.model.module.APIError;
 import kr.co.zumo.app.lifeplus.model.module.APIModuleSimpleListener;
-import kr.co.zumo.app.lifeplus.supervisor.ActivityDeliveryHelper;
 import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.dialog.ShareDialog;
 
@@ -110,10 +109,6 @@ public class ContentsOverviewModel extends ContentsBaseModel {
     });
   }
 
-  public void setResultPackaging(int index) {
-    ActivityDeliveryHelper.getInstance().setPackaging(index);
-  }
-
   public void setContentsItemBeans(List<ContentsItemBean> contentsItemBeans) {
     this.contentsItemBeans = contentsItemBeans;
   }

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

@@ -104,6 +104,7 @@ public class ContentsPresenter extends ContentsBasePresenter<ContentsModel, ICon
     }
 
     int deliveredIndex = model.getDeliveredIndex();
+    Log.e("APP#  ContentsPresenter | startInternal", "|" + "==============================>>>>> " + deliveredIndex);
     if (deliveredIndex > -1) {
       view.setScrollToPosition(deliveredIndex);
       model.clearDeliveredIndex();