[Android] Request focus for the selected chapter

Robert Stone git at videolan.org
Thu Mar 16 13:19:33 UTC 2023


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sat Mar 11 11:37:27 2023 -0800| [dcb1b7697b21aed31fc0f1304d8516a9f5bb5890] | committer: Nicolas Pomepuy

Request focus for the selected chapter

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

 .../videolan/vlc/gui/dialogs/SelectChapterDialog.kt | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
index 7ed7636c44..ab5f315791 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.kt
@@ -34,7 +34,6 @@ import androidx.recyclerview.widget.RecyclerView
 import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
 import kotlinx.coroutines.flow.onEach
 import org.videolan.medialibrary.Tools
-import org.videolan.tools.dp
 import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.ChapterListItemBinding
@@ -72,26 +71,28 @@ class SelectChapterDialog : VLCBottomSheetDialogFragment(), IOnChapterSelectedLi
     }
 
     private fun initChapterList() {
-        val chapters = service!!.getChapters(-1)
-        val chaptersCount = chapters?.size ?: 0
-        if (chaptersCount <= 1) return
+        val svc = service ?: return
+        val chapters = svc.getChapters(-1)
+        if (chapters == null || chapters.size <= 1) return
 
         val chapterData = ArrayList<Chapter>()
 
-        for (i in 0 until chaptersCount) {
-            val name: String = TextUtils.formatChapterTitle(requireActivity(), chapters!![i].name)
+        for (i in chapters.indices) {
+            val name: String = TextUtils.formatChapterTitle(requireActivity(), chapters[i].name)
             chapterData.add(Chapter(name, Tools.millisToString(chapters[i].timeOffset)))
         }
 
-
-        val adapter = ChapterAdapter(chapterData, service?.chapterIdx, this)
+        val adapter = ChapterAdapter(chapterData, svc.chapterIdx, this)
 
         chapterList.layoutManager = object : LinearLayoutManager(activity, VERTICAL, false) {
             override fun onLayoutCompleted(state: RecyclerView.State?) {
                 super.onLayoutCompleted(state)
-                service?.chapterIdx?.let { index ->
+                svc.chapterIdx.let { position ->
                     //we cannot scroll the recyclerview as its height is wrap_content. We scroll the nestedScrollView instead
-                    nestedScrollView.smoothScrollTo(0, 48.dp * index)
+                    findViewByPosition(position)?.apply {
+                        nestedScrollView.smoothScrollTo(0, y.toInt())
+                        requestFocusFromTouch()
+                    }
                 }
             }
         }



More information about the Android mailing list