浏览代码

[카테고리메인][Common] 카테고리 메인 이미지 스팬그리드레이아웃 적용 및 뷰홀더 생성

Hasemi 7 年之前
父节点
当前提交
34042f049b

+ 33 - 18
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/category/SecondCategoryMainAdapter.java

@@ -19,12 +19,12 @@ import kr.co.zumo.app.R;
  * @history 하세미   [2018-10-24]   [최초 작성]
  * @since 2018-10-24
  */
-public class SecondCategoryMainAdapter extends RecyclerView.Adapter<SecondCategoryMainViewHolder> {
+public class SecondCategoryMainAdapter extends RecyclerView.Adapter<SecondCategoryMainView> {
 
   private Context context;
   private LayoutInflater inflater;
-  private static final int FULL_IMAGE = 0;
-  private static final int DEFAULT_IMAGE = 1;
+  public static final int FULL_IMAGE = 0;
+  public static final int DEFAULT_IMAGE = 1;
 
 
   public SecondCategoryMainAdapter(Context context) {
@@ -34,28 +34,43 @@ public class SecondCategoryMainAdapter extends RecyclerView.Adapter<SecondCatego
 
   @NonNull
   @Override
-  public SecondCategoryMainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
-    View view = inflater.inflate(R.layout.main_second_category_image_view, parent, false);
-    return new SecondCategoryMainViewHolder(view);
+  public SecondCategoryMainView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+    View view;
+
+    switch (viewType) {
+      case FULL_IMAGE:
+        view = inflater.inflate(R.layout.main_second_category_full_image_view, parent, false);
+        return new SecondCategoryMainFullImageViewHolder(view);
+      case DEFAULT_IMAGE:
+        view = inflater.inflate(R.layout.main_second_category_default_image_view, parent, false);
+        return new SecondCategoryMainDefaultImageViewHolder(view);
+      default:
+        break;
+
+    }
+    return null;
   }
 
   @Override
-  public void onBindViewHolder(@NonNull SecondCategoryMainViewHolder holder, int position) {
-    holder.doDataSetting();
+  public void onBindViewHolder(@NonNull SecondCategoryMainView holder, int position) {
+   holder.init();
   }
 
   @Override
   public int getItemCount() {
-    return 9;
+    return 12;
   }
 
-//  @Override
-//  public int getItemViewType(int position) {
-//    if (position == 0 || position == 5) {
-//      return FULL_IMAGE;
-//    }
-//    else {
-//      return DEFAULT_IMAGE;
-//    }
-//  }
+  @Override
+  public int getItemViewType(int position) {
+    position = position % 9;
+    switch (position) {
+      case 0:
+        return FULL_IMAGE;
+      case 4:
+        return FULL_IMAGE;
+      default:
+        return DEFAULT_IMAGE;
+    }
+  }
 }

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

@@ -0,0 +1,20 @@
+package kr.co.zumo.app.lifeplus.view.screen.main.category;
+
+import android.view.View;
+
+/**
+ * SecondCategoryDefaultImageViewHolder
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-10-31]   [최초 작성]
+ * @since 2018-10-31
+ */
+public class SecondCategoryMainDefaultImageViewHolder extends SecondCategoryMainView {
+
+  public SecondCategoryMainDefaultImageViewHolder(View itemView) {
+    super(itemView);
+  }
+}

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

@@ -63,20 +63,17 @@ public class SecondCategoryMainFragment extends FragmentBase<SecondCategoryMainP
     recyclerViewSecondCategoryMain.setLayoutManager(new SpannedGridLayoutManager(
       new SpannedGridLayoutManager.GridSpanLookup() {
         @Override
-        public SpannedGridLayoutManager.SpanInfo getSpanInfo(int position)
-        {
-          //position 1, 6,
-          // 10 , 15 , 19 , 24
-          switch (position) {
-            case 0:
-              return new SpannedGridLayoutManager.SpanInfo(2, 2);
-            case 5:
+        public SpannedGridLayoutManager.SpanInfo getSpanInfo(int position) {
+          switch (secondCategoryMainAdapter.getItemViewType(position)) {
+            case SecondCategoryMainAdapter.DEFAULT_IMAGE:
+              return new SpannedGridLayoutManager.SpanInfo(1, 1);
+            case SecondCategoryMainAdapter.FULL_IMAGE:
               return new SpannedGridLayoutManager.SpanInfo(2, 2);
             default:
               return new SpannedGridLayoutManager.SpanInfo(1, 1);
           }
         }
-      },3,1f ));
+      }, 3, 1f));
     recyclerViewSecondCategoryMain.setAdapter(secondCategoryMainAdapter);
   }
 

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

