Browse Source

[공통][New] 팝업 정보 API 중복 호출 방지

hyodong.min 7 years ago
parent
commit
70606f10a0

+ 1 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/activity/ScreenStarter.java

@@ -111,6 +111,7 @@ public class ScreenStarter {
       public void onApiSuccess(PopupInfoResultBean resultBean) {
         PopupInfoListBean popupInfoListBean = resultBean.getData();
         if (null != popupInfoListBean) {
+          SystemPopupModelHelper.getInstance().setPromotionPopupBeans(popupInfoListBean.getPromotionPopupList());
           SystemPopupModelHelper.getInstance().setSystemPopupBeans(popupInfoListBean.getSystemPopupList());
         }
 

+ 22 - 15
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainModel.java

@@ -131,23 +131,30 @@ public class MainModel extends Model {
   }
 
   public void loadPopupInfo() {
-    disposablePromotion = new APIPopupLoadModule().call(new RequestBean(), new APIModuleSimpleListener<PopupInfoResultBean>() {
-      @Override
-      public void onApiSuccess(PopupInfoResultBean resultBean) {
-        popupInfoListBean = resultBean.getData();
-        if (null != popupInfoListBean) {
-          promotionPopupBeans = popupInfoListBean.getPromotionPopupList();
-          SystemPopupModelHelper.getInstance().setSystemPopupBeans(popupInfoListBean.getSystemPopupList());
+    if (SystemPopupModelHelper.getInstance().isAvailableRefresh()) {
+      disposablePromotion = new APIPopupLoadModule().call(new RequestBean(), new APIModuleSimpleListener<PopupInfoResultBean>() {
+        @Override
+        public void onApiSuccess(PopupInfoResultBean resultBean) {
+          popupInfoListBean = resultBean.getData();
+          if (null != popupInfoListBean) {
+            promotionPopupBeans = popupInfoListBean.getPromotionPopupList();
+            SystemPopupModelHelper.getInstance().setSystemPopupBeans(popupInfoListBean.getSystemPopupList());
+          }
+
+          onResult(new Event.Builder(Event.SUCCESS).integer(Event.LOADED_POPUP_INFO).build());
         }
 
-        onResult(new Event.Builder(Event.SUCCESS).integer(Event.LOADED_POPUP_INFO).build());
-      }
-
-      @Override
-      public void onApiError(String errorMessage, APIError error) {
-        onResult(new Event.Builder(Event.ERROR).integer(Event.LOADED_POPUP_INFO).string(errorMessage).build());
-      }
-    });
+        @Override
+        public void onApiError(String errorMessage, APIError error) {
+          onResult(new Event.Builder(Event.ERROR).integer(Event.LOADED_POPUP_INFO).string(errorMessage).build());
+        }
+      });
+    }
+    else {
+      SystemPopupModelHelper.getInstance().setAvailableRefresh();
+      promotionPopupBeans = SystemPopupModelHelper.getInstance().getPromotionPopupBeans();
+      onResult(new Event.Builder(Event.SUCCESS).integer(Event.LOADED_POPUP_INFO).build());
+    }
   }
 
   private List<PromotionPopupBean> promotionPopupBeans;

+ 30 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/SystemPopupModelHelper.java

@@ -7,6 +7,7 @@ import java.util.List;
 
 import kr.co.zumo.app.lifeplus.bean.api.LifeplusData;
 import kr.co.zumo.app.lifeplus.bean.api.MenuIDBean;
+import kr.co.zumo.app.lifeplus.bean.api.PromotionPopupBean;
 import kr.co.zumo.app.lifeplus.bean.api.SystemPopupBean;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
 import kr.co.zumo.app.lifeplus.view.presenter.LinkInvoker;
@@ -32,13 +33,41 @@ public class SystemPopupModelHelper {
   }
 
   private List<SystemPopupBean> systemPopupBeans;
+  private List<PromotionPopupBean> promotionPopupBeans;
   private SystemPopupBean matchedBean;
+  private boolean isAvailableRefresh = false;
 
   public void setSystemPopupBeans(List<SystemPopupBean> systemPopupBeans) {
     this.systemPopupBeans = systemPopupBeans;
   }
 
-  /*
+  public void setPromotionPopupBeans(List<PromotionPopupBean> promotionPopupBeans) {
+    this.promotionPopupBeans = promotionPopupBeans;
+  }
+
+  public List<PromotionPopupBean> getPromotionPopupBeans() {
+    return promotionPopupBeans;
+  }
+
+  /**
+   * 앱 실행 시 스플래시에서 로드하므로 바로 다음 메인에서는 로드하지 않도록 설정
+   * 단, 이전에 에러로 로드 실패 시에는 다시 로드
+   *
+   * @return
+   */
+  public boolean isAvailableRefresh() {
+    return isAvailableRefresh || null == systemPopupBeans;
+  }
+
+  /**
+   * 한 번 스킵 후 리로딩이 가능하도록 설정
+   */
+  public void setAvailableRefresh() {
+    isAvailableRefresh = true;
+  }
+
+
+/*
 
   화면 진입 전 진입불가 화면을 체크