diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java index 786bf6ca4..b330ff4cc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java @@ -71,7 +71,7 @@ public class AccountTimelineFragment extends StatusListFragment{ @Override public void onViewCreated(View view, Bundle savedInstanceState){ super.onViewCreated(view, savedInstanceState); - fab = ((ProfileFragment) getParentFragment()).getFab(); +// fab = ((ProfileFragment) getParentFragment()).getFab(); } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 3bb892285..acd61a03b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -74,8 +74,7 @@ public abstract class BaseStatusListFragment exten protected String accountID; protected PhotoViewer currentPhotoViewer; protected ImageButton fab; - protected boolean isScrollingUp = false; -// protected boolean isFirstLaunch = true; + protected int scrollDiff = 0; protected HashMap knownAccounts=new HashMap<>(); protected HashMap relationships=new HashMap<>(); protected Rect tmpRect=new Rect(); @@ -285,22 +284,21 @@ public abstract class BaseStatusListFragment exten public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy){ if(currentPhotoViewer!=null) currentPhotoViewer.offsetView(-dx, -dy); + if (fab!=null && GlobalUserPreferences.disableFabAutoHide) { - if (dy > 0 /*&& !isFirstLaunch*/) { - if (isScrollingUp /*&& !isFirstLaunch*/) { - fab.setVisibility(View.INVISIBLE); - TranslateAnimation animate = new TranslateAnimation( - 0, - 0, - 0, - fab.getHeight() * 2); - animate.setDuration(300); - animate.setFillAfter(true); - fab.startAnimation(animate); - isScrollingUp = false; - } - } else { - if (!isScrollingUp) { + if (dy > 0 && fab.getVisibility() == View.VISIBLE) { + TranslateAnimation animate = new TranslateAnimation( + 0, + 0, + 0, + fab.getHeight() * 2); + animate.setDuration(300); + animate.setFillAfter(true); + fab.startAnimation(animate); + fab.setVisibility(View.INVISIBLE); + scrollDiff = 0; + } else if (dy < 0 && fab.getVisibility() != View.VISIBLE) { + if (scrollDiff > 400) { fab.setVisibility(View.VISIBLE); TranslateAnimation animate = new TranslateAnimation( 0, @@ -310,7 +308,9 @@ public abstract class BaseStatusListFragment exten animate.setDuration(300); animate.setFillAfter(true); fab.startAnimation(animate); - isScrollingUp = true; + scrollDiff = 0; + } else { + scrollDiff += Math.abs(dy); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index ef9721d51..834407b39 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -463,6 +463,29 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList }); scrollView.setOnScrollChangeListener(this::onScrollChanged); + scrollView.setNestedScrollListener((target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed) -> { + if (dyConsumed > 0) { + fab.setVisibility(View.INVISIBLE); + TranslateAnimation animate = new TranslateAnimation( + 0, + 0, + 0, + fab.getHeight() * 2); + animate.setDuration(300); + animate.setFillAfter(true); + fab.startAnimation(animate); + } else { + fab.setVisibility(View.VISIBLE); + TranslateAnimation animate = new TranslateAnimation( + 0, + 0, + fab.getHeight() * 2, + 0); + animate.setDuration(300); + animate.setFillAfter(true); + fab.startAnimation(animate); + } + }); titleTransY=getToolbar().getLayoutParams().height; if(toolbarTitleView!=null){ toolbarTitleView.setTranslationY(titleTransY); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/views/NestedRecyclerScrollView.java b/mastodon/src/main/java/org/joinmastodon/android/ui/views/NestedRecyclerScrollView.java index 8bad60d6e..9f7259539 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/views/NestedRecyclerScrollView.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/views/NestedRecyclerScrollView.java @@ -10,7 +10,12 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; public class NestedRecyclerScrollView extends CustomScrollView{ + + public interface NestedScrollListener{ + public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed); + } private Supplier scrollableChildSupplier; + private NestedScrollListener nestedScrollListener; public NestedRecyclerScrollView(Context context){ super(context); @@ -24,6 +29,18 @@ public class NestedRecyclerScrollView extends CustomScrollView{ super(context, attrs, defStyleAttr); } + @Override + public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { + super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); + if (nestedScrollListener != null) { + nestedScrollListener.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); + } + } + + public void setNestedScrollListener(NestedScrollListener listener) { + this.nestedScrollListener = listener; + } + @Override public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { final RecyclerView rv = (RecyclerView) target;