optimize getting media with Show All

This commit is contained in:
tibbi 2017-05-20 16:49:01 +02:00
parent 987f333c5c
commit 3a98da85fe

View file

@ -5,7 +5,6 @@ import android.os.AsyncTask
import android.provider.MediaStore import android.provider.MediaStore
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getParents
import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.IMAGES
import com.simplemobiletools.gallery.helpers.IMAGES_AND_VIDEOS import com.simplemobiletools.gallery.helpers.IMAGES_AND_VIDEOS
import com.simplemobiletools.gallery.helpers.VIDEOS import com.simplemobiletools.gallery.helpers.VIDEOS
@ -31,16 +30,14 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
override fun doInBackground(vararg params: Void): Unit { override fun doInBackground(vararg params: Void): Unit {
if (showAll) { if (showAll) {
val parents = context.getParents() getFilesFrom("")
for (parent in parents) {
getFilesFrom(parent)
}
} else { } else {
getFilesFrom(mPath) getFilesFrom(mPath)
} }
Medium.sorting = fileSorting Medium.sorting = fileSorting
media.sort() media.sort()
return Unit return Unit
} }
@ -52,8 +49,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATA,
MediaStore.Images.Media.SIZE) MediaStore.Images.Media.SIZE)
val uri = MediaStore.Files.getContentUri("external") val uri = MediaStore.Files.getContentUri("external")
val selection = "${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?" val selection = if (curPath.isEmpty()) null else "(${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?)"
val selectionArgs = arrayOf("$curPath/%", "$curPath/%/%") val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%")
val cur = context.contentResolver.query(uri, projection, selection, selectionArgs, null) val cur = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
if (cur.moveToFirst()) { if (cur.moveToFirst()) {
@ -62,6 +59,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
var dateTaken: Long var dateTaken: Long
var dateModified: Long var dateModified: Long
var size: Long var size: Long
var isImage: Boolean
var isVideo: Boolean
do { do {
if (shouldStop) if (shouldStop)
@ -81,8 +80,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
if (filename.isEmpty()) if (filename.isEmpty())
filename = path.getFilenameFromPath() filename = path.getFilenameFromPath()
val isImage = filename.isImageFast() || filename.isGif() isImage = filename.isImageFast() || filename.isGif()
val isVideo = if (isImage) false else filename.isVideoFast() isVideo = if (isImage) false else filename.isVideoFast()
if (!isImage && !isVideo) if (!isImage && !isVideo)
continue continue