From d93519dd1aebfdee26c8921b59d5246977de182c Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Sun, 14 Mar 2021 11:40:22 +0530 Subject: [PATCH] Add checkIfDirectory flag in Tools.checkUriExists() --- src/main/java/balti/filex/filex11/utils/Tools.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/balti/filex/filex11/utils/Tools.kt b/src/main/java/balti/filex/filex11/utils/Tools.kt index 8dfcf38..a877c95 100644 --- a/src/main/java/balti/filex/filex11/utils/Tools.kt +++ b/src/main/java/balti/filex/filex11/utils/Tools.kt @@ -178,12 +178,14 @@ object Tools { catch (_: Exception) { null } } - internal fun checkUriExists(uri: Uri): Boolean{ + internal fun checkUriExists(uri: Uri, checkIfDirectory: Boolean = false): Boolean{ var result = false val evalUri = convertToDocumentUri(uri) ?: return false + val projection = if (checkIfDirectory) arrayOf(DocumentsContract.Document.COLUMN_MIME_TYPE) else null try { - val c = FileXInit.fCResolver.query(evalUri, null, null, null, null, null) - if (c != null && c.count > 0 && c.moveToFirst()) result = c.getString(4) != null + val c = FileXInit.fCResolver.query(evalUri, projection, null, null, null, null) + if (c != null && c.count > 0 && c.moveToFirst()) result = c.columnCount != 0 + if (result && checkIfDirectory) result = c?.getString(0) == DocumentsContract.Document.MIME_TYPE_DIR c?.close() } catch (e: Exception){