|
|
@@ -134,22 +134,23 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
|
|
|
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
|
|
|
@Override
|
|
|
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
|
|
|
+
|
|
|
int action = e.getAction();
|
|
|
switch (action) {
|
|
|
-// case MotionEvent.ACTION_MOVE:
|
|
|
-// case MotionEvent.ACTION_DOWN:
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
/**
|
|
|
* 스크롤 시킬 조건
|
|
|
* - 1번 카테고리가 화면에서 벗어나 있을 때, (아래 쪽이 잘렸을 때)
|
|
|
*/
|
|
|
- if (true) {
|
|
|
- listener.onEvent(new Event.Builder(Event.SCROLL).build());
|
|
|
+ if (DIRECTION_LEFT.equals(direction) || DIRECTION_RIGHT.equals(direction)) {
|
|
|
+ listener.onEvent(new Event.Builder(Event.SCROLL).index(index).build());
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
+ direction = getDirection(e);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -169,6 +170,56 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
|
|
|
recyclerView.getLayoutManager().onRestoreInstanceState(state);
|
|
|
}
|
|
|
|
|
|
+ int oldX;
|
|
|
+ int oldY;
|
|
|
+ String direction;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void dispose() {
|
|
|
if (null != adapter) {
|