From 59096651d6581f4f91f8383d454e7bbe583389b1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Jan 2017 23:21:28 +0100 Subject: [PATCH] implement Show All at media view --- .../gallery/asynctasks/GetMediaAsynctask.kt | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) 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 6fc5c0683..8a93acf32 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -5,9 +5,8 @@ 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.helpers.Config -import com.simplemobiletools.gallery.helpers.IMAGES -import com.simplemobiletools.gallery.helpers.VIDEOS +import com.simplemobiletools.gallery.extensions.getParents +import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.* @@ -16,17 +15,36 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : AsyncTask>() { lateinit var mConfig: Config + var showMedia = IMAGES_AND_VIDEOS + var fileSorting = 0 override fun onPreExecute() { super.onPreExecute() mConfig = Config.newInstance(context) + showMedia = mConfig.showMedia + fileSorting = mConfig.fileSorting } override fun doInBackground(vararg params: Void): ArrayList { val media = ArrayList() - val showMedia = mConfig.showMedia - val dir = File(mPath) + if (showAll) { + val parents = context.getParents(isPickImage, isPickVideo) + for (parent in parents) { + media.addAll(getFilesFrom(parent)) + } + } else { + media.addAll(getFilesFrom(mPath)) + } + + Medium.sorting = fileSorting + media.sort() + return media + } + + private fun getFilesFrom(path: String): ArrayList { + val media = ArrayList() + val dir = File(path) val files = dir.listFiles() ?: return media for (file in files) { val isImage = file.isImageFast() || file.isGif() @@ -46,13 +64,10 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo continue val name = file.name - val path = file.absolutePath - val dateModified = file.lastModified() - media.add(Medium(name, path, isVideo, dateModified, dateModified, size)) + val absolutePath = file.absolutePath + val dateModified = if (fileSorting and SORT_BY_DATE_MODIFIED != 0) file.lastModified() else 0 + media.add(Medium(name, absolutePath, isVideo, dateModified, dateModified, size)) } - - Medium.sorting = mConfig.fileSorting - media.sort() return media }