Browse Source

[메인][New] 이미지 스페이싱

hyodong.min 7 years ago
parent
commit
91e9fb2aaf

+ 13 - 15
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainCategoryContentsAdapter.java

@@ -75,10 +75,6 @@ public class MainCategoryContentsAdapter extends RecyclerView.Adapter<MainCatego
     }
 
     switch (viewType) {
-      case VIEW_TYPE_HEAD:
-        view = inflater.inflate(R.layout.main_contents_category_head, parent, false);
-        holder = new MainCategoryContentsHeadView(context, view);
-        break;
       case VIEW_TYPE_IMAGE:
         view = inflater.inflate(R.layout.main_contents_category_image, parent, false);
         holder = new MainCategoryContentsImageView(context, view);
@@ -90,9 +86,6 @@ public class MainCategoryContentsAdapter extends RecyclerView.Adapter<MainCatego
       default:
         break;
     }
-    if (null != holder) {
-      holders.add(holder);
-    }
     return holder;
   }
 
@@ -117,6 +110,18 @@ public class MainCategoryContentsAdapter extends RecyclerView.Adapter<MainCatego
 
   }
 
+  @Override
+  public void onViewAttachedToWindow(@NonNull MainCategoryContentsView holder) {
+    holders.add(holder);
+    holder.attach();
+  }
+
+  @Override
+  public void onViewDetachedFromWindow(@NonNull MainCategoryContentsView holder) {
+    holders.remove(holder);
+    holder.detach();
+  }
+
   @Override
   public int getItemCount() {
     return bean.getContentsList().size();
@@ -130,14 +135,7 @@ public class MainCategoryContentsAdapter extends RecyclerView.Adapter<MainCatego
       type = VIEW_TYPE_TAIL;
     }
     else {
-      switch (position) {
-        case 0:
-          type = VIEW_TYPE_HEAD;
-          break;
-        default:
-          type = VIEW_TYPE_IMAGE;
-          break;
-      }
+      type = VIEW_TYPE_IMAGE;
     }
     return type;
   }

+ 11 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainCategoryContentsHeadView.java

@@ -35,8 +35,19 @@ public class MainCategoryContentsHeadView extends MainCategoryContentsView {
   public void init(int index, MainContentsCategoryBean bean, IEventListener listener) {
   }
 
+  @Override
+  public void attach() {
+
+  }
+
+  @Override
+  public void detach() {
+
+  }
+
   @Override
   public void dispose() {
 
   }
+
 }

+ 65 - 9
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainCategoryContentsImageView.java

@@ -42,6 +42,9 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
   private TextView textBig;
   private TextView textSmall;
   private ImageView imageView;
+  private View mask0;
+  private View mask1;
+  private View mask2;
 
   private int maskWidth;
   private int maskHeight;
@@ -51,6 +54,7 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
   private int imageHeight;
   private int screenWidth;
   private int screenHeight;
+  private int spaceWidth;
 
   public MainCategoryContentsImageView(Context context, View view) {
     super(context, view);
@@ -217,7 +221,7 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
           /**
            * 이미지가 스크린보다 클 때
            */
-          ratio = (float) (maskHeight + x) / (maskHeight + screenHeight);
+          ratio = (float) (maskHeight + y) / (maskHeight + screenHeight);
           ty = -((int) ((imageHeight + maskHeight) * ratio)) + maskHeight;
 
         }
@@ -229,15 +233,51 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
 
       imageView.setImageMatrix(matrix);
     }
+
+    x = (int) itemView.getX();
+    if (x > -maskWidth && x < screenWidth) {  // holder 가 표시되는 부분에서만 계산
+      // modify itemView x
+      cx = x;
+      ratio = (float) -cx / maskWidth;
+
+      if (ratio > 1) {
+        ratio = 1;
+      }
+      else if (ratio < 0) {
+        ratio = 0;
+      }
+      tx = (int) -(spaceWidth * ratio);
+      imageView.setX(tx);
+      mask0.setX(tx);
+      mask1.setX(tx);
+      mask2.setX(tx);
+
+//      if (index == 2) {
+//        Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " cx: " + cx);
+//        Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " ratio: " + ratio);
+//          Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " imageWidth: " + imageWidth);
+//          Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " maskWidth: " + maskWidth);
+//        Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " tx: " + tx);
+//          Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "|" + " dx: " + dx);
+//          Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "| item x: " + itemView.getX());
+//          Log.i("APP# MainCategoryContentsImageView | onScrolledInternal", "| item y: " + itemView.getY());
+//      }
+    }
   }
 
