mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
go back to the mediastore way of fetching media
This commit is contained in:
parent
b2f9bbdf2c
commit
cc814d8d45
1 changed files with 51 additions and 26 deletions
|
@ -2,9 +2,8 @@ package com.simplemobiletools.gallery.asynctasks
|
|||
|
||||
import android.content.Context
|
||||
import android.os.AsyncTask
|
||||
import com.simplemobiletools.commons.extensions.isGif
|
||||
import com.simplemobiletools.commons.extensions.isImageFast
|
||||
import com.simplemobiletools.commons.extensions.isVideoFast
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.extensions.getParents
|
||||
import com.simplemobiletools.gallery.helpers.IMAGES
|
||||
|
@ -45,13 +44,40 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
|||
return Unit
|
||||
}
|
||||
|
||||
private fun getFilesFrom(path: String) {
|
||||
val dir = File(path)
|
||||
val filenames = dir.list() ?: return
|
||||
for (filename in filenames) {
|
||||
private fun getFilesFrom(curPath: String) {
|
||||
val projection = arrayOf(MediaStore.Images.Media._ID,
|
||||
MediaStore.Images.Media.DISPLAY_NAME,
|
||||
MediaStore.Images.Media.DATE_TAKEN,
|
||||
MediaStore.Images.Media.DATE_MODIFIED,
|
||||
MediaStore.Images.Media.DATA,
|
||||
MediaStore.Images.Media.SIZE)
|
||||
val uri = MediaStore.Files.getContentUri("external")
|
||||
val selection = "${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?"
|
||||
val selectionArgs = arrayOf("$curPath/%", "$curPath/%/%")
|
||||
|
||||
val cur = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
if (cur.moveToFirst()) {
|
||||
var filename: String
|
||||
var path: String
|
||||
var dateTaken: Long
|
||||
var dateModified: Long
|
||||
var size: Long
|
||||
|
||||
do {
|
||||
if (shouldStop)
|
||||
cancel(true)
|
||||
|
||||
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) ?: ""
|
||||
val isImage = filename.isImageFast() || filename.isGif()
|
||||
val isVideo = if (isImage) false else filename.isVideoFast()
|
||||
|
||||
|
@ -67,15 +93,14 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
|||
if (!showHidden && filename.startsWith('.'))
|
||||
continue
|
||||
|
||||
val file = File(path, filename)
|
||||
val size = file.length()
|
||||
if (size == 0L)
|
||||
continue
|
||||
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
||||
|
||||
val dateModified = file.lastModified()
|
||||
val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size)
|
||||
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
|
||||
media.add(medium)
|
||||
} while (cur.moveToNext())
|
||||
}
|
||||
cur.close()
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: Unit?) {
|
||||
|
|
Loading…
Reference in a new issue