Commit e2252491 authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Geoffrey Métais
Browse files

Browser: change listener in IO threadpool

Avoid ANRs
parent 0b3468ba
......@@ -133,16 +133,22 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
loading.postValue(false)
}
private fun filesFlow(url: String? = this.url, interact : Boolean = true) = channelFlow<Media> {
val listener = object : EventListener {
override fun onMediaAdded(index: Int, media: Media) { if (!isClosedForSend) offer(media.apply { retain() }) }
private suspend fun filesFlow(url: String? = this.url, interact : Boolean = true) = withContext(Dispatchers.IO) {
channelFlow {
val listener = object : EventListener {
override fun onMediaAdded(index: Int, media: Media) {
if (!isClosedForSend) offer(media.apply { retain() })
}
override fun onBrowseEnd() { if (!isClosedForSend) close() }
override fun onBrowseEnd() {
if (!isClosedForSend) close()
}
override fun onMediaRemoved(index: Int, media: Media) {}
override fun onMediaRemoved(index: Int, media: Media) {}
}
requestBrowsing(url, listener, interact)
awaitClose { mediabrowser?.changeEventListener(null) }
}
requestBrowsing(url, listener, interact)
awaitClose { mediabrowser?.changeEventListener(null) }
}
protected open fun addMedia(media: MediaLibraryItem) = dataset.add(media)
......
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