diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-18 02:31:52 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-18 02:32:05 +0200 |
commit | 8e3586328c867c135ff455c19a6f751b89ae0197 (patch) | |
tree | c697f213adac5b92905a618c0426dd3050751f1c /app/src | |
parent | f315654d404959bee2b15744d870a6bdf2fd0472 (diff) |
fab: use auto calculated fling threshold
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java | 11 |
1 files 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; |