[Android] TV,ChromeOS: Fix subs dl focus for DPAD navigation

Geoffrey Métais git at videolan.org
Thu Dec 12 15:39:00 CET 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey at videolan.org> | Thu Dec 12 15:33:34 2019 +0100| [588b2f1dcc3cb341f420e2443000d88a33f08fa0] | committer: Nicolas Pomepuy

TV,ChromeOS: Fix subs dl focus for DPAD navigation

(cherry picked from commit 0a423b5574e04aaf75be5047820546835cefe030)

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

 .../vlc/gui/dialogs/SubtitleDownloadFragment.kt    |  9 +++++---
 .../videolan/vlc/gui/dialogs/SubtitlesAdapter.kt   | 25 +++++++++-------------
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt
index b2c4e22ab..71ef7e0fb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitleDownloadFragment.kt
@@ -12,10 +12,12 @@ import androidx.lifecycle.ViewModelProviders
 import androidx.recyclerview.widget.DividerItemDecoration
 import androidx.recyclerview.widget.LinearLayoutManager
 import org.videolan.vlc.R
+import org.videolan.vlc.VLCApplication
 import org.videolan.vlc.databinding.SubtitleDownloadFragmentBinding
 import org.videolan.vlc.gui.OnItemSelectListener
 import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.util.AndroidDevices
+import org.videolan.vlc.util.Settings
 import org.videolan.vlc.viewmodels.SubtitlesModel
 
 class SubtitleDownloadFragment : Fragment() {
@@ -34,16 +36,17 @@ class SubtitleDownloadFragment : Fragment() {
         val binding = SubtitleDownloadFragmentBinding.inflate(inflater, container, false)
         binding.viewmodel = viewModel
 
-        if (!AndroidDevices.isAndroidTv)
+        if (!Settings.showTvUi && !AndroidDevices.isChromeBook) {
             //Prevent opening soft keyboard automatically
             binding.constraintLayout.isFocusableInTouchMode = true
+        }
 
         adapter = SubtitlesAdapter((parentFragment as SubtitleDownloaderDialogFragment).listEventActor)
         val recyclerView = binding.subtitleList
         recyclerView.addItemDecoration(DividerItemDecoration(activity, DividerItemDecoration.VERTICAL))
         recyclerView.adapter = adapter
         recyclerView.layoutManager = LinearLayoutManager(activity)
-        viewModel.result.observe(this, Observer {
+        viewModel.result.observe(viewLifecycleOwner, Observer {
             adapter.setList(it)
             if (it.isNotEmpty()) focusOnView(binding.scrollView, binding.swipeContainer)
         })
@@ -60,7 +63,7 @@ class SubtitleDownloadFragment : Fragment() {
         binding.languageListSpinner.setOnItemsSelectListener(object: OnItemSelectListener {
             override fun onItemSelect(selectedItems: List<Int>) {
                 val selectedLanguages = if (selectedItems.size == allValuesOfLanguages.size) listOf<String>()
-                else selectedItems.filter { it in 0 until allValuesOfLanguages.size }.map { allValuesOfLanguages[it] }
+                else selectedItems.filter { it in allValuesOfLanguages.indices }.map { allValuesOfLanguages[it] }
                 viewModel.observableSearchLanguage.set(selectedLanguages)
             }
         })
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt
index 677763ef3..32cb9f3e8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SubtitlesAdapter.kt
@@ -30,28 +30,23 @@ internal class SubtitlesAdapter(private val eventActor: SendChannel<SubtitleEven
     override fun getItemCount() = dataset?.size ?: 0
 
     @ExperimentalCoroutinesApi
-    inner class ViewHolder(val binding: SubtitleDownloadItemBinding) : RecyclerView.ViewHolder(binding.root), View.OnClickListener, View.OnLongClickListener {
+    inner class ViewHolder(val binding: SubtitleDownloadItemBinding) : RecyclerView.ViewHolder(binding.root) {
 
         init {
-            itemView.setOnClickListener(this)
-            itemView.setOnLongClickListener(this)
-        }
-
-        override fun onClick(v: View) {
-            dataset?.get(layoutPosition)?.let {
-                if(!eventActor.isClosedForSend)
+            itemView.setOnClickListener {
+                dataset?.get(layoutPosition)?.let {
+                    if (!eventActor.isClosedForSend)
                     eventActor.offer(Click(it)) }
-        }
-
-        override fun onLongClick(v: View): Boolean {
-            dataset?.get(layoutPosition)?.let {
-                if(!eventActor.isClosedForSend)
+            }
+            itemView.setOnLongClickListener {
+                dataset?.get(layoutPosition)?.let {
+                    if (!eventActor.isClosedForSend)
                     eventActor.offer(LongClick(it))
+                }
+                true
             }
-            return true
         }
 
-
         fun bind(subtitleItem: SubtitleItem?) {
             binding.subtitleItem = subtitleItem
             binding.executePendingBindings()



More information about the Android mailing list