diff --git a/app/build.gradle b/app/build.gradle index 536cca47b..f65588e21 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.15.2' + compile 'com.simplemobiletools:commons:2.15.3' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' 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 5621cf61c..0eb31c6c6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -16,11 +16,12 @@ import java.util.* class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo: Boolean = false, val isPickImage: Boolean = false, val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : - AsyncTask>() { + AsyncTask() { var config = context.config var showMedia = IMAGES_AND_VIDEOS var fileSorting = 0 var shouldStop = false + var media = ArrayList() override fun onPreExecute() { super.onPreExecute() @@ -28,27 +29,24 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo fileSorting = config.getFileSorting(mPath) } - override fun doInBackground(vararg params: Void): ArrayList { - val media = ArrayList() - + override fun doInBackground(vararg params: Void): Unit { if (showAll) { val parents = context.getParents() for (parent in parents) { - media.addAll(getFilesFrom(parent)) + getFilesFrom(parent) } } else { - media.addAll(getFilesFrom(mPath)) + getFilesFrom(mPath) } Medium.sorting = fileSorting media.sort() - return media + return Unit } - private fun getFilesFrom(path: String): ArrayList { - val media = ArrayList() + private fun getFilesFrom(path: String) { val dir = File(path) - val filenames = dir.list() ?: return media + val filenames = dir.list() ?: return for (filename in filenames) { if (shouldStop) cancel(true) @@ -71,13 +69,13 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo continue val dateModified = file.lastModified() - media.add(Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size)) + val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size) + media.add(medium) } - return media } - override fun onPostExecute(media: ArrayList) { - super.onPostExecute(media) + override fun onPostExecute(result: Unit?) { + super.onPostExecute(result) callback.invoke(media) } }