ignore the root folders at fetching media

This commit is contained in:
tibbi 2017-09-27 23:10:14 +02:00
parent dfdfd88941
commit 373e06c98f
1 changed files with 23 additions and 2 deletions

View File

@ -89,8 +89,8 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.SIZE)
val uri = MediaStore.Files.getContentUri("external")
val selection = if (curPath.isEmpty()) null else "(${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?)"
val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%")
val selection = getSelectionQuery(curPath)
val selectionArgs = getSelectionArgsQuery(curPath)
return try {
val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath))
@ -100,6 +100,27 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
}
}
fun Context.getSelectionQuery(path: String): String {
val dataQuery = "${MediaStore.Images.Media.DATA} LIKE ?"
return if (path.isEmpty()) {
var query = "($dataQuery)"
if (hasExternalSDCard()) {
query += " OR ($dataQuery)"
}
query
} else {
"($dataQuery AND ${MediaStore.Images.Media.DATA} NOT LIKE ?)"
}
}
fun Context.getSelectionArgsQuery(path: String): Array<String> {
return if (path.isEmpty()) {
if (hasExternalSDCard()) arrayOf("$internalStoragePath/%", "$sdCardPath/%") else arrayOf("$internalStoragePath/%")
} else {
arrayOf("$path/%", "$path/%/%")
}
}
private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isPickVideo: Boolean, curPath: String): ArrayList<Medium> {
val curMedia = ArrayList<Medium>()
val config = context.config