瀏覽代碼

[카테고리][New] 카테고리 No <-> index 변환을 CategoryID 클래스에서 처리

hyodong.min 6 年之前
父節點
當前提交
deb3e31700

+ 86 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/CategoryID.java

@@ -3,6 +3,14 @@
  */
 package kr.co.zumo.app.lifeplus.view.screen.category;
 
+import android.support.annotation.StringDef;
+import android.support.annotation.StringRes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import kr.co.zumo.app.R;
+
 /**
  * CategoryID
  * <pre>
@@ -20,4 +28,82 @@ public class CategoryID {
   public final static String CATEGORY_3 = "4";
   public final static String CATEGORY_4 = "5";
   public final static String CATEGORY_5 = "6";
+
+  @Retention(RetentionPolicy.SOURCE)
+  @StringDef({
+    CATEGORY_NONE, CATEGORY_1, CATEGORY_2, CATEGORY_3, CATEGORY_4, CATEGORY_5
+  })
+  public @interface No {}
+
+  /**
+   * 카테고리 No 로 인덱스를 반환한다.
+   *
+   * @param no
+   * @return
+   */
+  public static int ofIndex(@No String no) {
+    switch (no) {
+      case CATEGORY_1:
+        return 0;
+      case CATEGORY_2:
+        return 1;
+      case CATEGORY_3:
+        return 2;
+      case CATEGORY_5:
+//        return 4;
+//      case CATEGORY_4:
+        return 3;
+      default:
+        return -1;
+    }
+  }
+
+  /**
+   * 카테고리 index 로 No 를 반환
+   *
+   * @param index
+   * @return
+   */
+  @No
+  public static String ofNo(int index) {
+    switch (index) {
+      case 0:
+        return CATEGORY_1;
+      case 1:
+        return CATEGORY_2;
+      case 2:
+        return CATEGORY_3;
+      case 3:
+//        return CATEGORY_4;
+//      case 4:
+        return CATEGORY_5;
+      default:
+        return CATEGORY_NONE;
+    }
+  }
+
+  /**
+   * 카테고리 No 로 이름을 반환한다.
+   *
+   * @param no
+   * @return
+   */
+  @StringRes
+  public static int getCategoryNameByNo(@CategoryID.No String no) {
+    switch (no) {
+      case CategoryID.CATEGORY_1:
+        return R.string.fa_category_title_1;
+      case CategoryID.CATEGORY_2:
+        return R.string.fa_category_title_2;
+      case CategoryID.CATEGORY_3:
+        return R.string.fa_category_title_3;
+      case CategoryID.CATEGORY_4:
+        return R.string.fa_category_title_4;
+      case CategoryID.CATEGORY_5:
+        return R.string.fa_category_title_5;
+      default:
+        return R.string.empty_string;
+    }
+
+  }
 }

+ 4 - 19
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/CategoryMainModel.java

@@ -9,7 +9,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import io.reactivex.disposables.Disposable;
-import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.bean.api.CategoryBannerBean;
 import kr.co.zumo.app.lifeplus.bean.api.CategoryBannerResultBean;
 import kr.co.zumo.app.lifeplus.bean.api.CategoryContentsBean;
