use thoe shorter version of cursor looping
This commit is contained in:
parent
60b44c27be
commit
a7b35e36b2
|
@ -442,10 +442,7 @@ 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 {
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
try {
|
try {
|
||||||
val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN)
|
val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN)
|
||||||
if (dateTaken != 0L) {
|
if (dateTaken != 0L) {
|
||||||
|
@ -454,8 +451,6 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,10 +477,7 @@ 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 {
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
try {
|
try {
|
||||||
val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN)
|
val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN)
|
||||||
if (dateTaken != 0L) {
|
if (dateTaken != 0L) {
|
||||||
|
@ -494,8 +486,6 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
|
@ -521,10 +511,7 @@ 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 {
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
try {
|
try {
|
||||||
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
|
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
|
||||||
if (lastModified != 0L) {
|
if (lastModified != 0L) {
|
||||||
|
@ -533,8 +520,6 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,10 +536,7 @@ 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 {
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
try {
|
try {
|
||||||
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
|
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
|
||||||
if (lastModified != 0L) {
|
if (lastModified != 0L) {
|
||||||
|
@ -563,8 +545,6 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
|
@ -584,10 +564,7 @@ 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 {
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
try {
|
try {
|
||||||
val size = cursor.getLongValue(Images.Media.SIZE)
|
val size = cursor.getLongValue(Images.Media.SIZE)
|
||||||
if (size != 0L) {
|
if (size != 0L) {
|
||||||
|
@ -596,8 +573,6 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue