[Android] Properly restore selected position when coming back to TV network browser

Nicolas Pomepuy git at videolan.org
Tue Aug 27 13:01:52 CEST 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Aug 23 09:12:27 2019 +0200| [6f68d746813a2b0e0b06233878dc3d7f8de682f0] | committer: Nicolas Pomepuy

Properly restore selected position when coming back to TV network browser

(cherry picked from commit 3d9097ba82a62e7874757967830fc3a343475ca2)

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

 .../videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt    | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
index ded303828..e59825a0f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
@@ -6,6 +6,7 @@ import android.util.Log
 import android.view.View
 import androidx.lifecycle.Observer
 import androidx.recyclerview.widget.GridLayoutManager
+import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import kotlinx.android.synthetic.main.song_browser.*
 import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -26,7 +27,6 @@ import org.videolan.vlc.viewmodels.browser.BrowserModel
 import org.videolan.vlc.viewmodels.browser.TYPE_FILE
 import org.videolan.vlc.viewmodels.browser.TYPE_NETWORK
 import org.videolan.vlc.viewmodels.browser.getBrowserModel
-import java.util.*
 
 @UseExperimental(ObsoleteCoroutinesApi::class)
 @ExperimentalCoroutinesApi
@@ -65,7 +65,17 @@ class FileBrowserTvFragment : BaseBrowserTvFragment() {
         viewModel.currentItem = item
 
         (viewModel.provider as BrowserProvider).dataset.observe(this, Observer { items ->
+            val lm = binding.list.layoutManager as LinearLayoutManager
+            val selectedItem = lm.focusedChild
             submitList(items)
+            binding.list.post {
+                for (i in 0 until lm.childCount) {
+                    if (lm.getChildAt(i) == selectedItem) {
+                        lm.getChildAt(i)?.requestFocus()
+                        lm.scrollToPosition(lm.getPosition(lm.getChildAt(i)!!))
+                    }
+                }
+            }
             if (BuildConfig.DEBUG) Log.d("FileBrowserTvFragment", "Submit lis of ${items.size} items")
             if (BuildConfig.DEBUG) Log.d("FileBrowserTvFragment", "header size: ${viewModel.provider.headers.size()}")
 
@@ -114,7 +124,6 @@ class FileBrowserTvFragment : BaseBrowserTvFragment() {
         super.onSaveInstanceState(outState)
     }
 
-
     override fun onStop() {
         super.onStop()
         (viewModel as BrowserModel).stop()



More information about the Android mailing list