mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +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.content.Context
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import com.simplemobiletools.commons.extensions.isGif
|
import android.provider.MediaStore
|
||||||
import com.simplemobiletools.commons.extensions.isImageFast
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.isVideoFast
|
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.getParents
|
import com.simplemobiletools.gallery.extensions.getParents
|
||||||
import com.simplemobiletools.gallery.helpers.IMAGES
|
import com.simplemobiletools.gallery.helpers.IMAGES
|
||||||
|
@ -45,13 +44,40 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
return Unit
|
return Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFilesFrom(path: String) {
|
private fun getFilesFrom(curPath: String) {
|
||||||
val dir = File(path)
|
val projection = arrayOf(MediaStore.Images.Media._ID,
|
||||||
val filenames = dir.list() ?: return
|
MediaStore.Images.Media.DISPLAY_NAME,
|
||||||
for (filename in filenames) {
|
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)
|
if (shouldStop)
|
||||||
cancel(true)
|
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 isImage = filename.isImageFast() || filename.isGif()
|
||||||
val isVideo = if (isImage) false else filename.isVideoFast()
|
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('.'))
|
if (!showHidden && filename.startsWith('.'))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val file = File(path, filename)
|
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||||
val size = file.length()
|
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
||||||
if (size == 0L)
|
|
||||||
continue
|
|
||||||
|
|
||||||
val dateModified = file.lastModified()
|
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
|
||||||
val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size)
|
|
||||||
media.add(medium)
|
media.add(medium)
|
||||||
|
} while (cur.moveToNext())
|
||||||
}
|
}
|
||||||
|
cur.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPostExecute(result: Unit?) {
|
override fun onPostExecute(result: Unit?) {
|
||||||
|
|
Loading…
Reference in a new issue