From 8e3586328c867c135ff455c19a6f751b89ae0197 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 18 Jul 2018 02:31:52 +0200 Subject: [PATCH] fab: use auto calculated fling threshold Signed-off-by: Jason A. Donenfeld --- .../widget/CustomRecyclerViewScrollListener.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java b/app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java index 2660179f..dfdfd513 100644 --- a/app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java +++ b/app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java @@ -8,21 +8,26 @@ package com.wireguard.android.widget; import android.support.v7.widget.RecyclerView; +import com.wireguard.android.R; + public abstract class CustomRecyclerViewScrollListener extends RecyclerView.OnScrollListener { private int scrollDist; private boolean isVisible = true; - private static final float FLING_THRESHOLD = 25; + private static int flingThreshold; @Override public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) { super.onScrolled(recyclerView, dx, dy); - if (isVisible && scrollDist > FLING_THRESHOLD) { + if (flingThreshold == 0) + flingThreshold = recyclerView.getResources().getDimensionPixelSize(R.dimen.design_fab_size_normal) / 2; + + if (isVisible && scrollDist >= flingThreshold) { hide(); scrollDist = 0; isVisible = false; - } else if (!isVisible && scrollDist < -FLING_THRESHOLD) { + } else if (!isVisible && scrollDist <= -flingThreshold) { show(); scrollDist = 0; isVisible = true;