@@ -0,0 +1,24 @@
+package kr.co.zumo.app.lifeplus.view.screen.main.category;
+
+import android.view.View;
+
+/**
+ * SecondCategoryMainViewHolder
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-10-24]   [최초 작성]
+ * @since 2018-10-24
+ */
+public class SecondCategoryMainFullImageViewHolder extends SecondCategoryMainView {
+
+  public SecondCategoryMainFullImageViewHolder(View itemView) {
+    super(itemView);
+  }
+
+  public void doDataSetting() {
+
+  }
+}

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

@@ -0,0 +1,31 @@
+package kr.co.zumo.app.lifeplus.view.screen.main.category;
+
+import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
+
+import kr.co.zumo.app.lifeplus.util.ResourceUtil;
+
+/**
+ * SecondCategoryView
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-10-31]   [최초 작성]
+ * @since 2018-10-31
+ */
+public class SecondCategoryMainView extends RecyclerView.ViewHolder {
+
+  public SecondCategoryMainView(View itemView) {
+    super(itemView);
+    GridLayoutManager.LayoutParams layoutParams = new  GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+    float margin = ResourceUtil.dpToPx(5);
+    layoutParams.setMargins((int) margin, (int) margin, (int) margin, (int) margin);
+    itemView.setLayoutParams(layoutParams);
+  }
+
+  public void init() {}
+}

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

@@ -1,71 +0,0 @@
-package kr.co.zumo.app.lifeplus.view.screen.main.category;
-
-import android.support.v7.widget.GridLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-
-import kr.co.zumo.app.lifeplus.util.ResourceUtil;
-
-/**
- * SecondCategoryMainViewHolder
- * <pre>
- * </pre>
- *
- * @author 하세미
- * @version 1.0
- * @history 하세미   [2018-10-24]   [최초 작성]
- * @since 2018-10-24
- */
-public class SecondCategoryMainViewHolder extends RecyclerView.ViewHolder {
-
-  //  private ImageView imageViewMainSecondCategory;
-//  private TextView textViewMainSecondCategory;
-  private ImageView imageView1;
-  private ImageView imageView2;
-  private ImageView imageView3;
-//    private ImageView imageView4;
-//    private ImageView imageView5;
-//    private ImageView imageView6;
-//    private ImageView imageView7;
-//    private ImageView imageView8;
-//    private ImageView imageView9;
-
-  public SecondCategoryMainViewHolder(View itemView) {
-    super(itemView);
-    GridLayoutManager.LayoutParams layoutParams = new
-      GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
-      ViewGroup.LayoutParams.MATCH_PARENT);
-    float margin = ResourceUtil.dpToPx(5);
-    layoutParams.setMargins((int) margin, (int) margin, (int) margin,
-      (int) margin);
-    itemView.setLayoutParams(layoutParams);
-//    imageViewMainSecondCategory = itemView.findViewById(R.id.image_view_main_second_category);
-//    textViewMainSecondCategory = itemView.findViewById(R.id.text_view_main_second_title);
-  /*  imageView1 = itemView.findViewById(R.id.first_image_view);
-    imageView2 = itemView.findViewById(R.id.second_image_view);
-    imageView3 = itemView.findViewById(R.id.third_image_view);*/
-//    imageView4 = itemView.findViewById(R.id.fourth_image_view);
-//    imageView5 = itemView.findViewById(R.id.fifth_image_view);
-//    imageView6 = itemView.findViewById(R.id.sixth_image_view);
-//    imageView7 = itemView.findViewById(R.id.seventh_image_view);
-//    imageView8 = itemView.findViewById(R.id.eighth_image_view);
-//    imageView9 = itemView.findViewById(R.id.ninth_image_view);
-  }
-
-  public void doDataSetting() {
-//    imageViewMainSecondCategory.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-//    textViewMainSecondCategory.setText(R.string.main_second_category_title);
-  /*  imageView1.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-    imageView2.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-    imageView3.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));*/
-//    imageView4.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-//    imageView5.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-//    imageView6.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-//    imageView7.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-//    imageView8.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-//    imageView9.setImageDrawable(itemView.getResources().getDrawable(R.drawable.img_bestbucket_3));
-
-  }
-}

