mirror of
				https://github.com/SimpleMobileTools/Simple-Gallery.git
				synced 2025-06-05 21:59:19 +02:00 
			
		
		
		
	do not try closing the media fetching cursor twice
This commit is contained in:
		| @@ -69,80 +69,78 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP | ||||
|     val showMedia = config.showMedia | ||||
|     val showHidden = config.shouldShowHidden | ||||
|  | ||||
|     cur.use { cur -> | ||||
|         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 noMediaFolders = context.getNoMediaFolders() | ||||
|     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 noMediaFolders = context.getNoMediaFolders() | ||||
|  | ||||
|             do { | ||||
|                 try { | ||||
|                     path = cur.getStringValue(MediaStore.Images.Media.DATA) | ||||
|                     size = cur.getLongValue(MediaStore.Images.Media.SIZE) | ||||
|                     if (size == 0L) { | ||||
|                         size = File(path).length() | ||||
|         do { | ||||
|             try { | ||||
|                 path = cur.getStringValue(MediaStore.Images.Media.DATA) | ||||
|                 size = cur.getLongValue(MediaStore.Images.Media.SIZE) | ||||
|                 if (size == 0L) { | ||||
|                     size = File(path).length() | ||||
|                 } | ||||
|  | ||||
|                 if (size <= 0L) { | ||||
|                     continue | ||||
|                 } | ||||
|  | ||||
|                 filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: "" | ||||
|                 if (filename.isEmpty()) | ||||
|                     filename = path.getFilenameFromPath() | ||||
|  | ||||
|                 isImage = filename.isImageFast() || filename.isGif() | ||||
|                 isVideo = if (isImage) false else filename.isVideoFast() | ||||
|  | ||||
|                 if (!isImage && !isVideo) | ||||
|                     continue | ||||
|  | ||||
|                 if (isVideo && (isPickImage || showMedia == IMAGES)) | ||||
|                     continue | ||||
|  | ||||
|                 if (isImage && (isPickVideo || showMedia == VIDEOS)) | ||||
|                     continue | ||||
|  | ||||
|                 if (!showHidden && filename.startsWith('.')) | ||||
|                     continue | ||||
|  | ||||
|                 var isExcluded = false | ||||
|                 excludedFolders.forEach { | ||||
|                     if (path.startsWith(it)) { | ||||
|                         isExcluded = true | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                     if (size <= 0L) { | ||||
|                         continue | ||||
|                     } | ||||
|  | ||||
|                     filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: "" | ||||
|                     if (filename.isEmpty()) | ||||
|                         filename = path.getFilenameFromPath() | ||||
|  | ||||
|                     isImage = filename.isImageFast() || filename.isGif() | ||||
|                     isVideo = if (isImage) false else filename.isVideoFast() | ||||
|  | ||||
|                     if (!isImage && !isVideo) | ||||
|                         continue | ||||
|  | ||||
|                     if (isVideo && (isPickImage || showMedia == IMAGES)) | ||||
|                         continue | ||||
|  | ||||
|                     if (isImage && (isPickVideo || showMedia == VIDEOS)) | ||||
|                         continue | ||||
|  | ||||
|                     if (!showHidden && filename.startsWith('.')) | ||||
|                         continue | ||||
|  | ||||
|                     var isExcluded = false | ||||
|                     excludedFolders.forEach { | ||||
|                 if (!isExcluded && !showHidden) { | ||||
|                     noMediaFolders.forEach { | ||||
|                         if (path.startsWith(it)) { | ||||
|                             isExcluded = true | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     if (!isExcluded && !showHidden) { | ||||
|                         noMediaFolders.forEach { | ||||
|                             if (path.startsWith(it)) { | ||||
|                                 isExcluded = true | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     if (!isExcluded && !showHidden && path.contains("/.")) { | ||||
|                         isExcluded = true | ||||
|                     } | ||||
|  | ||||
|                     if (!isExcluded) { | ||||
|                         dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) | ||||
|                         dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L | ||||
|  | ||||
|                         val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size) | ||||
|                         curMedia.add(medium) | ||||
|                     } | ||||
|                 } catch (e: Exception) { | ||||
|                     continue | ||||
|                 } | ||||
|             } while (cur.moveToNext()) | ||||
|         } | ||||
|  | ||||
|                 if (!isExcluded && !showHidden && path.contains("/.")) { | ||||
|                     isExcluded = true | ||||
|                 } | ||||
|  | ||||
|                 if (!isExcluded) { | ||||
|                     dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) | ||||
|                     dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L | ||||
|  | ||||
|                     val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size) | ||||
|                     curMedia.add(medium) | ||||
|                 } | ||||
|             } catch (e: Exception) { | ||||
|                 continue | ||||
|             } | ||||
|         } while (cur.moveToNext()) | ||||
|     } | ||||
|  | ||||
|     Medium.sorting = config.getFileSorting(curPath) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user