mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 14:28:00 +01:00
update getmedia asynctask
This commit is contained in:
parent
c7625554ba
commit
2cf58c2e1e
1 changed files with 6 additions and 10 deletions
|
@ -2,6 +2,9 @@ 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 com.simplemobiletools.commons.extensions.isImageFast
|
||||||
|
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
|
||||||
|
@ -17,8 +20,6 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
var config = context.config
|
var config = context.config
|
||||||
var showMedia = IMAGES_AND_VIDEOS
|
var showMedia = IMAGES_AND_VIDEOS
|
||||||
var fileSorting = 0
|
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() {
|
override fun onPreExecute() {
|
||||||
super.onPreExecute()
|
super.onPreExecute()
|
||||||
|
@ -49,8 +50,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
val files = dir.listFiles() ?: return media
|
val files = dir.listFiles() ?: return media
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
val filePath = file.absolutePath
|
val filePath = file.absolutePath
|
||||||
val isImage = localIsImage(filePath) || localIsGif(filePath)
|
val isImage = filePath.isImageFast() || filePath.isGif()
|
||||||
val isVideo = if (isImage) false else localIsVideo(filePath)
|
val isVideo = if (isImage) false else filePath.isVideoFast()
|
||||||
|
|
||||||
if (!isImage && !isVideo)
|
if (!isImage && !isVideo)
|
||||||
continue
|
continue
|
||||||
|
@ -66,17 +67,12 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val name = file.name
|
val name = file.name
|
||||||
val absolutePath = file.absolutePath
|
|
||||||
val dateModified = file.lastModified()
|
val dateModified = file.lastModified()
|
||||||
media.add(Medium(name, absolutePath, isVideo, dateModified, dateModified, 0))
|
media.add(Medium(name, filePath, isVideo, dateModified, dateModified, size))
|
||||||
}
|
}
|
||||||
return media
|
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>) {
|
override fun onPostExecute(media: ArrayList<Medium>) {
|
||||||
super.onPostExecute(media)
|
super.onPostExecute(media)
|
||||||
callback.invoke(media)
|
callback.invoke(media)
|
||||||
|
|
Loading…
Reference in a new issue