update getmedia asynctask

This commit is contained in:
tibbi 2017-02-25 11:01:40 +01:00
parent c7625554ba
commit 2cf58c2e1e

View File

@ -2,6 +2,9 @@ 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 com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getParents
import com.simplemobiletools.gallery.helpers.IMAGES
@ -17,8 +20,6 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
var config = context.config
var showMedia = IMAGES_AND_VIDEOS
var fileSorting = 0
val photoExtensions = arrayOf("jpg", "png", "jpeg", "bmp", "webp", "tiff")
val videoExtensions = arrayOf("webm", "mkv", "flv", "vob", "avi", "wmv", "mp4", "ogv", "qt", "m4p", "mpg", "m4v", "mp2", "mpeg", "3gp")
override fun onPreExecute() {
super.onPreExecute()
@ -49,8 +50,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
val files = dir.listFiles() ?: return media
for (file in files) {
val filePath = file.absolutePath
val isImage = localIsImage(filePath) || localIsGif(filePath)
val isVideo = if (isImage) false else localIsVideo(filePath)
val isImage = filePath.isImageFast() || filePath.isGif()
val isVideo = if (isImage) false else filePath.isVideoFast()
if (!isImage && !isVideo)
continue
@ -66,17 +67,12 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
continue
val name = file.name
val absolutePath = file.absolutePath
val dateModified = file.lastModified()
media.add(Medium(name, absolutePath, isVideo, dateModified, dateModified, 0))
media.add(Medium(name, filePath, isVideo, dateModified, dateModified, size))
}
return media
}
private fun localIsImage(path: String) = photoExtensions.any { path.endsWith(".$it", true) }
private fun localIsGif(path: String) = path.endsWith(".gif", true)
private fun localIsVideo(path: String) = videoExtensions.any { path.endsWith(".$it", true) }
override fun onPostExecute(media: ArrayList<Medium>) {
super.onPostExecute(media)
callback.invoke(media)