mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
adding a helper function for fetching media store IDs from file paths
This commit is contained in:
parent
e268927756
commit
3781ee1f04
2 changed files with 41 additions and 0 deletions
|
@ -1045,3 +1045,18 @@ fun Context.getFileDateTaken(path: String): Long {
|
|||
|
||||
return 0L
|
||||
}
|
||||
|
||||
fun Context.getFileUrisFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<Uri> {
|
||||
val fileUris = ArrayList<Uri>()
|
||||
val allIds = MediaFetcher(this).getMediaStoreIds()
|
||||
val filePaths = fileDirItems.map { it.path.lowercase(Locale.getDefault()) }
|
||||
for ((filePath, mediaStoreId) in allIds) {
|
||||
if (filePaths.contains(filePath.lowercase(Locale.getDefault()))) {
|
||||
val baseUri = getFileUri(filePath)
|
||||
val uri = ContentUris.withAppendedId(baseUri, mediaStoreId)
|
||||
fileUris.add(uri)
|
||||
}
|
||||
}
|
||||
|
||||
return fileUris
|
||||
}
|
||||
|
|
|
@ -606,6 +606,32 @@ class MediaFetcher(val context: Context) {
|
|||
return sizes
|
||||
}
|
||||
|
||||
fun getMediaStoreIds(): HashMap<String, Long> {
|
||||
val ids = HashMap<String, Long>()
|
||||
val projection = arrayOf(
|
||||
Images.Media.DATA,
|
||||
Images.Media._ID
|
||||
)
|
||||
|
||||
val uri = Files.getContentUri("external")
|
||||
|
||||
try {
|
||||
context.queryCursor(uri, projection) { cursor ->
|
||||
try {
|
||||
val id = cursor.getLongValue(Images.Media._ID)
|
||||
if (id != 0L) {
|
||||
val path = cursor.getStringValue(Images.Media.DATA)
|
||||
ids[path] = id
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
fun sortMedia(media: ArrayList<Medium>, sorting: Int) {
|
||||
if (sorting and SORT_BY_RANDOM != 0) {
|
||||
media.shuffle()
|
||||
|
|
Loading…
Reference in a new issue