[Android] TV,ChromeOS: Fix subs dl focus for DPAD navigation
Geoffrey Métais
git at videolan.org
Thu Dec 12 15:33:34 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey at videolan.org> | Thu Dec 12 15:33:34 2019 +0100| [0a423b5574e04aaf75be5047820546835cefe030] | committer: Nicolas Pomepuy
TV,ChromeOS: Fix subs dl focus for DPAD navigation
> https://code.videolan.org/videolan/vlc-android/commit/0a423b5574e04aaf75be5047820546835cefe030
---
.../vlc/gui/dialogs/SubtitleDownloadFragment.kt | 9 ++++---
.../videolan/vlc/gui/dialogs/SubtitlesAdapter.kt | 29 +++++++++-------------
2 files changed, 18 insertions(+), 20 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 db6e0ef03..7a86f782a 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 2471a0acc..55f1b5188 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)
- eventActor.offer(SubtitleClick(it)) }
- }
-
- override fun onLongClick(v: View): Boolean {
- dataset?.get(layoutPosition)?.let {
- if(!eventActor.isClosedForSend)
- eventActor.offer(SubtitleLongClick(it))
+ itemView.setOnClickListener {
+ dataset?.get(layoutPosition)?.let {
+ if(!eventActor.isClosedForSend)
+ eventActor.offer(SubtitleClick(it)) }
+ }
+ itemView.setOnLongClickListener {
+ dataset?.get(layoutPosition)?.let {
+ if(!eventActor.isClosedForSend)
+ eventActor.offer(SubtitleLongClick(it))
+ }
+ true
}
- return true
}
-
fun bind(subtitleItem: SubtitleItem?) {
binding.subtitleItem = subtitleItem
binding.executePendingBindings()
More information about the Android
mailing list