[Android] Add the fast scroller to the HeaderMediaListActivity

Nicolas Pomepuy git at videolan.org
Fri Jun 23 09:34:39 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun 22 11:05:20 2023 +0200| [fb43a25556bdda486deaa86c6ebd8a0cea35a0de] | committer: Duncan McNamara

Add the fast scroller to the HeaderMediaListActivity

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

 .../res/layout/header_media_list_activity.xml      | 47 ++++++++++++++++------
 .../videolan/vlc/gui/HeaderMediaListActivity.kt    |  6 +++
 .../videolan/vlc/gui/audio/AudioBrowserAdapter.kt  |  3 +-
 .../src/org/videolan/vlc/gui/view/FastScroller.kt  |  8 ++--
 4 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/application/vlc-android/res/layout/header_media_list_activity.xml b/application/vlc-android/res/layout/header_media_list_activity.xml
index cbad3131d4..03ae3b0cd2 100644
--- a/application/vlc-android/res/layout/header_media_list_activity.xml
+++ b/application/vlc-android/res/layout/header_media_list_activity.xml
@@ -236,18 +236,41 @@
             </com.google.android.material.appbar.CollapsingToolbarLayout>
         </com.google.android.material.appbar.AppBarLayout>
 
-        <androidx.recyclerview.widget.RecyclerView
-                android:id="@+id/songs"
-                android:layout_width="@dimen/default_content_width"
-                tools:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:layout_gravity="center_horizontal|top"
-                android:background="?attr/background_default"
-                android:clipToPadding="false"
-                android:fastScrollEnabled="true"
-                android:paddingBottom="64dp"
-                android:scrollbars="vertical"
-                vlc:layout_behavior="@string/appbar_scrolling_view_behavior" />
+        <org.videolan.vlc.gui.view.SwipeRefreshLayout
+                android:id="@+id/swipeLayout"
+                    android:layout_width="match_parent"
+                vlc:layout_behavior="@string/appbar_scrolling_view_behavior"
+                    android:layout_height="match_parent">
+
+            <RelativeLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent">
+
+            <androidx.recyclerview.widget.RecyclerView
+                    android:id="@+id/songs"
+                    android:layout_width="@dimen/default_content_width"
+                    android:layout_height="match_parent"
+                    android:layout_gravity="center_horizontal|top"
+                    android:background="?attr/background_default"
+                    android:clipToPadding="false"
+                    android:fastScrollEnabled="true"
+                    android:paddingBottom="64dp"
+                    tools:layout_width="match_parent" />
+
+                <org.videolan.vlc.gui.view.FastScroller
+                        android:id="@+id/browser_fast_scroller"
+                        android:layout_width="wrap_content"
+                        android:layout_height="match_parent"
+                        android:layout_alignParentEnd="true"
+                        android:layout_alignParentRight="true"
+                        android:visibility="invisible" />
+            </RelativeLayout>
+        </org.videolan.vlc.gui.view.SwipeRefreshLayout>
+
+
+
+
+
 
         <include layout="@layout/audioplayercontainer" />
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index 5dd1340847..08668cf221 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -212,6 +212,12 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
         }
 
         binding.playBtn.setOnClickListener(this)
+
+        //swipe layout is only here to be able to make the recyclerview dispatch the scroll events
+        binding.swipeLayout.isEnabled = false
+        audioBrowserAdapter.areSectionsEnabled = false
+        binding.browserFastScroller.attachToCoordinator(binding.appbar, binding.coordinator, null)
+        binding.browserFastScroller.setRecyclerView(binding.songs, viewModel.tracksProvider)
     }
 
     override fun onStop() {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
index 4312254dc1..671cd9c279 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
@@ -93,6 +93,7 @@ open class AudioBrowserAdapter @JvmOverloads constructor(
     lateinit var inflater: LayoutInflater
     private val handler by lazy(LazyThreadSafetyMode.NONE) { Handler(Looper.getMainLooper()) }
     var stopReorder = false
+    var areSectionsEnabled = true
 
     protected fun inflaterInitialized() = ::inflater.isInitialized
 
@@ -218,7 +219,7 @@ open class AudioBrowserAdapter @JvmOverloads constructor(
     }
 
     override fun hasSections(): Boolean {
-        return true
+        return areSectionsEnabled
     }
 
     override fun onItemMove(fromPosition: Int, toPosition: Int) {
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 00003a28e1..98df2886ed 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
@@ -87,7 +87,7 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
     private lateinit var bubble: TextView
     private lateinit var coordinatorLayout: CoordinatorLayout
     private lateinit var appbarLayout: AppBarLayout
-    private lateinit var floatingActionButton: FloatingActionButton
+    private var floatingActionButton: FloatingActionButton? = null
     private var lastPosition = 0f
     private var appbarLayoutExpanded = true
     private val isAnimating = AtomicBoolean(false)
@@ -141,7 +141,7 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
     /**
      * Attaches the FastScroller to an [appBarLayout] and a [coordinatorLayout]
      */
-    fun attachToCoordinator(appBarLayout: AppBarLayout, coordinatorLayout: CoordinatorLayout, floatingActionButton: FloatingActionButton) {
+    fun attachToCoordinator(appBarLayout: AppBarLayout, coordinatorLayout: CoordinatorLayout, floatingActionButton: FloatingActionButton?) {
         this.coordinatorLayout = coordinatorLayout
         appbarLayout = appBarLayout
         this.floatingActionButton = floatingActionButton
@@ -326,7 +326,7 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
                 if (tryCollapseAppbarOnNextScroll && lastVerticalOffset != -it) {
                     if (!isAnimating.get()) {
                         appbarLayout.setExpanded(false)
-                        floatingActionButton.hide()
+                        floatingActionButton?.hide()
                         isAnimating.set(true)
                     }
                     tryCollapseAppbarOnNextScroll = false
@@ -335,7 +335,7 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
                 if (tryExpandAppbarOnNextScroll && lastVerticalOffset == -it) {
                     if (!isAnimating.get()) {
                         appbarLayout.setExpanded(true)
-                        floatingActionButton.show()
+                        floatingActionButton?.show()
                         isAnimating.set(true)
                     }
                     tryExpandAppbarOnNextScroll = false



More information about the Android mailing list