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

Fix external device not added to medialibrary

Fix #781
parent bb5f2b0e
No related branches found
No related tags found
No related merge requests found
Pipeline #5508 passed with stage
in 3 minutes and 40 seconds
......@@ -78,17 +78,20 @@ fun Long.random() = (Random().nextFloat() * this).toLong()
suspend inline fun <reified T> Context.getFromMl(crossinline block: Medialibrary.() -> T) = withContext(Dispatchers.IO) {
val ml = Medialibrary.getInstance()
if (ml.isStarted) block.invoke(ml)
else suspendCancellableCoroutine { continuation ->
val listener = object : Medialibrary.OnMedialibraryReadyListener {
override fun onMedialibraryReady() {
if (!continuation.isCompleted) continuation.resume(block.invoke(ml))
let { launch { ml.removeOnMedialibraryReadyListener(it) } }
else {
val scan = Settings.getInstance(this@getFromMl).getInt(KEY_MEDIALIBRARY_SCAN, ML_SCAN_ON) == ML_SCAN_ON
suspendCancellableCoroutine { continuation ->
val listener = object : Medialibrary.OnMedialibraryReadyListener {
override fun onMedialibraryReady() {
if (!continuation.isCompleted) continuation.resume(block.invoke(ml))
let { launch { ml.removeOnMedialibraryReadyListener(it) } }
}
override fun onMedialibraryIdle() {}
}
override fun onMedialibraryIdle() {}
continuation.invokeOnCancellation { ml.removeOnMedialibraryReadyListener(listener) }
ml.addOnMedialibraryReadyListener(listener)
startMedialibrary(false, false, scan)
}
continuation.invokeOnCancellation { ml.removeOnMedialibraryReadyListener(listener) }
ml.addOnMedialibraryReadyListener(listener)
startMedialibrary(false, false, false)
}
}
......
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