Skip to content

Commit

Permalink
Add checkIfDirectory flag in Tools.checkUriExists()
Browse files Browse the repository at this point in the history
  • Loading branch information
sayantan-kgp committed Mar 14, 2021
1 parent 30a2e75 commit d93519d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/balti/filex/filex11/utils/Tools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit d93519d

Please sign in to comment.