Last active
September 21, 2022 17:50
-
-
Save Priyansh-Kedia/b09b87d587412ecc2a978c3fec00546f to your computer and use it in GitHub Desktop.
Document Repo for Pagination in MediaStore API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun getImages(count: Int, start: Int): Three<MutableList<Three<Uri?, String?, Date>>, Boolean, Int> { | |
val imagesList = mutableListOf<Three<Uri?, String?, Date>>() | |
var index = start | |
return withContext(Dispatchers.IO) { | |
while (imageCursor?.moveToPosition(i) == true) { | |
val id = imageIdColumn?.let { imageCursor.getLong(it) } | |
val dateModified = Date(TimeUnit.SECONDS.toMillis(imageCursor.getLong(imageDateModifiedColumn ?: 0))) | |
val displayName = imageDisplayNameColumn?.let { imageCursor.getString(it) } | |
val contentUri = id?.let { | |
ContentUris.withAppendedId( | |
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, | |
it | |
) | |
} | |
index++ | |
contentUri?.let { imagesList.add(Three(contentUri, displayName, dateModified)) } | |
if (index == count) | |
break | |
} | |
val areAllLoaded = index == imagesToLoad | |
return@withContext Three(imagesList, areAllLoaded, index) | |
} | |
} |
Hello @jeyk-digikraft
ImageCursor is created using the default method. Adding the code here too.
private val imageCursor = context.contentResolver.query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, ImagePicker.imageProjection, null, null, ImagePicker.imageSortOrder )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
imageCursor, are missed ?