[Android] Bundle onItemAdded callbacks
Geoffrey Métais
git at videolan.org
Tue Feb 12 15:15:18 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 12 15:14:05 2019 +0100| [6d83d58df0e1e998437d34c0f022bc2f52f6e23f] | committer: Geoffrey Métais
Bundle onItemAdded callbacks
Will help for large collections loading or folder expanding.
Otherwise, it starts hundreds of update callbacks.
> https://code.videolan.org/videolan/vlc-android/commit/6d83d58df0e1e998437d34c0f022bc2f52f6e23f
---
vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index c71927e7d..22e2928f0 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -10,6 +10,8 @@ import androidx.annotation.MainThread
import androidx.lifecycle.MutableLiveData
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import kotlinx.coroutines.*
+import kotlinx.coroutines.channels.Channel
+import kotlinx.coroutines.channels.actor
import org.videolan.libvlc.Media
import org.videolan.libvlc.MediaPlayer
import org.videolan.libvlc.RendererItem
@@ -375,7 +377,11 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
override fun onItemAdded(index: Int, mrl: String?) {
if (BuildConfig.DEBUG) Log.i(TAG, "CustomMediaListItemAdded")
if (currentIndex >= index && !expanding) ++currentIndex
- launch {
+ addUpdateActor.offer(Unit)
+ }
+
+ private val addUpdateActor = actor<Unit>(capacity = Channel.CONFLATED) {
+ for (update in channel) {
determinePrevAndNextIndices()
executeUpdate()
saveMediaList()
More information about the Android
mailing list