switch to the new way of getting images again, with some tweak later
This commit is contained in:
parent
720f2ea312
commit
23d85f6ff9
1 changed files with 45 additions and 43 deletions
|
@ -4,7 +4,7 @@ import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import com.simplemobiletools.commons.extensions.scanFiles
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.gallery.extensions.getLongValue
|
import com.simplemobiletools.gallery.extensions.getLongValue
|
||||||
import com.simplemobiletools.gallery.extensions.getStringValue
|
import com.simplemobiletools.gallery.extensions.getStringValue
|
||||||
import com.simplemobiletools.gallery.helpers.Config
|
import com.simplemobiletools.gallery.helpers.Config
|
||||||
|
@ -28,17 +28,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
val media = ArrayList<Medium>()
|
val media = ArrayList<Medium>()
|
||||||
val invalidFiles = ArrayList<File>()
|
val invalidFiles = ArrayList<File>()
|
||||||
val showMedia = mConfig.showMedia
|
val showMedia = mConfig.showMedia
|
||||||
for (i in 0..1) {
|
val uri = MediaStore.Files.getContentUri("external")
|
||||||
if (i == 0 && (isPickVideo || showMedia == VIDEOS))
|
|
||||||
continue
|
|
||||||
|
|
||||||
var uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
|
|
||||||
if (i == 1) {
|
|
||||||
if (isPickImage || showMedia == IMAGES)
|
|
||||||
continue
|
|
||||||
|
|
||||||
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
|
||||||
}
|
|
||||||
val where = "${MediaStore.Images.Media.DATA} LIKE ?"
|
val where = "${MediaStore.Images.Media.DATA} LIKE ?"
|
||||||
val checkPath = if (showAll) "%" else "$mPath%"
|
val checkPath = if (showAll) "%" else "$mPath%"
|
||||||
val args = arrayOf(checkPath)
|
val args = arrayOf(checkPath)
|
||||||
|
@ -48,7 +38,6 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(uri, columns, where, args, null)
|
cursor = context.contentResolver.query(uri, columns, where, args, null)
|
||||||
|
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val curPath = cursor.getStringValue(MediaStore.Images.Media.DATA) ?: continue
|
val curPath = cursor.getStringValue(MediaStore.Images.Media.DATA) ?: continue
|
||||||
|
@ -64,16 +53,29 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
if (!showAll && file.parent != mPath)
|
if (!showAll && file.parent != mPath)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
|
var name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
|
||||||
|
val isImage = file.isImageFast() || file.isGif()
|
||||||
|
val isVideo = file.isVideoFast()
|
||||||
|
|
||||||
|
if (!isImage && !isVideo)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (isVideo && (isPickImage || showMedia == IMAGES))
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (isImage && (isPickVideo || showMedia == VIDEOS))
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (name.isEmpty())
|
||||||
|
name = curPath.getFilenameFromPath()
|
||||||
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
||||||
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||||
media.add(Medium(name, curPath, i == 1, dateModified, dateTaken, size))
|
media.add(Medium(name, curPath, isVideo, dateModified, dateTaken, size))
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
context.scanFiles(invalidFiles) {}
|
context.scanFiles(invalidFiles) {}
|
||||||
Medium.sorting = mConfig.fileSorting
|
Medium.sorting = mConfig.fileSorting
|
||||||
|
|
Loading…
Reference in a new issue