[Android] PlaylistManager: code factorization
Geoffrey Métais
git at videolan.org
Mon Sep 23 17:21:30 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Sep 23 11:36:07 2019 +0200| [55f39cb3576dd2ab98a7a380488b88891d10161b] | committer: Geoffrey Métais
PlaylistManager: code factorization
> https://code.videolan.org/videolan/vlc-android/commit/55f39cb3576dd2ab98a7a380488b88891d10161b
---
.../src/org/videolan/vlc/media/PlaylistManager.kt | 2 +-
.../src/org/videolan/vlc/util/Kextensions.kt | 37 +++++-----------------
2 files changed, 9 insertions(+), 30 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 4cf0f7c81..a89463acd 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -651,7 +651,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
load(list, 0)
return
}
- val list = withContext(Dispatchers.IO) { list.getWithMLMeta() }
+ val list = withContext(Dispatchers.IO) { list.updateWithMLMeta() }
mediaList.removeEventListener(this)
for (media in list) mediaList.add(media)
mediaList.addEventListener(this)
diff --git a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index ae7cd6333..3d2698368 100644
--- a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -11,6 +11,7 @@ import android.os.Build
import android.util.DisplayMetrics
import android.view.View
import android.widget.TextView
+import androidx.annotation.WorkerThread
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.text.PrecomputedTextCompat
import androidx.core.widget.TextViewCompat
@@ -23,8 +24,8 @@ import org.videolan.libvlc.Media
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
+import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper.TYPE_ALL
import org.videolan.medialibrary.media.MediaLibraryItem
-import org.videolan.vlc.VLCApplication
import org.videolan.vlc.startMedialibrary
import java.io.File
import java.net.URI
@@ -104,40 +105,18 @@ suspend inline fun <reified T> Context.getFromMl(crossinline block: AbstractMedi
}
}
-
-fun List<AbstractMediaWrapper>.getWithMLMeta() : List<AbstractMediaWrapper> {
- if (this is MutableList<AbstractMediaWrapper>) return updateWithMLMeta()
- val list = mutableListOf<AbstractMediaWrapper>()
+ at WorkerThread
+fun List<AbstractMediaWrapper>.updateWithMLMeta() : MutableList<AbstractMediaWrapper> {
val ml = AbstractMedialibrary.getInstance()
+ val list = mutableListOf<AbstractMediaWrapper>()
for (media in this) {
- if (media.id == 0L) {
- val mw = ml.findMedia(media)
- if (mw.id != 0L) if (mw.type == AbstractMediaWrapper.TYPE_ALL) mw.type = media.type
- list.add(mw)
- }
+ list.add(ml.findMedia(media).apply {
+ if (type == TYPE_ALL) type = media.type
+ })
}
return list
}
-
-fun MutableList<AbstractMediaWrapper>.updateWithMLMeta() : MutableList<AbstractMediaWrapper> {
- val iter = listIterator()
- val ml = AbstractMedialibrary.getInstance()
- try {
- while (iter.hasNext()) {
- val media = iter.next()
- if (media.id == 0L) {
- val mw = ml.findMedia(media)
- if (mw!!.id != 0L) {
- if (mw.type == AbstractMediaWrapper.TYPE_ALL) mw.type = media.getType()
- iter.set(mw)
- }
- }
- }
- } catch (ignored: Exception) {}
- return this
-}
-
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
suspend fun String.scanAllowed() = withContext(Dispatchers.IO) {
More information about the Android
mailing list