[Android] Fix stream adapter crashes
Nicolas Pomepuy
git at videolan.org
Tue Nov 3 15:47:10 CET 2020
vlc-android | branch: 3.3.x | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Oct 28 08:48:32 2020 +0100| [1ce9f6095244f37ed88eef7525991e4041d03af7] | committer: Nicolas Pomepuy
Fix stream adapter crashes
Fixes #1523
(cherry picked from commit 872f12e84d588b442f1c3b3ad24b0c279368f2c4)
> https://code.videolan.org/videolan/vlc-android/commit/1ce9f6095244f37ed88eef7525991e4041d03af7
---
.../src/org/videolan/vlc/gui/network/MRLAdapter.kt | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.kt
index 51c0ba439..e5db6578e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/network/MRLAdapter.kt
@@ -27,6 +27,8 @@ import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.channels.SendChannel
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.tools.Settings
@@ -42,6 +44,8 @@ private const val TYPE_LIST = 0
private const val TYPE_CARD = 1
private const val TYPE_DUMMY = 2
+ at ExperimentalCoroutinesApi
+ at ObsoleteCoroutinesApi
internal class MRLAdapter(private val eventActor: SendChannel<MrlAction>, private val inCards: Boolean = false) : DiffUtilAdapter<MediaWrapper, RecyclerView.ViewHolder>() {
private var dummyClickListener: (() -> Unit)? = null
private val handler by lazy(LazyThreadSafetyMode.NONE) { Handler() }
@@ -56,13 +60,13 @@ internal class MRLAdapter(private val eventActor: SendChannel<MrlAction>, privat
}
override fun getItemViewType(position: Int) = when {
- dataset[position] != null && dataset[position].id < 0 -> TYPE_DUMMY
+ dataset.getOrNull(position)?.id ?: 0 < 0 -> TYPE_DUMMY
inCards -> TYPE_CARD
else -> TYPE_LIST
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
- val item = dataset[position]
+ val item = dataset.getOrNull(position) ?: return
when (holder) {
is ListViewHolder -> {
holder.binding.mrlItemUri.text = Uri.decode(item.location)
@@ -128,7 +132,7 @@ internal class MRLAdapter(private val eventActor: SendChannel<MrlAction>, privat
}
override fun onClick(v: View) {
- dataset[layoutPosition].let { eventActor.offer(Playmedia(it)) }
+ dataset.getOrNull(layoutPosition)?.let { eventActor.offer(Playmedia(it)) }
}
fun recycle() {}
@@ -143,7 +147,7 @@ internal class MRLAdapter(private val eventActor: SendChannel<MrlAction>, privat
}
override fun onClick(v: View) {
- dataset[layoutPosition].let { eventActor.offer(Playmedia(it)) }
+ dataset.getOrNull(layoutPosition)?.let { eventActor.offer(Playmedia(it)) }
}
fun recycle() {
More information about the Android
mailing list