[Android] Cancel current job before updating favorites

Geoffrey Métais git at videolan.org
Fri Aug 3 09:57:18 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Aug  3 09:56:49 2018 +0200| [a7de371ae171b0fa37a0c4c978871d1c83a67fb5] | committer: Geoffrey Métais

Cancel current job before updating favorites

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

 .../src/org/videolan/vlc/providers/BrowserProvider.kt    |  2 +-
 .../org/videolan/vlc/providers/FileBrowserProvider.kt    | 16 ++++++++++------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index eac654c9c..285337ec1 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -57,7 +57,7 @@ abstract class BrowserProvider(val dataset: LiveDataset<MediaLibraryItem>, val u
 
     private val foldersContentMap = SimpleArrayMap<MediaLibraryItem, MutableList<MediaLibraryItem>>()
     private lateinit var browserChannel : Channel<Media>
-    private var job : Job? = null
+    protected var job : Job? = null
 
     val descriptionUpdate = MutableLiveData<Pair<Int, String>>()
     internal val medialibrary = Medialibrary.getInstance()
diff --git a/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
index b5d5e6190..172a4f754 100644
--- a/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
@@ -25,6 +25,7 @@ import android.hardware.usb.UsbDevice
 import android.net.Uri
 import android.text.TextUtils
 import kotlinx.coroutines.experimental.Job
+import kotlinx.coroutines.experimental.cancelAndJoin
 import kotlinx.coroutines.experimental.withContext
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.media.DummyItem
@@ -62,13 +63,16 @@ open class FileBrowserProvider(
                 }
             }
         }
-        if (favs.isNotEmpty()) {
-            val quickAccess = VLCApplication.getAppResources().getString(R.string.browser_quick_access)
-            data.add(DummyItem(quickAccess))
-            for (fav in favs) if (File(fav.uri.path).exists()) data.add(fav)
+        uiJob(false) {
+            if (favs.isNotEmpty()) {
+                job?.cancelAndJoin()
+                val quickAccess = VLCApplication.getAppResources().getString(R.string.browser_quick_access)
+                data.add(DummyItem(quickAccess))
+                for (fav in favs) if (File(fav.uri.path).exists()) data.add(fav)
+            }
+            dataset.value = data
+            parseSubDirectories()
         }
-        dataset.value = data
-        uiJob(false) { parseSubDirectories() }
     } }
 
     init {



More information about the Android mailing list