mirror of
https://github.com/SimpleMobileTools/Simple-Gallery.git
synced 2024-12-28 09:11:44 +01:00
sort the media already at fetching from mediastore, to save time
This commit is contained in:
parent
2a7baf14d2
commit
06fe8a669a
@ -4,6 +4,10 @@ import android.content.Context
|
||||
import android.os.AsyncTask
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.helpers.IMAGES
|
||||
import com.simplemobiletools.gallery.helpers.VIDEOS
|
||||
@ -24,9 +28,6 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||
media = getFilesFrom(mPath)
|
||||
}
|
||||
|
||||
Medium.sorting = context.config.getFileSorting(mPath)
|
||||
media.sort()
|
||||
|
||||
return Unit
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||
val selection = if (curPath.isEmpty()) null else "(${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?)"
|
||||
val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%")
|
||||
|
||||
val cur = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
val cur = context.contentResolver.query(uri, projection, selection, selectionArgs, getSorting())
|
||||
if (cur.moveToFirst()) {
|
||||
var filename: String
|
||||
var path: String
|
||||
@ -95,9 +96,30 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||
} while (cur.moveToNext())
|
||||
}
|
||||
cur.close()
|
||||
|
||||
Medium.sorting = context.config.getFileSorting(mPath)
|
||||
curMedia.sort()
|
||||
|
||||
return curMedia
|
||||
}
|
||||
|
||||
private fun getSorting(): String {
|
||||
val sorting = context.config.getFileSorting(mPath)
|
||||
val sortValue = if (sorting and SORT_BY_NAME > 0)
|
||||
MediaStore.Images.Media.DISPLAY_NAME
|
||||
else if (sorting and SORT_BY_SIZE > 0)
|
||||
MediaStore.Images.Media.SIZE
|
||||
else if (sorting and SORT_BY_DATE_MODIFIED > 0)
|
||||
MediaStore.Images.Media.DATE_MODIFIED
|
||||
else
|
||||
MediaStore.Images.Media.DATE_TAKEN
|
||||
|
||||
return if (sorting and SORT_DESCENDING > 0)
|
||||
"$sortValue DESC"
|
||||
else
|
||||
"$sortValue ASC"
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: Unit?) {
|
||||
super.onPostExecute(result)
|
||||
callback.invoke(media)
|
||||
|
Loading…
Reference in New Issue
Block a user