[Android] Add a Job to DiffUtilAdapter scope

Geoffrey Métais git at videolan.org
Wed Oct 30 15:24:16 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Oct 30 15:20:33 2019 +0100| [58f9e5cf5486dd64a25af6887ae7f975a636d9ec] | committer: Geoffrey Métais

Add a Job to DiffUtilAdapter scope

> https://code.videolan.org/videolan/vlc-android/commit/58f9e5cf5486dd64a25af6887ae7f975a636d9ec
---

 vlc-android/src/org/videolan/vlc/gui/DiffUtilAdapter.kt          | 2 +-
 .../src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt    | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DiffUtilAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/DiffUtilAdapter.kt
index ef7f809c6..14e505566 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DiffUtilAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/DiffUtilAdapter.kt
@@ -10,7 +10,7 @@ import kotlinx.coroutines.channels.actor
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
 abstract class DiffUtilAdapter<D, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>(), CoroutineScope {
-    override val coroutineContext = Dispatchers.Main.immediate
+    override val coroutineContext = Dispatchers.Main.immediate + SupervisorJob()
 
     protected var dataset: List<D> = listOf()
     private set
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
index e39e85eb8..98db73252 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
@@ -27,7 +27,10 @@ import android.content.Context
 import android.net.Uri
 import android.view.View
 import androidx.databinding.ViewDataBinding
-import kotlinx.coroutines.*
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.ObsoleteCoroutinesApi
+import kotlinx.coroutines.launch
 import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
 import org.videolan.medialibrary.media.MediaLibraryItem
@@ -51,7 +54,7 @@ internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBro
 
     override fun onBindViewHolder(holder: ViewHolder<ViewDataBinding>, position: Int) {
         val vh = holder as MediaViewHolder
-        vh.job = launch(start = CoroutineStart.UNDISPATCHED) {
+        vh.job = launch {
             var storage = getItem(position)
             if (storage.itemType == MediaLibraryItem.TYPE_MEDIA) storage = Storage((storage as AbstractMediaWrapper).uri)
             var storagePath = (storage as Storage).uri.path ?: ""
@@ -100,8 +103,6 @@ internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBro
             AbstractMedialibrary.getInstance().foldersList
         }
 
-
-
         folders.forEach {
             mediaDirsLocation.add(Uri.decode(if (it.startsWith("file://")) it.substring(7) else it))
         }



More information about the Android mailing list