瀏覽代碼

Merge branch 'develop' of https://github.com/swict/LifePlusAndroid into develop

Hasemi 7 年之前
父節點
當前提交
ae8d6c5f14

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

@@ -22,4 +22,6 @@ public interface IMainView extends IView {
   void drawContents(ArrayList<MainContentsBean> data);
 
   void render();
+
+  void scrollToPosition(int index);
 }

+ 36 - 8
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsCategoryHolder.java

@@ -8,6 +8,7 @@ import android.content.Context;
 import android.os.Parcelable;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
+import android.view.MotionEvent;
 import android.view.View;
 import android.widget.TextView;
 
@@ -125,18 +126,45 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
       public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
         if (null != adapter) {
           adapter.onScrolledHorizontal(recyclerView, dx, dy);
-          /**
-           * 스크롤 시킬 조건
-           * - 1번 카테고리가 화면에서 벗어나 있을 때, (아래 쪽이 잘렸을 때)
-           */
-          if (index == 1 && dx != 0) {
-//            Log.i("APP# MainContentsCategoryHolder | onScrolledVertical", "|" + "---------------------------------------" + dx + ", " + dy);
-//            listener.onEvent(new Event.Builder(Event.SCROLL).build());
-          }
         }
       }
     });
 
+    if (index == 1) {
+      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());
+              }
+              break;
+            default:
+              break;
+          }
+          return false;
+        }
+
+        @Override
+        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
+
+        }
+
+        @Override
+        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
+
+        }
+      });
+    }
+
     Parcelable state = MainModelHelper.getInstance().getInstanceState(this.index);
     recyclerView.getLayoutManager().onRestoreInstanceState(state);
   }

+ 15 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsSnapper.java

@@ -237,6 +237,21 @@ public class MainContentsSnapper extends RecyclerView.OnFlingListener {
 
   }
 
+  public void smoothScrollToPosition(int position) {
+
+    LayoutManager layoutManager = mRecyclerView.getLayoutManager();
+    if (layoutManager == null) {
+      return;
+    }
+
+    SmoothScroller smoothScroller = createScroller(layoutManager);
+    if (smoothScroller == null) {
+      return;
+    }
+    smoothScroller.setTargetPosition(position);
+    layoutManager.startSmoothScroll(smoothScroller);
+  }
+
   /**
    * Creates a scroller to be used in the snapping implementation.
    *

+ 36 - 7
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainFragment.java

@@ -7,11 +7,15 @@ import android.animation.ObjectAnimator;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
+import android.support.v4.view.NestedScrollingParent2;
+import android.support.v4.view.ViewCompat;
+import android.support.v4.view.ViewParentCompat;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.ViewParent;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -44,6 +48,7 @@ public class MainFragment extends FragmentBase<MainPresenter> implements IMainVi
   private RecyclerView contentsRecyclerView;
   private MainContentsAdapter adapter;
   private PageIndicator indicator;
+  private MainContentsSnapper snapper;
 
   private RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() {
     @Override
@@ -92,7 +97,7 @@ public class MainFragment extends FragmentBase<MainPresenter> implements IMainVi
     AnimatorManager.getInstance().add(indicatorAnimator);
 
     if (contentsRecyclerView.getOnFlingListener() == null) {
-      MainContentsSnapper snapper = new MainContentsSnapper(1000, statusBarHeight - ResourceUtil.dpToPx(5) /* 리스트 간격보다 5dp 적다 */);
+      snapper = new MainContentsSnapper(1000, statusBarHeight - ResourceUtil.dpToPx(5) /* 리스트 간격보다 5dp 적다 */);
       snapper.attachToRecyclerView(contentsRecyclerView);
     }
 
@@ -246,6 +251,34 @@ public class MainFragment extends FragmentBase<MainPresenter> implements IMainVi
     findViewById(R.id.button_pin_reset).setEnabled(StringUtil.isEmpty(SuperModel.getInstance().getPreferences().getEncryptedPin()));
   }
 
+  @Override
+  public void scrollToPosition(int index) {
+    if (null != snapper) {
+      snapper.smoothScrollToPosition(index);
+
+      // appbar 를 스크롤 시키기위해서 가상 이벤트를 전송한다.
+//      NestedScrollingChildHelper helper = new NestedScrollingChildHelper(contentsRecyclerView);
+//
+//      helper.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL, ViewCompat.TYPE_NON_TOUCH);
+//      helper.dispatchNestedPreScroll(0, 300, new int[2], new int[2], ViewCompat.TYPE_NON_TOUCH);
+
+      // appbar 를 스크롤 시키기위해서 가상 이벤트를 전송한다.
+      ViewParent p = contentsRecyclerView.getParent();
+      ViewParent layoutCoordinator = null;
+      while (p != null) {
+        if (p instanceof NestedScrollingParent2) {
+          layoutCoordinator = p;
+        }
+        p = p.getParent();
+      }
+
+      if (null != layoutCoordinator) {
+        ViewParentCompat.onStartNestedScroll(layoutCoordinator, contentsRecyclerView, contentsRecyclerView, ViewCompat.SCROLL_AXIS_VERTICAL, ViewCompat.TYPE_NON_TOUCH);
+        ViewParentCompat.onNestedPreScroll(layoutCoordinator, contentsRecyclerView, 0, 300, new int[2], ViewCompat.TYPE_NON_TOUCH);
+      }
+    }
+  }
+
   @Override
   protected MainPresenter definePresenter() {
     return new MainPresenter(getModel(MainModel.class), this);
@@ -259,13 +292,9 @@ public class MainFragment extends FragmentBase<MainPresenter> implements IMainVi
       AnimatorManager.getInstance().start();
 
       adapter = new MainContentsAdapter(getContext(), data, event -> {
-        if (event.getEventId() == Event.SCROLL) {
-          contentsRecyclerView.smoothScrollToPosition(1);
-        }
-        else {
-          presenter.onEvent(event);
-        }
+        presenter.onEvent(event);
       });
+
       contentsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
       contentsRecyclerView.setAdapter(adapter);
     }

+ 35 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainPresenter.java

@@ -5,6 +5,11 @@ package kr.co.zumo.app.lifeplus.view.screen.main;
 
 import android.util.Log;
 
+import java.util.concurrent.TimeUnit;
+
+import io.reactivex.Completable;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.disposables.Disposable;
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.bean.ContentsDeliveryBean;
 import kr.co.zumo.app.lifeplus.bean.api.MainContentsCategoryBean;
@@ -38,6 +43,7 @@ import kr.co.zumo.app.lifeplus.view.screen.category.CategoryID;
  */
 public class MainPresenter extends Presenter<MainModel, IMainView> {
 
+  private Disposable disposable;
   private DialogBase alertDialog;
   private DoubleChecker doubleChecker;
 
@@ -91,6 +97,10 @@ public class MainPresenter extends Presenter<MainModel, IMainView> {
       alertDialog.dispose();
       alertDialog = null;
     }
+    if (null != disposable) {
+      disposable.dispose();
+      disposable = null;
+    }
   }
 
   @Override
@@ -105,6 +115,8 @@ public class MainPresenter extends Presenter<MainModel, IMainView> {
       case Event.SUCCESS:
         // contents loading complete
         doubleChecker.checkSecond();
+
+        setTimer();
         break;
       case Event.COMPLETED:
         if (event.getInteger() == Event.MEMBER_DELETE) {
@@ -130,6 +142,19 @@ public class MainPresenter extends Presenter<MainModel, IMainView> {
     }
   }
 
+  /**
+   * 2초 동안 사용자 입력이 없으면 카테고리 1로 스크롤 시킴.
+   */
+  private void setTimer() {
+    disposable = Completable.timer(2000, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
+      .subscribe(() -> {
+        if (false == isTouched) {
+          // 첫 번째 카테고리로 이동
+          view.scrollToPosition(1);
+        }
+      });
+  }
+
   @Override
   public boolean onBackPressed() {
     /*
@@ -182,6 +207,10 @@ public class MainPresenter extends Presenter<MainModel, IMainView> {
       case Event.MORE:
         gotoCategoryMain(event.getString());
         break;
+      case Event.SCROLL:
+        // 첫 번째 카테고리로 이동
+        view.scrollToPosition(1);
+        break;
 
       case Event.INIT:
         initUser();
@@ -191,6 +220,12 @@ public class MainPresenter extends Presenter<MainModel, IMainView> {
     }
   }
 
+  private boolean isTouched = false;
+
+  public void touch() {
+    isTouched = true;
+  }
+
   private void initUser() {
 
     // 가입하면 설정되는 값들

+ 3 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/my/bookmark/BookMarkListFragment.java

@@ -157,6 +157,7 @@ public class BookMarkListFragment extends FragmentBase<BookMarkListPresenter> im
             OrientationHelper helper = OrientationHelper.createVerticalHelper(layoutManager);
             final int dy = helper.getDecoratedStart(targetView);
 
+            // appbar 를 스크롤 시키기위해서 가상 이벤트를 전송한다.
             ViewParentCompat.onNestedPreScroll(layoutCoordinator, recyclerView, 0, dy, new int[2], ViewCompat.TYPE_NON_TOUCH);
 
             // fixme 0 위치가 미묘하게 다르게 처리된다.
@@ -258,6 +259,8 @@ public class BookMarkListFragment extends FragmentBase<BookMarkListPresenter> im
   public void scrollToAnchor(int itemIndex) {
 
     recyclerView.smoothScrollToPosition(itemIndex);
+
+    // appbar 를 스크롤 시키기위해서 가상 이벤트를 전송한다.
     ViewParentCompat.onStartNestedScroll(layoutCoordinator, recyclerView, recyclerView, ViewCompat.SCROLL_AXIS_VERTICAL, ViewCompat.TYPE_NON_TOUCH);
   }
 }

+ 0 - 31
app/src/main/res/layout/contents_card_detail.xml

@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout
-  xmlns:android="http://schemas.android.com/apk/res/android"
-  xmlns:app="http://schemas.android.com/apk/res-auto"
-  xmlns:tools="http://schemas.android.com/tools"
-  android:layout_width="match_parent"
-  android:layout_height="match_parent">
-
-
-  <ImageView
-    android:id="@+id/image_view_card_listicle_cover"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:scaleType="centerCrop"
-    tools:src="@drawable/mymain_bucket_banner_3"/>
-  <TextView
-    android:id="@+id/text_view_page_number"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:layout_marginEnd="25dp"
-    android:layout_marginBottom="28dp"
-    android:gravity="end"
-    android:lineSpacingExtra="3.5sp"
-    android:textColor="@color/CFFFFFF"
-    android:textSize="12sp"
-    android:textStyle="bold"
-    app:layout_constraintBottom_toBottomOf="parent"
-    app:layout_constraintEnd_toEndOf="parent"
-    tools:text="1 / 5"
-    />
-</android.support.constraint.ConstraintLayout>

+ 1 - 0
app/src/main/res/layout/fragment_main.xml

@@ -3,6 +3,7 @@
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
+  android:id="@+id/layout_coordinator"
   android:layout_width="match_parent"
   android:layout_height="match_parent">