package com.gh4a.widget;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;

import com.gh4a.R;

@SuppressWarnings("unused")
public class ScrollAwareFloatingActionButtonBehavior extends FloatingActionButton.Behavior {
    public ScrollAwareFloatingActionButtonBehavior(Context context, AttributeSet attrs) {
        super();
    }

    @Override
    public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout,
            FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {
        if (target.getTag(R.id.FloatingActionButtonScrollEnabled) == null) {
            return super.onStartNestedScroll(coordinatorLayout, child,
                    directTargetChild, target, nestedScrollAxes);
        }
        return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
    }

    @Override
    public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child,
            View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
                dyUnconsumed);

        if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
            child.hide();
        } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
            child.show();
        }
    }
}

@@ -51,16 +51,59 @@
 ontext;%0A
+import android.support.annotation.NonNull;%0A
 import a
@@ -454,16 +454,348 @@
 avior %7B%0A
+    private FloatingActionButton.OnVisibilityChangedListener mVisibilityChangedListener =%0A            new FloatingActionButton.OnVisibilityChangedListener() %7B%0A        @Override%0A        public void onHidden(FloatingActionButton fab) %7B%0A            super.onHidden(fab);%0A            fab.setVisibility(View.INVISIBLE);%0A        %7D%0A    %7D;%0A%0A
     publ
@@ -890,16 +890,30 @@
   super(
+context, attrs
 );%0A    %7D
@@ -959,32 +959,41 @@
 artNestedScroll(
+@NonNull 
 CoordinatorLayou
@@ -1025,16 +1025,25 @@
         
+@NonNull 
 Floating
@@ -1057,24 +1057,33 @@
 utton child,
+ @NonNull
  View direct
@@ -1094,16 +1094,37 @@
 etChild,
+%0A            @NonNull
  View ta
@@ -1133,32 +1133,30 @@
 et, int 
-nestedScrollAxes
+axes, int type
 ) %7B%0A    
@@ -1302,28 +1302,8 @@
 ild,
-%0A                   
  dir
@@ -1325,33 +1325,47 @@
  target,
- nestedScrollAxes
+%0A                    axes, type
 );%0A     
@@ -1388,21 +1388,9 @@
 urn 
-nestedScrollA
+a
 xes 
@@ -1477,16 +1477,25 @@
 dScroll(
+@NonNull 
 Coordina
@@ -1522,16 +1522,37 @@
 rLayout,
+%0A            @NonNull
  Floatin
@@ -1571,28 +1571,25 @@
 n child,
-%0A           
+ @NonNull
  View ta
@@ -1605,24 +1605,36 @@
  dxConsumed,
+%0A           
  int dyConsu
@@ -1672,16 +1672,26 @@
 consumed
+, int type
 ) %7B%0A    
@@ -1815,16 +1815,22 @@
 consumed
+, type
 );%0A%0A    
@@ -1919,16 +1919,42 @@
 ld.hide(
+mVisibilityChangedListener
 );%0A     

Fix FAB not re-appearing when scrolling back