+ 3 - 1
app/src/main/res/layout/activity_main.xml

@@ -59,7 +59,9 @@
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@color/CFFFFFF"
-      android:visibility="gone">
+      android:visibility="gone"
+      tools:visibility="visible"
+      >
 
 
       <RadioGroup

+ 30 - 0
app/src/main/res/layout/main_second_category_default_image_view.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  xmlns:app="http://schemas.android.com/apk/res-auto"
+  xmlns:tools="http://schemas.android.com/tools"
+  android:layout_width="match_parent"
+  android:layout_height="match_parent">
+  <ImageView
+    android:id="@+id/image_view_default"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:scaleType="centerCrop"
+    android:src="@drawable/mymain_bucket_banner_3"
+    />
+
+  <TextView
+    android:id="@+id/text_view_default"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:textSize="12sp"
+    android:textColor="@color/CFFFFFF"
+    android:lineSpacingExtra="4sp"
+    android:text="중국판 헐리우드"
+    app:layout_constraintStart_toStartOf="parent"
+    app:layout_constraintEnd_toEndOf="parent"
+    app:layout_constraintBottom_toBottomOf="parent"
+    android:layout_marginBottom="10dp"
+    />
+
+</android.support.constraint.ConstraintLayout>

+ 30 - 0
app/src/main/res/layout/main_second_category_full_image_view.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  xmlns:app="http://schemas.android.com/apk/res-auto"
+  xmlns:tools="http://schemas.android.com/tools"
+  android:layout_width="match_parent"
+  android:layout_height="match_parent">
+
+  <ImageView
+    android:id="@+id/image_view_1"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:scaleType="centerCrop"
+    android:src="@drawable/mymain_bucket_banner_3"
+    />
+
+  <TextView
+    app:layout_constraintStart_toStartOf="parent"
+    app:layout_constraintBottom_toBottomOf="parent"
+    android:layout_marginStart="16dp"
+    android:layout_marginBottom="15dp"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:lineSpacingExtra="6sp"
+    android:textColor="@color/CFFFFFF"
+    android:textSize="14sp"
+    android:text="디즈니랜드 여행"
+    />
+
+</android.support.constraint.ConstraintLayout>

+ 0 - 19
app/src/main/res/layout/main_second_category_image_view.xml

@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout
-  xmlns:android="http://schemas.android.com/apk/res/android"
-  xmlns:app="http://schemas.android.com/apk/res-auto"
-  xmlns:tools="http://schemas.android.com/tools"
-  android:layout_width="match_parent"
-  android:layout_height="wrap_content">
-<ImageView
-  android:id="@+id/image_view_1"
-  android:layout_width="wrap_content"
-  android:layout_height="wrap_content"
-  android:scaleType="centerCrop"
-  android:src="@drawable/img_bannerimg_1"
-  >
-
-
-</ImageView>
-
-</android.support.constraint.ConstraintLayout>

+ 2 - 1
app/src/main/res/layout/main_series_view.xml

@@ -8,7 +8,8 @@
     android:id="@+id/main_category_recycler_view"
     android:paddingStart="16dp"
     android:paddingEnd="16dp"
-    android:paddingBottom="30dp"
+    android:paddingBottom="31dp"
+    android:clipToPadding="false"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"/>
 </android.support.constraint.ConstraintLayout>