use local variables at fetching media

This commit is contained in:
tibbi 2017-06-06 22:47:16 +02:00
parent 3de178a5eb
commit 0f135c845b

View file

@ -73,20 +73,13 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
cur.use { cur -> cur.use { cur ->
if (cur.moveToFirst()) { if (cur.moveToFirst()) {
var filename: String
var path: String
var dateTaken: Long
var dateModified: Long
var size: Long
var isImage: Boolean
var isVideo: Boolean
val excludedFolders = config.excludedFolders val excludedFolders = config.excludedFolders
val noMediaFolders = context.getNoMediaFolders() val noMediaFolders = context.getNoMediaFolders()
do { do {
try { try {
path = cur.getStringValue(MediaStore.Images.Media.DATA) val path = cur.getStringValue(MediaStore.Images.Media.DATA)
size = cur.getLongValue(MediaStore.Images.Media.SIZE) var size = cur.getLongValue(MediaStore.Images.Media.SIZE)
if (size == 0L) { if (size == 0L) {
size = File(path).length() size = File(path).length()
} }
@ -95,12 +88,12 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
continue continue
} }
filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: "" var filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
if (filename.isEmpty()) if (filename.isEmpty())
filename = path.getFilenameFromPath() filename = path.getFilenameFromPath()
isImage = filename.isImageFast() || filename.isGif() val isImage = filename.isImageFast() || filename.isGif()
isVideo = if (isImage) false else filename.isVideoFast() val isVideo = if (isImage) false else filename.isVideoFast()
if (!isImage && !isVideo) if (!isImage && !isVideo)
continue continue
@ -134,8 +127,8 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
} }
if (!isExcluded) { if (!isExcluded) {
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size) val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
curMedia.add(medium) curMedia.add(medium)