Commit 40579537 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy

Fix NullPointerException whe deleting files

parent 0efa9402
......@@ -323,19 +323,22 @@ object FileUtils {
@WorkerThread
fun findFile(uri: Uri): DocumentFile? {
val storage = getMediaStorage(uri)
val treePref = Settings.getInstance(VLCApplication.appContext).getString("tree_uri_" + storage!!, null)
?: return null
val treeUri = Uri.parse(treePref)
var documentFile = DocumentFile.fromTreeUri(VLCApplication.appContext, treeUri)
val parts = uri.path.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
for (i in 3 until parts.size) {
if (documentFile != null)
documentFile = documentFile.findFile(parts[i])
else
return null
uri.path?.let { path ->
val storage = getMediaStorage(uri)
val treePref = Settings.getInstance(VLCApplication.appContext).getString("tree_uri_" + storage!!, null)
?: return null
val treeUri = Uri.parse(treePref)
var documentFile = DocumentFile.fromTreeUri(VLCApplication.appContext, treeUri)
val parts = path.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
for (i in 3 until parts.size) {
if (documentFile != null)
documentFile = documentFile.findFile(parts[i])
else
return null
}
return documentFile
}
return documentFile
return null
}
......
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