[Android] Properly restore selected position when coming back to TV network browser
Nicolas Pomepuy
git at videolan.org
Fri Aug 23 09:20:10 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Aug 23 09:12:27 2019 +0200| [3d9097ba82a62e7874757967830fc3a343475ca2] | committer: Nicolas Pomepuy
Properly restore selected position when coming back to TV network browser
> https://code.videolan.org/videolan/vlc-android/commit/3d9097ba82a62e7874757967830fc3a343475ca2
---
.../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