[Android] TV: Prevent NPE on play click with no ViewModel

Geoffrey Métais git at videolan.org
Mon Jun 3 16:45:35 CEST 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jun  3 16:44:03 2019 +0200| [258a589511fb9e7ea95bc4a25390e20a2bd56a84] | committer: Geoffrey Métais

TV: Prevent NPE on play click with no ViewModel

Fix #891

> https://code.videolan.org/videolan/vlc-android/commit/258a589511fb9e7ea95bc4a25390e20a2bd56a84
---

 vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt | 2 +-
 vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt         | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
index 856e18f1f..ca68de1de 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/SearchFragment.kt
@@ -47,7 +47,7 @@ class SearchFragment : SearchSupportFragment(), SearchSupportFragment.SearchResu
 
     private val rowsAdapter = ArrayObjectAdapter(ListRowPresenter())
     private val defaultItemClickedListener: OnItemViewClickedListener
-        get() = OnItemViewClickedListener { _, item, _, row ->
+        get() = OnItemViewClickedListener { _, item, _, _ ->
             if (item is MediaWrapper) TvUtil.openMedia(requireActivity(), item, null)
             else TvUtil.openAudioCategory(requireActivity(), item as MediaLibraryItem)
             requireActivity().finish()
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
index f082a4b94..e82d9112b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
@@ -131,11 +131,11 @@ object TvUtil {
                     intent.putExtra(KEY_GROUP, title)
                     activity.startActivity(intent)
                 }
-                else -> {
-                    val list = (model!!.dataset.value as List<MediaWrapper>).filter { it.type != MediaWrapper.TYPE_DIR }
+                else -> model?.run {
+                    val list = (dataset.value as List<MediaWrapper>).filter { it.type != MediaWrapper.TYPE_DIR }
                     val position = list.getposition(item)
                     MediaUtils.openList(activity, list, position)
-                }
+                } ?: MediaUtils.openMedia(activity, item)
             }
             is DummyItem -> when {
                 item.id == HEADER_STREAM -> activity.startActivity(Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_STREAM)



More information about the Android mailing list