[Android] Add the fast scroller to the browse fragment

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 09:18:39 2023 +0200| [05d79fc3f77037b6f425ad7c6d8bf7cd4b99fd0d] | committer: Duncan McNamara

Add the fast scroller to the browse fragment

Fixes #2871

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

 application/vlc-android/res/layout/directory_browser.xml         | 9 +++++++++
 .../src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt       | 5 ++++-
 .../src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt      | 5 +++++
 .../vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt    | 7 +++----
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/res/layout/directory_browser.xml b/application/vlc-android/res/layout/directory_browser.xml
index 7af6689c62..2c7b937150 100644
--- a/application/vlc-android/res/layout/directory_browser.xml
+++ b/application/vlc-android/res/layout/directory_browser.xml
@@ -54,6 +54,15 @@
                     android:visibility="gone"/>
         </org.videolan.vlc.gui.view.SwipeRefreshLayout>
 
+        <org.videolan.vlc.gui.view.FastScroller
+                android:id="@+id/browser_fast_scroller"
+                android:layout_width="wrap_content"
+                android:layout_height="0dp"
+                android:visibility="invisible"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintTop_toTopOf="parent" />
+
         <org.videolan.vlc.gui.view.EmptyLoadingStateView
                 android:id="@+id/empty_loading"
                 android:layout_width="0dp"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
index 8362569011..9a387bb85c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
@@ -52,9 +52,10 @@ import org.videolan.vlc.databinding.BrowserItemSeparatorBinding
 import org.videolan.vlc.databinding.CardBrowserItemBinding
 import org.videolan.vlc.gui.DiffUtilAdapter
 import org.videolan.vlc.gui.helpers.*
+import org.videolan.vlc.gui.view.FastScroller
 import org.videolan.vlc.util.getDescriptionSpan
 
-open class BaseBrowserAdapter(val browserContainer: BrowserContainer<MediaLibraryItem>, var sort:Int = Medialibrary.SORT_FILENAME, var asc:Boolean = true) : DiffUtilAdapter<MediaLibraryItem, BaseBrowserAdapter.ViewHolder<ViewDataBinding>>(), MultiSelectAdapter<MediaLibraryItem> {
+open class BaseBrowserAdapter(val browserContainer: BrowserContainer<MediaLibraryItem>, var sort:Int = Medialibrary.SORT_FILENAME, var asc:Boolean = true) : DiffUtilAdapter<MediaLibraryItem, BaseBrowserAdapter.ViewHolder<ViewDataBinding>>(), MultiSelectAdapter<MediaLibraryItem>, FastScroller.SeparatedAdapter {
 
     protected val TAG = "VLC/BaseBrowserAdapter"
 
@@ -378,4 +379,6 @@ open class BaseBrowserAdapter(val browserContainer: BrowserContainer<MediaLibrar
 
         override fun areItemsTheSame(oldItemPosition : Int, newItemPosition : Int) = oldList[oldItemPosition] == newList[newItemPosition]
     }
+
+    override fun hasSections() = false
 }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index 8f45eb3ed8..ee2a0c8e0e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -29,6 +29,7 @@ import android.os.Message
 import android.util.Log
 import android.view.*
 import androidx.appcompat.view.ActionMode
+import androidx.coordinatorlayout.widget.CoordinatorLayout
 import androidx.core.content.ContextCompat
 import androidx.core.net.toUri
 import androidx.core.os.bundleOf
@@ -39,6 +40,8 @@ import androidx.recyclerview.widget.DividerItemDecoration
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+import com.google.android.material.appbar.AppBarLayout
+import com.google.android.material.floatingactionbutton.FloatingActionButton
 import com.google.android.material.snackbar.Snackbar
 import kotlinx.coroutines.*
 import kotlinx.coroutines.flow.launchIn
@@ -180,6 +183,8 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
             swipeRefreshLayout.isRefreshing = loading
             updateEmptyView()
         }
+        binding.browserFastScroller.attachToCoordinator(view.rootView.findViewById<View>(R.id.appbar) as AppBarLayout, view.rootView.findViewById<View>(R.id.coordinator) as CoordinatorLayout, view.rootView.findViewById<View>(R.id.fab) as FloatingActionButton)
+        binding.browserFastScroller.setRecyclerView(binding.networkList, viewModel.provider)
     }
 
     override fun sortBy(sort: 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 c3f066f85e..00003a28e1 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
@@ -47,12 +47,11 @@ 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.HeaderProvider
 import org.videolan.resources.util.HeadersIndex
 import org.videolan.tools.WeakHandler
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
-import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
 import org.videolan.vlc.util.scope
 import java.util.concurrent.atomic.AtomicBoolean
 import kotlin.math.max
@@ -83,7 +82,7 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
     private val scrollListener = ScrollListener()
     private lateinit var recyclerView: RecyclerView
     private lateinit var layoutManager: LinearLayoutManager
-    private lateinit var provider: MedialibraryProvider<out MediaLibraryItem>
+    private lateinit var provider: HeaderProvider
     private lateinit var handle: ImageView
     private lateinit var bubble: TextView
     private lateinit var coordinatorLayout: CoordinatorLayout
@@ -225,7 +224,7 @@ class FastScroller : LinearLayout, Observer<HeadersIndex> {
     /**
      * Sets the [recyclerView] it will be attached to
      */
-    fun setRecyclerView(recyclerView: RecyclerView, provider: MedialibraryProvider<out MediaLibraryItem>) {
+    fun setRecyclerView(recyclerView: RecyclerView, provider: HeaderProvider) {
         this.recyclerView = recyclerView
         this.layoutManager = recyclerView.layoutManager as LinearLayoutManager
         this.recyclerView.removeOnScrollListener(scrollListener)



More information about the Android mailing list