split the media getter into 2 functions

This commit is contained in:
tibbi 2017-05-24 23:02:33 +02:00
parent e1b461e2f1
commit faf1e19a87

View file

@ -47,9 +47,6 @@ fun Context.launchSettings() {
val Context.config: Config get() = Config.newInstance(this) val Context.config: Config get() = Config.newInstance(this)
fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean): ArrayList<Medium> { fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean): ArrayList<Medium> {
val curMedia = ArrayList<Medium>()
val showMedia = config.showMedia
val showHidden = config.shouldShowHidden
val projection = arrayOf(MediaStore.Images.Media._ID, val projection = arrayOf(MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.DATE_TAKEN,
@ -61,7 +58,18 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%") val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%")
val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath)) val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath))
try { cur.use { cur ->
return parseCursor(this, cur, isPickImage, isPickVideo, curPath)
}
}
private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isPickVideo: Boolean, curPath: String): ArrayList<Medium> {
val curMedia = ArrayList<Medium>()
val config = context.config
val showMedia = config.showMedia
val showHidden = config.shouldShowHidden
cur.use { cur ->
if (cur.moveToFirst()) { if (cur.moveToFirst()) {
var filename: String var filename: String
var path: String var path: String
@ -71,7 +79,7 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
var isImage: Boolean var isImage: Boolean
var isVideo: Boolean var isVideo: Boolean
val excludedFolders = config.excludedFolders val excludedFolders = config.excludedFolders
val noMediaFolders = getNoMediaFolders() val noMediaFolders = context.getNoMediaFolders()
do { do {
try { try {
@ -135,8 +143,6 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
} }
} while (cur.moveToNext()) } while (cur.moveToNext())
} }
} finally {
cur.close()
} }
Medium.sorting = config.getFileSorting(curPath) Medium.sorting = config.getFileSorting(curPath)