|
|
@@ -22,6 +22,7 @@ import kr.co.zumo.app.R;
|
|
|
import kr.co.zumo.app.lifeplus.bean.api.ContentsDetailImageBean;
|
|
|
import kr.co.zumo.app.lifeplus.util.StringUtil;
|
|
|
import kr.co.zumo.app.lifeplus.view.IEventListener;
|
|
|
+import kr.co.zumo.app.lifeplus.view.IndexScrollListener;
|
|
|
|
|
|
/**
|
|
|
* CustomListicleImageView
|
|
|
@@ -88,84 +89,16 @@ public class CustomListicleImageView extends ConstraintLayout {
|
|
|
snapHelper.attachToRecyclerView(recyclerView);
|
|
|
}
|
|
|
|
|
|
- int oldX;
|
|
|
- int oldY;
|
|
|
-
|
|
|
- private static final String DIRECTION_NONE = "none";
|
|
|
- private static final String DIRECTION_UP = "up";
|
|
|
- private static final String DIRECTION_DOWN = "down";
|
|
|
- private static final String DIRECTION_RIGHT = "right";
|
|
|
- private static final String DIRECTION_LEFT = "left";
|
|
|
-
|
|
|
- private String getDirection(MotionEvent e) {
|
|
|
- String direction = DIRECTION_NONE;
|
|
|
- int action = e.getAction();
|
|
|
- switch (action) {
|
|
|
- case MotionEvent.ACTION_DOWN:
|
|
|
- oldX = (int) e.getX();
|
|
|
- oldY = (int) e.getY();
|
|
|
- break;
|
|
|
- case MotionEvent.ACTION_MOVE:
|
|
|
- int newX = (int) e.getX();
|
|
|
- int newY = (int) e.getY();
|
|
|
-
|
|
|
- int dx = oldX - newX;
|
|
|
- int dy = oldY - newY;
|
|
|
-
|
|
|
- // Use dx and dy to determine the direction of the move
|
|
|
- if (Math.abs(dx) > Math.abs(dy)) {
|
|
|
- if (dx > 0) {
|
|
|
- direction = DIRECTION_RIGHT;
|
|
|
- }
|
|
|
- else {
|
|
|
- direction = DIRECTION_LEFT;
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- if (dy > 0) {
|
|
|
- direction = DIRECTION_DOWN;
|
|
|
- }
|
|
|
- else {
|
|
|
- direction = DIRECTION_UP;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- // nothing
|
|
|
- break;
|
|
|
- }
|
|
|
- return direction;
|
|
|
- }
|
|
|
|
|
|
private RecyclerView.OnItemTouchListener touchEventListener = new RecyclerView.OnItemTouchListener() {
|
|
|
@Override
|
|
|
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
|
|
|
- String direction = getDirection(e);
|
|
|
-// Log.w("APP# CustomListicleImageView | onInterceptTouchEvent", "|" + "direction: " + direction);
|
|
|
-
|
|
|
int action = e.getAction();
|
|
|
switch (action) {
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
-
|
|
|
- boolean intercept = true;
|
|
|
- /**
|
|
|
- * index 가 0 일 때 좌-> 우 드래그 시 false, index 가 끝일 때 좌<-우 드래그 시 false => 미사용
|
|
|
- */
|
|
|
-
|
|
|
-// if (currentIndex == 0) {
|
|
|
-// if (direction.equals(DIRECTION_LEFT)) {
|
|
|
-// intercept = false;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (currentIndex == contentsLength - 1) {
|
|
|
-// if (direction.equals(DIRECTION_RIGHT)) {
|
|
|
-// intercept = false;
|
|
|
-// }
|
|
|
-// }
|
|
|
- rv.getParent().requestDisallowInterceptTouchEvent(intercept);
|
|
|
+ rv.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -180,15 +113,7 @@ public class CustomListicleImageView extends ConstraintLayout {
|
|
|
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {}
|
|
|
};
|
|
|
|
|
|
- private RecyclerView.OnScrollListener scrollEventListener = new RecyclerView.OnScrollListener() {
|
|
|
- @Override
|
|
|
- public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
- index = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
|
|
|
- currentIndex = index % contentsLength;
|
|
|
- textViewCurrentPage.setText(String.valueOf(currentIndex + 1));
|
|
|
- textViewCurrentPage.setTypeface(null, Typeface.BOLD);
|
|
|
- }
|
|
|
- };
|
|
|
+ private RecyclerView.OnScrollListener scrollEventListener;
|
|
|
|
|
|
public void init(Context context, int index, String title, String subTitle, List<ContentsDetailImageBean> contentsDetailImageBeans, IEventListener listener) {
|
|
|
|
|
|
@@ -242,10 +167,16 @@ public class CustomListicleImageView extends ConstraintLayout {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
- recyclerView.setAdapter(adapter);
|
|
|
- recyclerView.addOnItemTouchListener(touchEventListener);
|
|
|
+ scrollEventListener = new IndexScrollListener(linearLayoutManager, idx -> {
|
|
|
+ CustomListicleImageView.this.index = idx;
|
|
|
+ currentIndex = idx % contentsLength;
|
|
|
+ textViewCurrentPage.setText(String.valueOf(currentIndex + 1));
|
|
|
+ textViewCurrentPage.setTypeface(null, Typeface.BOLD);
|
|
|
+ });
|
|
|
recyclerView.addOnScrollListener(scrollEventListener);
|
|
|
+ recyclerView.addOnItemTouchListener(touchEventListener);
|
|
|
recyclerView.scrollToPosition(contentsLength * 10000);
|
|
|
+ recyclerView.setAdapter(adapter);
|
|
|
imageViewPrePage.setOnClickListener(view -> {onClickPrePage();});
|
|
|
imageViewNextPage.setOnClickListener(view -> {onClickNextPage();});
|
|
|
}
|