Sfoglia il codice sorgente

[메인][New] API 연동 시작 2

hyodong.min 7 anni fa
parent
commit
b3af42f069

+ 2 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsAdapter.java

@@ -43,6 +43,8 @@ public class MainContentsAdapter extends RecyclerView.Adapter<MainContentsView>
     this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     this.data = data;
 
+    // 날씨 뷰 dummy data 추가
+    this.data.add(0, new MainCategoryContentsBean());
     holders = new ArrayList<>();
   }
 

+ 19 - 11
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsCategoryAdapter.java

@@ -15,6 +15,7 @@ import java.util.List;
 
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.bean.api.MainCategoryContentsBean;
+import kr.co.zumo.app.lifeplus.bean.api.MainContentsBean;
 
 /**
  * MainContentsCategoryAdapter
@@ -42,6 +43,10 @@ public class MainContentsCategoryAdapter extends RecyclerView.Adapter<MainCatogo
     this.context = context;
     this.bean = bean;
 
+    // 처음과 마지막에 dummy data 추가
+    this.bean.getContentsList().add(0, new MainContentsBean());
+    this.bean.getContentsList().add(new MainContentsBean());
+
     holders = new ArrayList<>();
   }
 
@@ -104,22 +109,25 @@ public class MainContentsCategoryAdapter extends RecyclerView.Adapter<MainCatogo
 
   @Override
   public int getItemCount() {
-    return 6;
+    return bean.getContentsList().size();
   }
 
   @Override
   public int getItemViewType(int position) {
     int type;
-    switch (position) {
-      case 0:
-        type = VIEW_TYPE_HEAD;
-        break;
-      case 5:
-        type = VIEW_TYPE_TAIL;
-        break;
-      default:
-        type = VIEW_TYPE_IMAGE;
-        break;
+    int tail = bean.getContentsList().size() - 1;
+    if (tail == position) {
+      type = VIEW_TYPE_TAIL;
+    }
+    else {
+      switch (position) {
+        case 0:
+          type = VIEW_TYPE_HEAD;
+          break;
+        default:
+          type = VIEW_TYPE_IMAGE;
+          break;
+      }
     }
     return type;
   }

+ 61 - 7
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsCategoryImageView.java

@@ -144,14 +144,24 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
 
       if (x > -maskWidth && x < screenWidth) {  // holder 가 표시되는 부분에서만 계산
         // x = 0 ~ screen.w - mask.w
-        ratio = (float) x / (screenWidth - maskWidth);
+        int rail = screenWidth - maskWidth;
+        ratio = (float) x / (rail);
 
         tx = -((int) ((imageWidth - maskWidth) * ratio));  // image 이동 구간 0 ~ -image.w-mask.w
 
+        if (imageWidth > screenWidth) {
+          if (tx > 0) {
+            tx = 0;
+          }
+          else if (tx < maskWidth - imageWidth) {
+            tx = maskWidth - imageWidth;
+          }
+        }
+
         cx = (int) values[2];
         dx = tx - cx;
 
-//        if (index == 1) {
+//        if (index == 2) {
 //          Log.i("APP# MainContentsCategoryImageView | onScrolledInternal", "|" + " x: " + x);
 //          Log.i("APP# MainContentsCategoryImageView | onScrolledInternal", "|" + " ratio: " + ratio);
 //          Log.i("APP# MainContentsCategoryImageView | onScrolledInternal", "|" + " imageWidth: " + imageWidth);
@@ -199,17 +209,26 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
     maskWidth = ResourceUtil.getDimension(R.dimen.main_contents_image_width);
     maskHeight = ResourceUtil.getDimension(R.dimen.main_contents_image_height);
 
-    Glide.with(getView())
-      .load(bean.getImageUrl())
+    String url = bean.getImageUrl();
+
+//    Drawable drawable = imageView.getDrawable();
+    //you should call after the bitmap drawn
+//    imageWidth = maskWidth + 200; //drawable.getIntrinsicWidth(); //this is the bitmap's width
+//    imageHeight = maskHeight + 100; //drawable.getIntrinsicHeight(); //this is the bitmap's height
+//
+//    onScrolledInternal();
+
+    Glide.with(imageView)
+      .load(url)
       .listener(new RequestListener<Drawable>() {
         @Override
         public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
-          return true;
+          return false;
         }
 
         @Override
         public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
-          Drawable drawable = imageView.getDrawable();
+          Drawable drawable = resource;
           //you should call after the bitmap drawn
           imageWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width
           imageHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height
@@ -219,10 +238,12 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
 
           onScrolledInternal();
 
-          return true;
+          return false;
         }
       })
       .into(imageView);
+
+
   }
 
   private int getScreenY(View view) {
@@ -236,4 +257,37 @@ public class MainContentsCategoryImageView extends MainCatogoryContentsView {
   public void dispose() {
 
   }
+
+//
+//  @GlideModule
+//  public class GlideImageLoader extends AppGlideModule {
+//
+//    public void load(ImageView imageView, String url) {
+//
+//      Glide.with(imageView)
+//        .load(url)
+//        .listener(new RequestListener<Drawable>() {
+//          @Override
+//          public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+//            return true;
+//          }
+//
+//          @Override
+//          public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+//            Drawable drawable = resource;
+//            //you should call after the bitmap drawn
+//            imageWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width
+//            imageHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height
+//
+////    Log.i("APP# MainContentsCategoryImageView | init", "| maskWidth: " + maskWidth + ", maskHeight: " + maskHeight);
+////    Log.i("APP# MainContentsCategoryImageView | init", "| imageWidth: " + imageWidth + ", imageHeight: " + imageHeight);
+//
+//            onScrolledInternal();
+//
+//            return true;
+//          }
+//        })
+//        .into(imageView);
+//    }
+//  }
 }