mirror of
				https://github.com/SimpleMobileTools/Simple-Gallery.git
				synced 2025-06-05 21:59:19 +02:00 
			
		
		
		
	use thoe shorter version of cursor looping
This commit is contained in:
		| @@ -442,19 +442,14 @@ class MediaFetcher(val context: Context) { | |||||||
|             val selection = "${Images.Media.DATA} LIKE ? AND ${Images.Media.DATA} NOT LIKE ?" |             val selection = "${Images.Media.DATA} LIKE ? AND ${Images.Media.DATA} NOT LIKE ?" | ||||||
|             val selectionArgs = arrayOf("$folder/%", "$folder/%/%") |             val selectionArgs = arrayOf("$folder/%", "$folder/%/%") | ||||||
|  |  | ||||||
|             val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) |             context.queryCursor(uri, projection, selection, selectionArgs) { cursor -> | ||||||
|             cursor?.use { |                 try { | ||||||
|                 if (cursor.moveToFirst()) { |                     val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) | ||||||
|                     do { |                     if (dateTaken != 0L) { | ||||||
|                         try { |                         val name = cursor.getStringValue(Images.Media.DISPLAY_NAME) | ||||||
|                             val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) |                         dateTakens["$folder/$name"] = dateTaken | ||||||
|                             if (dateTaken != 0L) { |                     } | ||||||
|                                 val name = cursor.getStringValue(Images.Media.DISPLAY_NAME) |                 } catch (e: Exception) { | ||||||
|                                 dateTakens["$folder/$name"] = dateTaken |  | ||||||
|                             } |  | ||||||
|                         } catch (e: Exception) { |  | ||||||
|                         } |  | ||||||
|                     } while (cursor.moveToNext()) |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -482,19 +477,14 @@ class MediaFetcher(val context: Context) { | |||||||
|         val uri = Files.getContentUri("external") |         val uri = Files.getContentUri("external") | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             val cursor = context.contentResolver.query(uri, projection, null, null, null) |             context.queryCursor(uri, projection) { cursor -> | ||||||
|             cursor?.use { |                 try { | ||||||
|                 if (cursor.moveToFirst()) { |                     val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) | ||||||
|                     do { |                     if (dateTaken != 0L) { | ||||||
|                         try { |                         val path = cursor.getStringValue(Images.Media.DATA) | ||||||
|                             val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) |                         dateTakens[path] = dateTaken | ||||||
|                             if (dateTaken != 0L) { |                     } | ||||||
|                                 val path = cursor.getStringValue(Images.Media.DATA) |                 } catch (e: Exception) { | ||||||
|                                 dateTakens[path] = dateTaken |  | ||||||
|                             } |  | ||||||
|                         } catch (e: Exception) { |  | ||||||
|                         } |  | ||||||
|                     } while (cursor.moveToNext()) |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } catch (e: Exception) { |         } catch (e: Exception) { | ||||||
| @@ -521,19 +511,14 @@ class MediaFetcher(val context: Context) { | |||||||
|             val selection = "${Images.Media.DATA} LIKE ? AND ${Images.Media.DATA} NOT LIKE ?" |             val selection = "${Images.Media.DATA} LIKE ? AND ${Images.Media.DATA} NOT LIKE ?" | ||||||
|             val selectionArgs = arrayOf("$folder/%", "$folder/%/%") |             val selectionArgs = arrayOf("$folder/%", "$folder/%/%") | ||||||
|  |  | ||||||
|             val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) |             context.queryCursor(uri, projection, selection, selectionArgs) { cursor -> | ||||||
|             cursor?.use { |                 try { | ||||||
|                 if (cursor.moveToFirst()) { |                     val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 | ||||||
|                     do { |                     if (lastModified != 0L) { | ||||||
|                         try { |                         val name = cursor.getStringValue(Images.Media.DISPLAY_NAME) | ||||||
|                             val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 |                         lastModifieds["$folder/$name"] = lastModified | ||||||
|                             if (lastModified != 0L) { |                     } | ||||||
|                                 val name = cursor.getStringValue(Images.Media.DISPLAY_NAME) |                 } catch (e: Exception) { | ||||||
|                                 lastModifieds["$folder/$name"] = lastModified |  | ||||||
|                             } |  | ||||||
|                         } catch (e: Exception) { |  | ||||||
|                         } |  | ||||||
|                     } while (cursor.moveToNext()) |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -551,19 +536,14 @@ class MediaFetcher(val context: Context) { | |||||||
|         val uri = Files.getContentUri("external") |         val uri = Files.getContentUri("external") | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             val cursor = context.contentResolver.query(uri, projection, null, null, null) |             context.queryCursor(uri, projection) { cursor -> | ||||||
|             cursor?.use { |                 try { | ||||||
|                 if (cursor.moveToFirst()) { |                     val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 | ||||||
|                     do { |                     if (lastModified != 0L) { | ||||||
|                         try { |                         val path = cursor.getStringValue(Images.Media.DATA) | ||||||
|                             val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 |                         lastModifieds[path] = lastModified | ||||||
|                             if (lastModified != 0L) { |                     } | ||||||
|                                 val path = cursor.getStringValue(Images.Media.DATA) |                 } catch (e: Exception) { | ||||||
|                                 lastModifieds[path] = lastModified |  | ||||||
|                             } |  | ||||||
|                         } catch (e: Exception) { |  | ||||||
|                         } |  | ||||||
|                     } while (cursor.moveToNext()) |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } catch (e: Exception) { |         } catch (e: Exception) { | ||||||
| @@ -584,19 +564,14 @@ class MediaFetcher(val context: Context) { | |||||||
|             val selection = "${Images.Media.DATA} LIKE ? AND ${Images.Media.DATA} NOT LIKE ?" |             val selection = "${Images.Media.DATA} LIKE ? AND ${Images.Media.DATA} NOT LIKE ?" | ||||||
|             val selectionArgs = arrayOf("$folder/%", "$folder/%/%") |             val selectionArgs = arrayOf("$folder/%", "$folder/%/%") | ||||||
|  |  | ||||||
|             val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) |             context.queryCursor(uri, projection, selection, selectionArgs) { cursor -> | ||||||
|             cursor?.use { |                 try { | ||||||
|                 if (cursor.moveToFirst()) { |                     val size = cursor.getLongValue(Images.Media.SIZE) | ||||||
|                     do { |                     if (size != 0L) { | ||||||
|                         try { |                         val name = cursor.getStringValue(Images.Media.DISPLAY_NAME) | ||||||
|                             val size = cursor.getLongValue(Images.Media.SIZE) |                         sizes["$folder/$name"] = size | ||||||
|                             if (size != 0L) { |                     } | ||||||
|                                 val name = cursor.getStringValue(Images.Media.DISPLAY_NAME) |                 } catch (e: Exception) { | ||||||
|                                 sizes["$folder/$name"] = size |  | ||||||
|                             } |  | ||||||
|                         } catch (e: Exception) { |  | ||||||
|                         } |  | ||||||
|                     } while (cursor.moveToNext()) |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user