- if (mActivity == null) return;
- if (swiper == null) return;
- swiper.setRefreshing(isRunning);
+ if (getActivity() == null)
+ return;
+ if (refreshLayout == null)
+ return;
+ refreshLayout.setRefreshing(isRunning);
+ }
+ protected void manageFabOnScroll() {
+ final MainActivity mainActivity = getMainActivity();
+ int triggerPixels = DimensionUtils.dp2px(mainActivity, 10f);
+ root.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
+ private float upAnchor = -1;
+ private float lastY;
+ @Override
+ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+ switch (e.getActionMasked()) {
+ case MotionEvent.ACTION_DOWN:
+ lastY = upAnchor = e.getAxisValue(MotionEvent.AXIS_Y);
+ break;
+ case MotionEvent.ACTION_MOVE:
+ final float currentY = e.getAxisValue(MotionEvent.AXIS_Y);
+ if (currentY > lastY) {
+ // swipe down
+ upAnchor = lastY;
+
+ mainActivity.fabShouldShow();
+ }
+ else {
+ // swipe up
+ if (currentY < upAnchor - triggerPixels)
+ mainActivity.fabHide();
+ }
+
+ lastY = currentY;
+
+ break;
+ }
+ return false;
+ }
+ @Override
+ public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+ }
+ @Override
+ public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
+ }
+ });