diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 688c1f099..82e086d31 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -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) { super.onPostExecute(media) callback.invoke(media)