[Android] Fix focus loss for advanced options in TV audio player
Nicolas Pomepuy
git at videolan.org
Wed Feb 9 14:56:37 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jan 17 09:14:57 2022 +0100| [57f5b42205f44e8893e814eff36d5e07ca00f441] | committer: Nicolas Pomepuy
Fix focus loss for advanced options in TV audio player
Relates to #2322
> https://code.videolan.org/videolan/vlc-android/commit/57f5b42205f44e8893e814eff36d5e07ca00f441
---
application/vlc-android/res/layout/player_options.xml | 4 ++--
.../src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt | 8 +++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/application/vlc-android/res/layout/player_options.xml b/application/vlc-android/res/layout/player_options.xml
index e0c4761a0..11a9107c3 100644
--- a/application/vlc-android/res/layout/player_options.xml
+++ b/application/vlc-android/res/layout/player_options.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.leanback.widget.BrowseFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/options_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -17,4 +17,4 @@
android:clipToPadding="false"
android:paddingTop="@dimen/default_margin"
android:paddingBottom="@dimen/default_margin" />
-</FrameLayout>
+</androidx.leanback.widget.BrowseFrameLayout>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
index 7eb3fe330..0485164cc 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
@@ -16,8 +16,9 @@ import androidx.appcompat.widget.ViewStubCompat
import androidx.core.content.getSystemService
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity
+import androidx.leanback.widget.BrowseFrameLayout
+import androidx.leanback.widget.BrowseFrameLayout.OnFocusSearchListener
import androidx.lifecycle.*
-import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.*
@@ -125,6 +126,11 @@ class PlayerOptionsDelegate(val activity: FragmentActivity, val service: Playbac
activity.findViewById<ViewStubCompat>(R.id.player_options_stub)?.let {
rootView = it.inflate() as FrameLayout
recyclerview = rootView.findViewById(R.id.options_list)
+ val browseFrameLayout = rootView.findViewById<BrowseFrameLayout>(R.id.options_background)
+ browseFrameLayout.onFocusSearchListener = OnFocusSearchListener { focused, direction ->
+ if (recyclerview.hasFocus()) focused // keep focus on recyclerview! DO NOT return recyclerview, but focused, which is a child of the recyclerview
+ else null // someone else will find the next focus
+ }
service.lifecycle.addObserver(this)
activity.lifecycle.addObserver(this)
if (recyclerview.layoutManager == null) recyclerview.layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
More information about the Android
mailing list