Skip to content
Snippets Groups Projects
Commit 55f39cb3 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

PlaylistManager: code factorization

parent 45eac0ba
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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>()
@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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment