[Android] Playback filter: prevent concurrent access
Geoffrey Métais
git at videolan.org
Fri Jul 19 14:59:05 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul 19 14:58:17 2019 +0200| [8f3bf5533521860bdc6592ef10a92f0b39c37efa] | committer: Geoffrey Métais
Playback filter: prevent concurrent access
> https://code.videolan.org/videolan/vlc-android/commit/8f3bf5533521860bdc6592ef10a92f0b39c37efa
---
vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
index b4d7042fd..0f288768b 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
@@ -20,6 +20,7 @@
package org.videolan.vlc.viewmodels
+import androidx.annotation.MainThread
import androidx.fragment.app.Fragment
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
@@ -27,7 +28,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
-import kotlinx.coroutines.launch
+import kotlinx.coroutines.channels.actor
import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.vlc.PlaybackService
@@ -54,6 +55,12 @@ class PlaylistModel : ScopedModel(), PlaybackService.Callback by EmptyPBSCallbac
private val filter by lazy(LazyThreadSafetyMode.NONE) { PlaylistFilterDelegate(dataset) }
+ private val filterActor by lazy(mode = LazyThreadSafetyMode.NONE) {
+ actor<CharSequence?> {
+ for (query in channel) filter.filter(query)
+ }
+ }
+
init {
PlaybackService.service.observeForever(this)
}
@@ -79,13 +86,14 @@ class PlaylistModel : ScopedModel(), PlaybackService.Callback by EmptyPBSCallbac
fun move(from: Int, to: Int) = service?.moveItem(from, to)
+ @MainThread
fun filter(query: CharSequence?) {
val filtering = query != null
if (this.filtering != filtering) {
this.filtering = filtering
originalDataset = if (filtering) dataset.value.toMutableList() else null
}
- launch { filter.filter(query) }
+ filterActor.offer(query)
}
val title
More information about the Android
mailing list