[Android] Finer dispatch for ViewModels init

Geoffrey Métais git at videolan.org
Fri Apr 13 10:16:03 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 12 13:11:50 2018 +0200| [a8d248b1d8aabb39bccf0fe2d52e65e6defe91ba] | committer: Geoffrey Métais

Finer dispatch for ViewModels init

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

 vlc-android/src/org/videolan/vlc/viewmodels/BaseModel.kt   |  2 +-
 .../src/org/videolan/vlc/viewmodels/MedialibraryModel.kt   |  5 +++--
 .../org/videolan/vlc/viewmodels/browser/BrowserProvider.kt | 14 +++++++++-----
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/BaseModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/BaseModel.kt
index d93c862d9..54796ec61 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/BaseModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/BaseModel.kt
@@ -54,7 +54,7 @@ abstract class BaseModel<T : MediaLibraryItem> : ViewModel(), RefreshModel {
     private val filter by lazy(LazyThreadSafetyMode.NONE) { FilterDelegate(dataset) }
 
     val dataset by lazy {
-        launch(UI) { fetch() }
+        fetch()
         LiveDataset<T>()
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryModel.kt
index 7b4026117..d2c4cfc8a 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryModel.kt
@@ -27,6 +27,7 @@ import org.videolan.medialibrary.interfaces.MediaAddedCb
 import org.videolan.medialibrary.interfaces.MediaUpdatedCb
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.vlc.util.EmptyMLCallbacks
+import org.videolan.vlc.util.uiStart
 
 
 abstract class MedialibraryModel<T : MediaLibraryItem> : BaseModel<T>(), Medialibrary.OnMedialibraryReadyListener, MediaUpdatedCb by EmptyMLCallbacks, MediaAddedCb by EmptyMLCallbacks {
@@ -39,11 +40,11 @@ abstract class MedialibraryModel<T : MediaLibraryItem> : BaseModel<T>(), Mediali
     }
 
     override fun onMedialibraryReady() {
-        launch(UI) { refresh() }
+        launch(UI, uiStart()) { refresh() }
     }
 
     override fun onMedialibraryIdle() {
-        launch(UI) { refresh() }
+        launch(UI, uiStart()) { refresh() }
     }
 
     override fun onCleared() {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserProvider.kt
index 0fbccb22e..062c7716e 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserProvider.kt
@@ -54,12 +54,16 @@ abstract class BrowserProvider(val url: String?, private val showHiddenFiles: Bo
     override fun fetch() {
         val prefetchList by lazy(LazyThreadSafetyMode.NONE) { prefetchLists[url] }
         if (url === null) {
-            browseRoot()
-            parseSubDirectories()
+            launch(UI) {
+                browseRoot()
+                parseSubDirectories()
+            }
         } else if (prefetchList !== null && !prefetchList.isEmpty()) {
-            dataset.value = prefetchList
-            prefetchLists.remove(url)
-            parseSubDirectories()
+            launch(UI) {
+                dataset.value = prefetchList
+                prefetchLists.remove(url)
+                parseSubDirectories()
+            }
         } else browse(url, browserListener)
     }
 



More information about the Android mailing list