+
   @Override
   public void init(int index, MainContentsCategoryBean bean, IEventListener listener) {
     this.index = index;
+    this.listener = listener;
+    this.bean = bean;
 
     textBig = itemView.findViewById(R.id.text_big);
     textSmall = itemView.findViewById(R.id.text_small);
     imageView = itemView.findViewById(R.id.image_contents);
+    mask0 = itemView.findViewById(R.id.mask_0);
+    mask1 = itemView.findViewById(R.id.mask_1);
+    mask2 = itemView.findViewById(R.id.mask_2);
     imageView.setOnClickListener(v -> listener.onEvent(new Event.Builder(Event.CONTENTS).integer(index).build()));
 
     this.screenWidth = SuperModel.getInstance().getScreenWidth();
@@ -251,6 +291,8 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
     maskWidth = ResourceUtil.getDimension(R.dimen.main_contents_image_width);
     maskHeight = ResourceUtil.getDimension(R.dimen.main_contents_image_height);
 
+    spaceWidth = ResourceUtil.getDimension(R.dimen.main_contents_start_gap);
+
     String url = bean.getImageUrl();
 
 //    Drawable drawable = imageView.getDrawable();
@@ -262,6 +304,7 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
 
     Glide.with(imageView)
       .load(url)
+//      .apply(new RequestOptions().override(maskWidth, maskHeight))
       .listener(new RequestListener<Drawable>() {
         @Override
         public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@@ -274,8 +317,8 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
           imageWidth = resource.getIntrinsicWidth(); //this is the bitmap's width
           imageHeight = resource.getIntrinsicHeight(); //this is the bitmap's height
 
-//    Log.i("APP# MainCategoryContentsImageView | init", "| maskWidth: " + maskWidth + ", maskHeight: " + maskHeight);
-//    Log.i("APP# MainCategoryContentsImageView | init", "| imageWidth: " + imageWidth + ", imageHeight: " + imageHeight);
+//          Log.i("APP# MainCategoryContentsImageView | init", "| maskWidth: " + maskWidth + ", maskHeight: " + maskHeight);
+//          Log.i("APP# MainCategoryContentsImageView | init", "| imageWidth: " + imageWidth + ", imageHeight: " + imageHeight);
 
           onScrolledInternal();
 
@@ -288,17 +331,30 @@ public class MainCategoryContentsImageView extends MainCategoryContentsView {
 
   }
 
-  private int getScreenY(View view) {
-    int[] containerPos = new int[2];
-    view.getLocationOnScreen(containerPos);
+  @Override
+  public void attach() {
+  }
 
-    return containerPos[1];
+  @Override
+  public void detach() {
   }
 
   @Override
   public void dispose() {
-    // 이미지가 화면에서 사라진 뒤 변환 됨
-//    Glide.with(imageView).clear(imageView);
+    if (null != imageView) {
+      Glide.with(imageView).clear(imageView);
+      imageView.setOnClickListener(null);
+      imageView = null;
+      textBig = null;
+      textSmall = null;
+    }
+  }
+
+  private int getScreenY(View view) {
+    int[] containerPos = new int[2];
+    view.getLocationOnScreen(containerPos);
+
+    return containerPos[1];
   }
 
 }

+ 11 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainCategoryContentsTailView.java

@@ -39,8 +39,19 @@ public class MainCategoryContentsTailView extends MainCategoryContentsView {
     getView().findViewById(R.id.icon_more).setOnClickListener(v -> listener.onEvent(new Event.Builder(Event.MORE).build()));
   }
 
+  @Override
+  public void attach() {
+
+  }
+
+  @Override
+  public void detach() {
+
+  }
+
   @Override
   public void dispose() {
 
   }
+
 }

+ 8 - 5
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainCategoryContentsView.java

@@ -21,8 +21,10 @@ import kr.co.zumo.app.lifeplus.view.IEventListener;
  * @since 2018. 10. 15.
  */
 public abstract class MainCategoryContentsView extends RecyclerView.ViewHolder {
-  Context context;
-  int index;
+  protected IEventListener listener;
+  protected MainContentsCategoryBean bean;
+  protected Context context;
+  protected int index;
 
   public MainCategoryContentsView(Context context, View view) {
     super(view);
@@ -55,8 +57,9 @@ public abstract class MainCategoryContentsView extends RecyclerView.ViewHolder {
    */
   public abstract void init(int index, MainContentsCategoryBean bean, IEventListener listener);
 
-  /**
-   * dispose
-   */
+  public abstract void attach();
+
+  public abstract void detach();
+
   public abstract void dispose();
 }

+ 1 - 3
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainModel.java

@@ -90,12 +90,10 @@ public class MainModel extends Model {
       public void onApiSuccess(MainContentsResultBean resultBean) {
         contentsBeans = resultBean.getData();
 
-        // fixme dummy 추가 없이 처리 될 수 있도록 수정 필요;
         // 메인 데이터에 날씨 홀더 용 dummy data 추가
 
         for (MainContentsBean contentsBean : contentsBeans) {
-          // 카테고리 처음과 마지막에 dummy data 추가
-          contentsBean.getContentsList().add(0, null);
+          // 카테고리 마지막에 dummy data 추가
           contentsBean.getContentsList().add(new MainContentsCategoryBean());
         }
 

+ 2 - 0
app/src/main/res/layout/main_contents_category.xml

@@ -28,6 +28,8 @@
     android:id="@+id/recycler_view_category"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:clipToPadding="false"
+    android:paddingStart="@dimen/main_contents_start_gap"
     android:orientation="horizontal"
     app:layout_constraintTop_toBottomOf="@+id/text_title"/>
 

+ 3 - 0
app/src/main/res/layout/main_contents_category_image.xml

@@ -17,16 +17,19 @@
     />
 
   <View
+    android:id="@+id/mask_0"
     android:layout_width="@dimen/main_contents_image_width"
     android:layout_height="@dimen/main_contents_image_height"
     android:background="@drawable/rectangle_dim_main_1"/>
 
   <View
+    android:id="@+id/mask_1"
     android:layout_width="@dimen/main_contents_image_width"
     android:layout_height="@dimen/main_contents_image_height"
     android:background="@drawable/rectangle_dim_main_2"/>
 
   <View
+    android:id="@+id/mask_2"
     android:layout_width="@dimen/main_contents_image_width"
     android:layout_height="@dimen/main_contents_image_height"
     android:background="@drawable/rectangle_dim_main_3"/>