@@ -115,9 +114,12 @@ public abstract class CategoryMainModel extends Model {
    ***********************************/
   protected abstract void modifyContents(List<CategoryContentsBean> contentsBeans);
 
+  @CategoryID.No
   protected abstract String getCategoryNo();
 
-  protected abstract int getCategoryIndex();
+  protected final int getCategoryIndex() {
+    return CategoryID.ofIndex(getCategoryNo());
+  }
 
   /**
    * 컨텐츠 정렬 방식
@@ -256,21 +258,4 @@ public abstract class CategoryMainModel extends Model {
     return recommendBeans.get(selectedRecommendedIndex);
   }
 
-  public int getCategoryNameByIndex(int index) {
-    switch (index) {
-      case 0:
-        return R.string.fa_category_title_1;
-      case 1:
-        return R.string.fa_category_title_2;
-      case 2:
-        return R.string.fa_category_title_3;
-      case 3:
-        return R.string.fa_category_title_4;
-      case 4:
-        return R.string.fa_category_title_5;
-      default:
-        return R.string.empty_string;
-    }
-
-  }
 }

+ 9 - 11
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/CategoryMainPresenter.java

@@ -148,9 +148,6 @@ public abstract class CategoryMainPresenter<M extends CategoryMainModel, V exten
         break;
       case Event.RECOMMEND:
 
-        /**
-         * todo api 수정되면 디테일 로딩 없이 시리즈/디테일 구분
-         */
         model.setSelectedRecommendedIndex(event.getIndex());
 
         flagContentsBean = model.getSelectedRecommendBean();
@@ -172,7 +169,7 @@ public abstract class CategoryMainPresenter<M extends CategoryMainModel, V exten
 
         break;
       case Event.CONTENTS:
-        linkContents(R.string.fa_type_list,  event.getIndex(), model.getContents().get(event.getIndex()));
+        linkContents(R.string.fa_type_list, event.getIndex(), model.getContents().get(event.getIndex()));
         break;
       case Event.BANNER:
         linkContents(R.string.fa_type_banner, event.getIndex(), model.getBannerBeans().get(event.getIndex()));
@@ -320,27 +317,28 @@ public abstract class CategoryMainPresenter<M extends CategoryMainModel, V exten
 
   @Override
   public final void onNavigationClickCategoryTab(ActionBar navigationBar, int index) {
+    String categoryNo = CategoryID.ofNo(index);
     firebaseAnalyticsHelper.logCategoryTabMenu(
       ResourceUtil.getString(R.string.fa_screen_category),
       model.getCategoryIndex() + 1,
       getAnalyticsScreenName(),
       index + 1,
-      ResourceUtil.getString(model.getCategoryNameByIndex(index)));
+      ResourceUtil.getString(CategoryID.getCategoryNameByNo(categoryNo)));
 
-    switch (index) {
-      case 0:
+    switch (categoryNo) {
+      case CategoryID.CATEGORY_1:
         go(ScreenID.FIRST_CATEGORY);
         break;
-      case 1:
+      case CategoryID.CATEGORY_2:
         go(ScreenID.SECOND_CATEGORY);
         break;
-      case 2:
+      case CategoryID.CATEGORY_3:
         go(ScreenID.THIRD_CATEGORY);
         break;
-      case 3:
+      case CategoryID.CATEGORY_4:
         go(ScreenID.FOURTH_CATEGORY);
         break;
-      case 4:
+      case CategoryID.CATEGORY_5:
         go(ScreenID.FIFTH_CATEGORY);
         break;
       default:

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type1/FirstCategoryMainFragment.java

@@ -42,7 +42,7 @@ public class FirstCategoryMainFragment extends CategoryMainFragment<FirstCategor
       .menu(actionBar -> presenter.onNavigationClickMenu(actionBar))
       .search(actionBar -> presenter.onNavigationClickSearch(actionBar))
       .back(actionBar -> presenter.onNavigationClickBack(actionBar))
-      .category(0, (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
+      .category(CategoryID.ofIndex(CategoryID.CATEGORY_1), (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
       .show();
 
   }

+ 0 - 5
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type1/FirstCategoryMainModel.java

@@ -22,9 +22,4 @@ public class FirstCategoryMainModel extends CategoryFilterModel {
     return CategoryID.CATEGORY_1;
   }
 
-  @Override
-  protected int getCategoryIndex() {
-    return 0;
-  }
-
 }

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type2/SecondCategoryMainFragment.java

@@ -45,7 +45,7 @@ public class SecondCategoryMainFragment extends CategoryMainFragment<SecondCateg
       .menu(actionBar -> presenter.onNavigationClickMenu(actionBar))
       .search(actionBar -> presenter.onNavigationClickSearch(actionBar))
       .back(actionBar -> presenter.onNavigationClickBack(actionBar))
-      .category(1, (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
+      .category(CategoryID.ofIndex(CategoryID.CATEGORY_2), (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
       .show();
   }
 

+ 0 - 5
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type2/SecondCategoryMainModel.java

@@ -22,9 +22,4 @@ public class SecondCategoryMainModel extends CategoryFilterModel {
     return CategoryID.CATEGORY_2;
   }
 
-  @Override
-  protected int getCategoryIndex() {
-    return 1;
-  }
-
 }

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type3/ThirdCategoryMainFragment.java

@@ -43,7 +43,7 @@ public class ThirdCategoryMainFragment extends CategoryMainFragment<ThirdCategor
       .menu(actionBar -> presenter.onNavigationClickMenu(actionBar))
       .search(actionBar -> presenter.onNavigationClickSearch(actionBar))
       .back(actionBar -> presenter.onNavigationClickBack(actionBar))
-      .category(2, (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
+      .category(CategoryID.ofIndex(CategoryID.CATEGORY_3), (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
       .show();
   }
 

+ 0 - 6
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type3/ThirdCategoryMainModel.java

@@ -26,12 +26,6 @@ public class ThirdCategoryMainModel extends CategoryMainModel {
     return CategoryID.CATEGORY_3;
   }
 
-  @Override
-  protected int getCategoryIndex() {
-    return 2;
-  }
-
-
   @Override
   protected void createViewInternal() {
   }

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type4/FourthCategoryMainFragment.java

@@ -43,7 +43,7 @@ public class FourthCategoryMainFragment extends CategoryMainFragment<FourthCateg
       .menu(actionBar -> presenter.onNavigationClickMenu(actionBar))
       .search(actionBar -> presenter.onNavigationClickSearch(actionBar))
       .back(actionBar -> presenter.onNavigationClickBack(actionBar))
-      .category(3, (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
+      .category(CategoryID.ofIndex(CategoryID.CATEGORY_4), (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
       .show();
   }
 

+ 0 - 6
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type4/FourthCategoryMainModel.java

@@ -26,12 +26,6 @@ public class FourthCategoryMainModel extends CategoryMainModel {
     return CategoryID.CATEGORY_4;
   }
 
-  @Override
-  protected int getCategoryIndex() {
-    return 3;
-  }
-
-
   @Override
   protected void createViewInternal() {
   }

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type5/FifthCategoryMainFragment.java

@@ -35,7 +35,7 @@ public class FifthCategoryMainFragment extends CategoryMainFragment<FifthCategor
       .menu(actionBar -> presenter.onNavigationClickMenu(actionBar))
       .search(actionBar -> presenter.onNavigationClickSearch(actionBar))
       .back(actionBar -> presenter.onNavigationClickBack(actionBar))
-      .category(4, (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
+      .category(CategoryID.ofIndex(CategoryID.CATEGORY_5), (actionBar, index) -> presenter.onNavigationClickCategoryTab(actionBar, index))
       .show();
   }
 

+ 0 - 6
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type5/FifthCategoryMainModel.java

@@ -30,12 +30,6 @@ public class FifthCategoryMainModel extends CategoryMainModel {
     return CategoryID.CATEGORY_5;
   }
 
-  @Override
-  protected int getCategoryIndex() {
-    return 4;
-  }
-
-
   @Override
   protected void createViewInternal() {
   }