Explorar o código

[콘텐츠상세][Common] 무한스크롤 구현 및 레이아웃 조정

Hasemi %!s(int64=7) %!d(string=hai) anos
pai
achega
f090a47028

+ 21 - 8
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/contents/CustomListicleImageView.java

@@ -10,6 +10,7 @@ import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import java.util.List;
@@ -32,6 +33,9 @@ import kr.co.zumo.app.lifeplus.view.IEventListener;
 public class CustomListicleImageView extends ConstraintLayout {
 
   private CustomListicleImageViewAdapter adapter;
+  private ImageView imageViewPrePage;
+  private ImageView imageViewNextPage;
+
   private RecyclerView recyclerView;
   private TextView textViewCurrentPage;
   private TextView textViewTotalPage;
@@ -39,9 +43,9 @@ public class CustomListicleImageView extends ConstraintLayout {
   private TextView textViewTitle;
   private TextView textViewSubTitle;
   private View layoutPager;
+  private int index = 0;
   private int currentIndex = 0;
   private int contentsLength = 0;
-  private boolean loading = false;
 
   public CustomListicleImageView(Context context) {
     super(context);
@@ -69,6 +73,9 @@ public class CustomListicleImageView extends ConstraintLayout {
     textViewSubTitle = findViewById(R.id.text_view_sub_title);
     layoutPager = findViewById(R.id.layout_pager);
 
+    imageViewPrePage = findViewById(R.id.image_view_pre_page);
+    imageViewNextPage = findViewById(R.id.image_view_next_page);
+
     recyclerView = findViewById(R.id.recycler_view_listicle_view);
 
     SnapHelper snapHelper = new PagerSnapHelper();
@@ -170,13 +177,9 @@ public class CustomListicleImageView extends ConstraintLayout {
   private RecyclerView.OnScrollListener scrollEventListener = new RecyclerView.OnScrollListener() {
     @Override
     public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
-      int index = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
-      index = index % contentsLength;
-      if (currentIndex != index) {
-        currentIndex = index;
-        textViewCurrentPage.setText(String.valueOf(index + 1));
-      }
-
+      index = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
+      currentIndex = index % contentsLength;
+      textViewCurrentPage.setText(String.valueOf(currentIndex + 1));
     }
   };
 
@@ -186,6 +189,7 @@ public class CustomListicleImageView extends ConstraintLayout {
     textViewTitle.setText(title);
     textViewSubTitle.setText(subTitle);
 
+
     contentsLength = contentsDetailImageBeans.size();
     if (contentsLength > 1) {
       layoutPager.setVisibility(View.VISIBLE);
@@ -211,6 +215,8 @@ public class CustomListicleImageView extends ConstraintLayout {
     recyclerView.addOnItemTouchListener(touchEventListener);
     recyclerView.addOnScrollListener(scrollEventListener);
     recyclerView.scrollToPosition(contentsLength * 10000);
+    imageViewPrePage.setOnClickListener(view -> {onClickPrePage();});
+    imageViewNextPage.setOnClickListener(view -> {onClickNextPage();});
   }
 
   public void dispose() {
@@ -220,5 +226,12 @@ public class CustomListicleImageView extends ConstraintLayout {
     }
   }
 
+  private void onClickPrePage() {
+    recyclerView.smoothScrollToPosition(index - 1);
+  }
+
+  private void onClickNextPage() {
+    recyclerView.smoothScrollToPosition(index + 1);
+  }
 
 }

+ 6 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/contents/CustomListicleImageViewAdapter.java

@@ -75,7 +75,11 @@ public class CustomListicleImageViewAdapter extends RecyclerView.Adapter<CustomL
 
   @Override
   public int getItemCount() {
-    return (contentsDetailImageBeans == null) ? 0 : Integer.MAX_VALUE;
-    //return contentsDetailImageBeans.size();
+    if (null != contentsDetailImageBeans) {
+      return (contentsDetailImageBeans.size() == 1) ? 1 : Integer.MAX_VALUE;
+    }
+    else {
+      return 0;
+    }
   }
 }

+ 1 - 1
app/src/main/res/layout/custom_listicle_image_view.xml

@@ -21,7 +21,7 @@
     android:layout_height="wrap_content"
     android:layout_marginStart="18dp"
     android:layout_marginTop="19dp"
-    android:layout_marginBottom="16dp"
+    android:layout_marginBottom="11dp"
     app:layout_constraintBottom_toBottomOf="parent"
     app:layout_constraintStart_toStartOf="parent"
     tools:background="@color/CD0D0D0">