Commit 55f39cb3 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

PlaylistManager: code factorization

parent 45eac0ba
...@@ -651,7 +651,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList ...@@ -651,7 +651,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
load(list, 0) load(list, 0)
return return
} }
val list = withContext(Dispatchers.IO) { list.getWithMLMeta() } val list = withContext(Dispatchers.IO) { list.updateWithMLMeta() }
mediaList.removeEventListener(this) mediaList.removeEventListener(this)
for (media in list) mediaList.add(media) for (media in list) mediaList.add(media)
mediaList.addEventListener(this) mediaList.addEventListener(this)
......
...@@ -11,6 +11,7 @@ import android.os.Build ...@@ -11,6 +11,7 @@ import android.os.Build
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.View import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.annotation.WorkerThread
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import androidx.core.text.PrecomputedTextCompat import androidx.core.text.PrecomputedTextCompat
import androidx.core.widget.TextViewCompat import androidx.core.widget.TextViewCompat
...@@ -23,8 +24,8 @@ import org.videolan.libvlc.Media ...@@ -23,8 +24,8 @@ import org.videolan.libvlc.Media
import org.videolan.libvlc.util.AndroidUtil import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.AbstractMedialibrary import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper 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.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.startMedialibrary import org.videolan.vlc.startMedialibrary
import java.io.File import java.io.File
import java.net.URI import java.net.URI
...@@ -104,40 +105,18 @@ suspend inline fun <reified T> Context.getFromMl(crossinline block: AbstractMedi ...@@ -104,40 +105,18 @@ suspend inline fun <reified T> Context.getFromMl(crossinline block: AbstractMedi
} }
} }
@WorkerThread
fun List<AbstractMediaWrapper>.getWithMLMeta() : List<AbstractMediaWrapper> { fun List<AbstractMediaWrapper>.updateWithMLMeta() : MutableList<AbstractMediaWrapper> {
if (this is MutableList<AbstractMediaWrapper>) return updateWithMLMeta()
val list = mutableListOf<AbstractMediaWrapper>()
val ml = AbstractMedialibrary.getInstance() val ml = AbstractMedialibrary.getInstance()
val list = mutableListOf<AbstractMediaWrapper>()
for (media in this) { for (media in this) {
if (media.id == 0L) { list.add(ml.findMedia(media).apply {
val mw = ml.findMedia(media) if (type == TYPE_ALL) type = media.type
if (mw.id != 0L) if (mw.type == AbstractMediaWrapper.TYPE_ALL) mw.type = media.type })
list.add(mw)
}
} }
return list 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 @ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi @ObsoleteCoroutinesApi
suspend fun String.scanAllowed() = withContext(Dispatchers.IO) { suspend fun String.scanAllowed() = withContext(Dispatchers.IO) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment