1717import android .support .v4 .view .PagerAdapterWrapper ;
1818import android .support .v4 .view .ScrollingView ;
1919import android .support .v4 .view .ViewPager ;
20+ import android .support .v4 .widget .NestedScrollView ;
2021import android .support .v4 .widget .Space ;
2122import android .support .v7 .widget .LinearLayoutManager ;
2223import android .support .v7 .widget .RecyclerView ;
@@ -303,6 +304,9 @@ public void setupComponent(RefreshKernel kernel, View fixedHeader, View fixedFoo
303304 if (mScrollableView instanceof AbsListView ) {
304305 AbsListViewScrollComponent component = new AbsListViewScrollComponent (kernel );
305306 component .attach (((AbsListView ) mScrollableView ));
307+ } else if (mScrollableView instanceof NestedScrollView ) {
308+ NestedScrollViewScrollComponent component = new NestedScrollViewScrollComponent (kernel );
309+ component .attach ((NestedScrollView ) mScrollableView );
306310 } else if (Build .VERSION .SDK_INT >= 23 && mScrollableView != null ) {
307311 mScrollableView .setOnScrollChangeListener (new Api23ViewScrollComponent (kernel ));
308312 }
@@ -434,7 +438,7 @@ public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int
434438// System.out.println("ValueAnimator - " + (lastTime - lastTimeOld) + " - " + velocity+"("+(lastOldScrollY - oldScrollY)+")");
435439 kernel .animSpinnerBounce (Math .min (velocity , mHeaderHeight ));
436440 } else if (oldScrollY < scrollY && mMotionEvent == null && overScroll && layout .isEnableLoadmore ()) {
437- if (lastTime - lastTimeOld > 1000 && !ScrollBoundaryUtil .canScrollDown (mScrollableView )) {
441+ if (lastTime - lastTimeOld > 1000 && !ScrollBoundaryUtil .canScrollDown (v )) {
438442 final int velocity = (lastOldScrollY - oldScrollY ) * 16000 / (int )((lastTime - lastTimeOld )/1000f );
439443// System.out.println("ValueAnimator - " + (lastTime - lastTimeOld) + " - " + velocity+"("+(lastOldScrollY - oldScrollY)+")");
440444 kernel .animSpinnerBounce (Math .max (velocity , -mFooterHeight ));
@@ -447,6 +451,48 @@ public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int
447451 }
448452 }
449453
454+ private class NestedScrollViewScrollComponent implements NestedScrollView .OnScrollChangeListener {
455+ long lastTime = 0 ;
456+ long lastTimeOld = 0 ;
457+ int lastScrollY = 0 ;
458+ int lastOldScrollY = 0 ;
459+ RefreshKernel kernel ;
460+
461+ NestedScrollViewScrollComponent (RefreshKernel kernel ) {
462+ this .kernel = kernel ;
463+ }
464+
465+ @ Override
466+ public void onScrollChange (NestedScrollView scrollView , int scrollX , int scrollY , int oldScrollX , int oldScrollY ) {
467+ if (lastScrollY == scrollY && lastOldScrollY == oldScrollY ) {
468+ return ;
469+ }
470+ RefreshLayout layout = kernel .getRefreshLayout ();
471+ boolean overScroll = layout .isEnableOverScrollBounce () || layout .isRefreshing () || layout .isLoading ();
472+ if (scrollY <= 0 && oldScrollY > 0 && mMotionEvent == null && lastTime - lastTimeOld > 1000 && overScroll && layout .isEnableRefresh ()) {
473+ final int velocity = (lastOldScrollY - oldScrollY ) * 16000 / (int )((lastTime - lastTimeOld )/1000f );
474+ kernel .animSpinnerBounce (Math .min (velocity , mHeaderHeight ));
475+ } else if (oldScrollY < scrollY && mMotionEvent == null && layout .isEnableLoadmore ()) {
476+ if (!layout .isLoadmoreFinished () && layout .isEnableAutoLoadmore ()
477+ && layout .getState () == RefreshState .None
478+ && !ScrollBoundaryUtil .canScrollDown (scrollView )) {
479+ kernel .getRefreshLayout ().autoLoadmore (0 , 1 );
480+ } else if (overScroll && lastTime - lastTimeOld > 1000 && !ScrollBoundaryUtil .canScrollDown (mScrollableView )) {
481+ final int velocity = (lastOldScrollY - oldScrollY ) * 16000 / (int )((lastTime - lastTimeOld )/1000f );
482+ kernel .animSpinnerBounce (Math .max (velocity , -mFooterHeight ));
483+ }
484+ }
485+ lastScrollY = scrollY ;
486+ lastOldScrollY = oldScrollY ;
487+ lastTimeOld = lastTime ;
488+ lastTime = System .nanoTime ();
489+ }
490+
491+ void attach (NestedScrollView scrollView ) {
492+ scrollView .setOnScrollChangeListener (this );
493+ }
494+ }
495+
450496 private class AbsListViewScrollComponent implements AbsListView .OnScrollListener {
451497
452498 int scrollY ;
@@ -483,8 +529,9 @@ public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleI
483529 }
484530 } else if (dy < 0 ) {
485531 int lastVisiblePosition = absListView .getLastVisiblePosition ();
486- if (lastVisiblePosition == totalItemCount - 1 && lastVisiblePosition > 0 ) {
487- if (layout .isEnableLoadmore () && !layout .isLoadmoreFinished () && layout .isEnableAutoLoadmore ()
532+ if (lastVisiblePosition == totalItemCount - 1 && lastVisiblePosition > 0
533+ && layout .isEnableLoadmore ()) {
534+ if (!layout .isLoadmoreFinished () && layout .isEnableAutoLoadmore ()
488535 && layout .getState () == RefreshState .None
489536 && !ScrollBoundaryUtil .canScrollDown (absListView )) {
490537 kernel .getRefreshLayout ().autoLoadmore (0 , 1 );
0 commit comments