[Android] Fix fast scroller visibility and threshold calculation

Nicolas Pomepuy git at videolan.org
Fri Sep 2 06:42:29 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug 30 14:34:01 2022 +0200| [d83a24c22c42e24967a507d8134cdaee628b68c6] | committer: Nicolas Pomepuy

Fix fast scroller visibility and threshold calculation

Fixes #2658

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

 application/vlc-android/res/layout/playlists_fragment.xml |  5 ++---
 .../src/org/videolan/vlc/gui/PlaylistFragment.kt          |  2 +-
 .../src/org/videolan/vlc/gui/view/FastScroller.kt         | 15 ++++++++-------
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/application/vlc-android/res/layout/playlists_fragment.xml b/application/vlc-android/res/layout/playlists_fragment.xml
index b62d479e6..5a521b079 100644
--- a/application/vlc-android/res/layout/playlists_fragment.xml
+++ b/application/vlc-android/res/layout/playlists_fragment.xml
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:app="http://schemas.android.com/apk/res-auto"
-        xmlns:tools="http://schemas.android.com/tools">
+        xmlns:app="http://schemas.android.com/apk/res-auto">
 
     <androidx.constraintlayout.widget.ConstraintLayout
             android:layout_width="match_parent"
@@ -35,7 +34,7 @@
         </org.videolan.vlc.gui.view.SwipeRefreshLayout>
 
         <org.videolan.vlc.gui.view.FastScroller
-                android:id="@+id/songs_fast_scroller"
+                android:id="@+id/songs_fast_scroller_playlist"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
                 android:layout_alignParentEnd="true"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index 47c7370e2..f5c0dadf6 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -97,7 +97,7 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
         setupLayoutManager()
 
         playlists.adapter = playlistAdapter
-        fastScroller = view.rootView.findViewById(R.id.songs_fast_scroller) as FastScroller
+        fastScroller = view.rootView.findViewById(R.id.songs_fast_scroller_playlist) as FastScroller
         fastScroller.attachToCoordinator(view.rootView.findViewById(R.id.appbar) as AppBarLayout, view.rootView.findViewById(R.id.coordinator) as CoordinatorLayout, view.rootView.findViewById(R.id.fab) as FloatingActionButton)
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt
index 94808ea70..c3f066f85 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt
@@ -43,15 +43,16 @@ import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.google.android.material.appbar.AppBarLayout
 import com.google.android.material.floatingactionbutton.FloatingActionButton
-import kotlinx.coroutines.*
+import kotlinx.coroutines.ObsoleteCoroutinesApi
 import kotlinx.coroutines.channels.Channel
 import kotlinx.coroutines.channels.actor
+import kotlinx.coroutines.delay
 import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.resources.util.HeadersIndex
+import org.videolan.tools.WeakHandler
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
-import org.videolan.resources.util.HeadersIndex
 import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
-import org.videolan.tools.WeakHandler
 import org.videolan.vlc.util.scope
 import java.util.concurrent.atomic.AtomicBoolean
 import kotlin.math.max
@@ -72,7 +73,8 @@ private const val ITEM_THRESHOLD = 25
 class FastScroller : LinearLayout, Observer<HeadersIndex> {
 
     private var currentHeight: Int = 0
-    private var itemCount: Int = 0
+    private val itemCount: Int
+        get() = recyclerView.adapter?.itemCount ?: 0
     private var fastScrolling: Boolean = false
     private var showBubble: Boolean = false
     private var currentPosition: Int = 0
@@ -99,8 +101,8 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
     private val handler = object : WeakHandler<FastScroller>(this) {
         override fun handleMessage(msg: Message) {
             when (msg.what) {
-                HIDE_HANDLE -> hideBubble()
-                HIDE_SCROLLER -> this at FastScroller.visibility = View.INVISIBLE
+                HIDE_HANDLE ->  hideBubble()
+                HIDE_SCROLLER ->  this at FastScroller.visibility = View.INVISIBLE
                 SHOW_SCROLLER -> {
                     if (itemCount < ITEM_THRESHOLD) {
                         return
@@ -228,7 +230,6 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
         this.layoutManager = recyclerView.layoutManager as LinearLayoutManager
         this.recyclerView.removeOnScrollListener(scrollListener)
         visibility = View.INVISIBLE
-        itemCount = recyclerView.adapter!!.itemCount
         if (this::provider.isInitialized) this.provider.liveHeaders.removeObserver(this)
         this.provider = provider
         provider.liveHeaders.observeForever(this)



More information about the Android mailing list