Browse Source

[이벤트][Common] 커스텀 인디케이터로 바꿈

Hasemi 7 năm trước cách đây
mục cha
commit
896071868b

+ 1 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/contents/ShownWithContentsViewHolder.java

@@ -33,8 +33,7 @@ public class ShownWithContentsViewHolder extends RecyclerView.ViewHolder {
 
   public void bind(IEventListener listener) {
     textViewSubtitle.setText("여유로운 하루를 즐기는 방법");
-    textViewTitle.setText("뜻밖의 행복한 오후 반차\n" +
-      "어디가지? 코스 6");
+    textViewTitle.setText("뜻밖의 행복한 오후 반차\n" + "어디가지? 코스 6");
     imageViewBackground.setImageDrawable(itemView.getResources().getDrawable(R.drawable.mymain_bucket_banner_3));
 
   }

+ 30 - 59
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/event/CustomIndicator.java

@@ -5,13 +5,11 @@ import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.support.annotation.Nullable;
-import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.View;
 
-import kr.co.zumo.app.lifeplus.view.IndexScrollListener;
-
 /**
  * CustomIndicator
  * <pre>
@@ -26,106 +24,79 @@ public class CustomIndicator extends View {
 
   public CustomIndicator(Context context) {
     super(context);
+    this.context = context;
   }
 
   public CustomIndicator(Context context, @Nullable AttributeSet attrs) {
     super(context, attrs);
+    this.context = context;
   }
 
   public CustomIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
     super(context, attrs, defStyleAttr);
+    this.context = context;
   }
 
   private Context context;
+  private RecyclerView recyclerView;
   private int activeColor;
   private int inActiveColor;
   private int bottomOffset;
+  private int activePosition;
 
   private static final float DP = Resources.getSystem().getDisplayMetrics().density;
-
-  /**
-   * Height of the space the indicator takes up at the bottom of the view.
-   */
   private final int mIndicatorHeight = (int) (DP * 16);
-
-  /**
-   * Indicator stroke width.
-   */
   private final float mIndicatorStrokeWidth = DP * 2;
-
-  /**
-   * Indicator width.
-   */
   private final float mIndicatorItemLength = DP * 4;
-  /**
-   * Padding between indicators.
-   */
   private final float mIndicatorItemPadding = DP * 8;
-
-
-  /**
-   * Some more natural animation interpolation
-   */
-
   private final Paint mPaint = new Paint();
 
-  private int itemCount = -1;
-
-  private int index = -1;
-
-  private IndexScrollListener indexScrollListener;
-
-  public void onChangedIndex(int itemCount, int index) {
-    if (this.itemCount != itemCount || this.index != index) {
-      this.itemCount = itemCount;
-      this.index = index;
-
-      invalidate();
-    }
+  public void setIndicatorSetting(RecyclerView recyclerview, int inActiveColor, int activeColor, int bottomOffset) {
+      this.recyclerView = recyclerview;
+      this.inActiveColor = inActiveColor;
+      this.activeColor = activeColor;
+      this.bottomOffset = bottomOffset;
+      mPaint.setStrokeCap(Paint.Cap.ROUND);
+      mPaint.setStrokeWidth(mIndicatorStrokeWidth);
+      mPaint.setStyle(Paint.Style.FILL);
   }
 
-  public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
+  public void onChangedIndex(int firstVisibleItemPosition) {
+    this.activePosition = firstVisibleItemPosition;
+    invalidate();
+  }
 
-    if (null == parent || null == parent.getAdapter()) {
+  @Override
+  protected void onDraw(Canvas canvas) {
+    if (null == recyclerView || null == recyclerView.getAdapter()) {
       return;
     }
-
-    int itemCount = parent.getAdapter().getItemCount();
-
+    int itemCount = recyclerView.getAdapter().getItemCount();
     float totalLength = mIndicatorItemLength * itemCount;
     float paddingBetweenItems = Math.max(0, itemCount - 1) * mIndicatorItemPadding;
     float indicatorTotalWidth = totalLength + paddingBetweenItems;
-    float indicatorStartX = (parent.getWidth() - indicatorTotalWidth) / 2F;
-    float indicatorPosY = parent.getHeight() - mIndicatorHeight / 2F;
+    float indicatorStartX = (recyclerView.getWidth() - indicatorTotalWidth) / 2F;
+    float indicatorPosY = getHeight() - 38F * DP;
 
     drawInactiveIndicators(canvas, indicatorStartX, indicatorPosY, itemCount);
-
-    // find active page (which should be highlighted)
-    LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
-    int activePosition = IndexScrollListener.getCurrentIndex(layoutManager);
-//    Log.e("APP#  MainBannerViewItemDotIndicator | onDrawOver", "| activePosition: " + activePosition);
-
     if (activePosition == RecyclerView.NO_POSITION) {
       return;
     }
-
     drawHighlights(canvas, indicatorStartX, indicatorPosY, activePosition, itemCount);
-
   }
 
   private void drawInactiveIndicators(Canvas c, float indicatorStartX, float indicatorPosY, int itemCount) {
     mPaint.setColor(context.getResources().getColor(inActiveColor));
-
-    // width of item indicator including padding
     final float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
 
     float start = indicatorStartX;
     for (int i = 0; i < itemCount; i++) {
       // itemCount 1은 안띄움
       if (itemCount != 1) {
-        c.drawCircle(start, indicatorPosY, mIndicatorItemLength / 2F, mPaint);
+        c.drawCircle(start, indicatorPosY, mIndicatorItemLength / 2, mPaint);
         start += itemWidth;
       }
+      Log.e("APP#  CustomIndicator | drawInactiveIndicators", "| drawInactiveIndicators " + itemCount);
     }
   }
 
@@ -133,16 +104,16 @@ public class CustomIndicator extends View {
                               int highlightPosition, int itemCount) {
     mPaint.setColor(context.getResources().getColor(activeColor));
 
-    // width of item indicator including padding
-    final float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
+    final float itemWidth = mIndicatorItemLength  + mIndicatorItemPadding;
 
     float start = indicatorStartX;
     for (int i = 0; i < itemCount; i++) {
       if (itemCount != 1 && i == highlightPosition) {
-        canvas.drawCircle(start, indicatorPosY, mIndicatorItemLength / 2F, mPaint);
+        canvas.drawCircle(start, indicatorPosY, mIndicatorItemLength /2, mPaint);
       }
       start += itemWidth;
     }
-
+    Log.e("APP#  CustomIndicator | drawHighlights", "| highlightPosition" + highlightPosition );
   }
+
 }

+ 7 - 4
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/event/EventFragment.java

@@ -19,7 +19,6 @@ import kr.co.zumo.app.lifeplus.model.BlankModel;
 import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.IEventListener;
-import kr.co.zumo.app.lifeplus.view.custom.category.banner.MainBannerViewItemDotIndicator;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
 
 /**
@@ -66,18 +65,22 @@ public class EventFragment extends FragmentBase<EventPresenter> implements IEven
     SnapHelper snapHelper = new PagerSnapHelper();
     snapHelper.attachToRecyclerView(recyclerViewEvent);
 
-    recyclerViewEvent.addItemDecoration(new MainBannerViewItemDotIndicator(getActivity(), R.color.C19000000, R.color.C000000, ResourceUtil.dpToPx(38)));
 
     layoutMyEvent = findViewById(R.id.layout_my_event);
+
     customIndicator = findViewById(R.id.custom_indicator);
+    customIndicator.setIndicatorSetting(recyclerViewEvent, R.color.C19000000, R.color.C000000, ResourceUtil.dpToPx(0));
+
     recyclerViewEvent.addOnScrollListener(new RecyclerView.OnScrollListener() {
       @Override
       public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
-        int currentIndex= layoutManager.findFirstVisibleItemPosition();
+        int currentIndex = layoutManager.findFirstVisibleItemPosition();
         // TODO: 마지막 인덱스 일때 MY 이벤트 버튼 보임
-        layoutMyEvent.setVisibility(currentIndex == 4? View.VISIBLE : View.GONE);
+        customIndicator.onChangedIndex(currentIndex);
+        layoutMyEvent.setVisibility(currentIndex == 4 ? View.VISIBLE : View.GONE);
       }
     });
+
   }
 
   @Override

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

@@ -23,8 +23,7 @@
   <kr.co.zumo.app.lifeplus.view.screen.event.CustomIndicator
     android:id="@+id/custom_indicator"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_marginTop="30dp"
+    android:layout_height="match_parent"
     app:layout_constraintEnd_toEndOf="parent"
     app:layout_constraintStart_toStartOf="parent"
     app:layout_constraintTop_toBottomOf="@+id/recycler_view_event"