add some null checks to obtaining directories

This commit is contained in:
tibbi 2017-01-22 18:53:32 +01:00
parent d1995d129a
commit 9773a481c8

View file

@ -54,7 +54,7 @@ fun Context.getParents(isPickImage: Boolean, isPickVideo: Boolean): ArrayList<St
cursor = contentResolver.query(uri, columns, where, args, null) cursor = contentResolver.query(uri, columns, where, args, null)
if (cursor?.moveToFirst() == true) { if (cursor?.moveToFirst() == true) {
do { do {
val curPath = cursor.getStringValue(MediaStore.Images.Media.DATA) val curPath = cursor.getStringValue(MediaStore.Images.Media.DATA) ?: ""
parents.add(File(curPath).parent) parents.add(File(curPath).parent)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
@ -62,8 +62,10 @@ fun Context.getParents(isPickImage: Boolean, isPickVideo: Boolean): ArrayList<St
cursor?.close() cursor?.close()
} }
filterDirectories(parents) val notNull = ArrayList<String>()
return parents parents.mapNotNullTo(notNull, { it })
filterDirectories(notNull)
return notNull
} }
fun Context.getWhereCondition(isPickImage: Boolean, isPickVideo: Boolean): String { fun Context.getWhereCondition(isPickImage: Boolean, isPickVideo: Boolean): String {
@ -86,7 +88,7 @@ fun Context.getArgs(isPickImage: Boolean, isPickVideo: Boolean): Array<String> {
} }
} }
fun Context.filterDirectories(dirs: MutableList<String>) { fun Context.filterDirectories(dirs: ArrayList<String>) {
if (!config.showHiddenFolders) { if (!config.showHiddenFolders) {
removeHiddenFolders(dirs) removeHiddenFolders(dirs)
removeNoMediaFolders(dirs) removeNoMediaFolders(dirs)