[Android] Fix fastscroller stuck on top and bottom

Geoffrey Métais git at videolan.org
Wed Aug 8 18:18:33 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug  8 18:17:30 2018 +0200| [390a389885e9049cb79c3cef1ee64636db248ec9] | committer: Geoffrey Métais

Fix fastscroller stuck on top and bottom

Fix #382

> https://code.videolan.org/videolan/vlc-android/commit/390a389885e9049cb79c3cef1ee64636db248ec9
---

 vlc-android/res/layout/audio_browser.xml             |  3 ++-
 .../src/org/videolan/vlc/gui/view/FastScroller.java  | 20 ++++++++------------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/vlc-android/res/layout/audio_browser.xml b/vlc-android/res/layout/audio_browser.xml
index f3f184231..7b60dcec1 100644
--- a/vlc-android/res/layout/audio_browser.xml
+++ b/vlc-android/res/layout/audio_browser.xml
@@ -64,7 +64,8 @@
         android:id="@+id/songs_fast_scroller"
         android:layout_width="wrap_content"
         android:layout_height="0dp"
-        android:layout_marginTop="@dimen/default_margin"
+        android:layout_marginTop="16dp"
+        android:layout_marginBottom="16dp"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintBottom_toBottomOf="@+id/swipeLayout"
         app:layout_constraintTop_toTopOf="@+id/swipeLayout"
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.java b/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.java
index ff2936305..a1a518b4c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.java
+++ b/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.java
@@ -27,6 +27,7 @@ import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
+import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
 import android.content.Context;
 import android.os.Build;
@@ -58,7 +59,6 @@ public class FastScroller extends LinearLayout {
     private static final int HANDLE_ANIMATION_DURATION = 100;
     private static final int HANDLE_HIDE_DELAY = 1000;
     private static final int SCROLLER_HIDE_DELAY = 3000;
-    private static final int TRACK_SNAP_RANGE = 5;
 
     private static final int HIDE_HANDLE = 0;
     private static final int HIDE_SCROLLER = 1;
@@ -196,14 +196,7 @@ public class FastScroller extends LinearLayout {
 
     private void setRecyclerViewPosition(float y) {
         if (mRecyclerView != null) {
-            float proportion;
-            if (handle.getY() == 0) {
-                proportion = 0f;
-            } else if (handle.getY() + handle.getHeight() >= mHeight - TRACK_SNAP_RANGE) {
-                proportion = 1f;
-            } else {
-                proportion = y / (float) mHeight;
-            }
+            final float proportion = y / (float) mHeight;
             final int targetPos = getValueInRange(0, mItemCount - 1, Math.round(proportion * (float) mItemCount));
             if (targetPos == mCurrentPosition) return;
             mCurrentPosition = targetPos;
@@ -248,18 +241,21 @@ public class FastScroller extends LinearLayout {
         }
     }
 
+    @SuppressLint("HandlerLeak")
     private final Handler mHandler = new FastScrollerHandler(this) {
         @Override
         public void handleMessage(Message msg) {
+            final FastScroller fs = getOwner();
+            if (fs == null) return;
             switch (msg.what) {
                 case HIDE_HANDLE:
-                    hideBubble();
+                    fs.hideBubble();
                     break;
                 case HIDE_SCROLLER:
-                    FastScroller.this.setVisibility(INVISIBLE);
+                    fs.setVisibility(INVISIBLE);
                     break;
                 case SHOW_SCROLLER:
-                    FastScroller.this.setVisibility(VISIBLE);
+                    fs.setVisibility(VISIBLE);
                     mHandler.removeMessages(HIDE_SCROLLER);
                     mHandler.sendEmptyMessageDelayed(HIDE_SCROLLER, SCROLLER_HIDE_DELAY);
                     break;



More information about the Android mailing list