catch exceptions thrown during media obtaining
This commit is contained in:
parent
52126c4d8f
commit
b564da6b91
1 changed files with 44 additions and 36 deletions
|
@ -139,53 +139,61 @@ 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))
|
||||||
if (cur.moveToFirst()) {
|
try {
|
||||||
var filename: String
|
if (cur.moveToFirst()) {
|
||||||
var path: String
|
var filename: String
|
||||||
var dateTaken: Long
|
var path: String
|
||||||
var dateModified: Long
|
var dateTaken: Long
|
||||||
var size: Long
|
var dateModified: Long
|
||||||
var isImage: Boolean
|
var size: Long
|
||||||
var isVideo: Boolean
|
var isImage: Boolean
|
||||||
|
var isVideo: Boolean
|
||||||
|
|
||||||
do {
|
|
||||||
path = cur.getStringValue(MediaStore.Images.Media.DATA)
|
|
||||||
size = cur.getLongValue(MediaStore.Images.Media.SIZE)
|
|
||||||
if (size == 0L) {
|
|
||||||
size = File(path).length()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size <= 0L) {
|
do {
|
||||||
continue
|
try {
|
||||||
}
|
path = cur.getStringValue(MediaStore.Images.Media.DATA)
|
||||||
|
size = cur.getLongValue(MediaStore.Images.Media.SIZE)
|
||||||
|
if (size == 0L) {
|
||||||
|
size = File(path).length()
|
||||||
|
}
|
||||||
|
|
||||||
filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
|
if (size <= 0L) {
|
||||||
if (filename.isEmpty())
|
continue
|
||||||
filename = path.getFilenameFromPath()
|
}
|
||||||
|
|
||||||
isImage = filename.isImageFast() || filename.isGif()
|
filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
|
||||||
isVideo = if (isImage) false else filename.isVideoFast()
|
if (filename.isEmpty())
|
||||||
|
filename = path.getFilenameFromPath()
|
||||||
|
|
||||||
if (!isImage && !isVideo)
|
isImage = filename.isImageFast() || filename.isGif()
|
||||||
continue
|
isVideo = if (isImage) false else filename.isVideoFast()
|
||||||
|
|
||||||
if (isVideo && (isPickImage || showMedia == IMAGES))
|
if (!isImage && !isVideo)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (isImage && (isPickVideo || showMedia == VIDEOS))
|
if (isVideo && (isPickImage || showMedia == IMAGES))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (!showHidden && filename.startsWith('.'))
|
if (isImage && (isPickVideo || showMedia == VIDEOS))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
if (!showHidden && filename.startsWith('.'))
|
||||||
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
continue
|
||||||
|
|
||||||
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
|
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||||
curMedia.add(medium)
|
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
||||||
} while (cur.moveToNext())
|
|
||||||
|
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
|
||||||
|
curMedia.add(medium)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} while (cur.moveToNext())
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cur.close()
|
||||||
}
|
}
|
||||||
cur.close()
|
|
||||||
|
|
||||||
Medium.sorting = config.getFileSorting(curPath)
|
Medium.sorting = config.getFileSorting(curPath)
|
||||||
curMedia.sort()
|
curMedia.sort()
|
||||||
|
|
Loading…
Reference in a new issue