improve the performance of fetching Android 11+ files, use the MediaStore
This commit is contained in:
parent
0224dc56c1
commit
dae13c0261
4 changed files with 30 additions and 17 deletions
|
@ -873,12 +873,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
|
||||
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
|
||||
val favoritePaths = getFavoritePaths()
|
||||
|
||||
/*if (isRPlus()) {
|
||||
mLastMediaFetcher!!.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths)
|
||||
return
|
||||
}*/
|
||||
|
||||
val hiddenString = getString(R.string.hidden)
|
||||
val albumCovers = config.parseAlbumCovers()
|
||||
val includedFolders = config.includedFolders
|
||||
|
@ -913,6 +907,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
}
|
||||
}
|
||||
|
||||
val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths)
|
||||
try {
|
||||
for (directory in dirs) {
|
||||
if (mShouldStopFetching || isDestroyed || isFinishing) {
|
||||
|
@ -933,7 +928,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
|
||||
val curMedia = mLastMediaFetcher!!.getFilesFrom(
|
||||
directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
|
||||
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens
|
||||
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens, android11Files
|
||||
)
|
||||
|
||||
val newDir = if (curMedia.isEmpty()) {
|
||||
|
@ -1040,7 +1035,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
|
||||
val newMedia = mLastMediaFetcher!!.getFilesFrom(
|
||||
folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
|
||||
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens
|
||||
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens, android11Files
|
||||
)
|
||||
|
||||
if (newMedia.isEmpty()) {
|
||||
|
|
|
@ -38,7 +38,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
|
|||
val media = ArrayList<Medium>()
|
||||
foldersToScan.forEach {
|
||||
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, getVideoDurations, lastModifieds, dateTakens)
|
||||
favoritePaths, getVideoDurations, lastModifieds, dateTakens, null)
|
||||
media.addAll(newMedia)
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
|
|||
media
|
||||
} else {
|
||||
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths,
|
||||
getVideoDurations, lastModifieds, dateTakens)
|
||||
getVideoDurations, lastModifieds, dateTakens, null)
|
||||
}
|
||||
|
||||
return mediaFetcher.groupMedia(media, pathToUse)
|
||||
|
|
|
@ -1071,7 +1071,7 @@ fun Context.updateDirectoryPath(path: String) {
|
|||
val favoritePaths = getFavoritePaths()
|
||||
val curMedia = mediaFetcher.getFilesFrom(
|
||||
path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, false, lastModifieds, dateTakens
|
||||
favoritePaths, false, lastModifieds, dateTakens, null
|
||||
)
|
||||
val directory = createDirectoryFromMedia(path, curMedia, albumCovers, hiddenString, includedFolders, getProperFileSize, noMediaFolders)
|
||||
updateDBDirectory(directory)
|
||||
|
|
|
@ -25,10 +25,11 @@ import java.util.*
|
|||
class MediaFetcher(val context: Context) {
|
||||
var shouldStop = false
|
||||
|
||||
// on Android 11 we fetch all files at once from MediaStore and have it split by folder, use it if available
|
||||
fun getFilesFrom(
|
||||
curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperLastModified: Boolean,
|
||||
getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean,
|
||||
lastModifieds: HashMap<String, Long>, dateTakens: HashMap<String, Long>
|
||||
lastModifieds: HashMap<String, Long>, dateTakens: HashMap<String, Long>, android11Files: HashMap<String, ArrayList<Medium>>?
|
||||
): ArrayList<Medium> {
|
||||
val filterMedia = context.config.filterMedia
|
||||
if (filterMedia == 0) {
|
||||
|
@ -42,12 +43,25 @@ class MediaFetcher(val context: Context) {
|
|||
curMedia.addAll(newMedia)
|
||||
}
|
||||
} else {
|
||||
if (isRPlus() && curPath != FAVORITES && curPath != RECYCLE_BIN) {
|
||||
if (android11Files?.containsKey(curPath.toLowerCase()) == true) {
|
||||
curMedia.addAll(android11Files[curPath.toLowerCase()]!!)
|
||||
} else {
|
||||
val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths)
|
||||
if (files.containsKey(curPath.toLowerCase())) {
|
||||
curMedia.addAll(files[curPath.toLowerCase()]!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (curMedia.isEmpty()) {
|
||||
val newMedia = getMediaInFolder(
|
||||
curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, getVideoDurations, lastModifieds.clone() as HashMap<String, Long>, dateTakens.clone() as HashMap<String, Long>
|
||||
)
|
||||
curMedia.addAll(newMedia)
|
||||
}
|
||||
}
|
||||
|
||||
sortMedia(curMedia, context.config.getFolderSorting(curPath))
|
||||
|
||||
|
@ -399,6 +413,10 @@ class MediaFetcher(val context: Context) {
|
|||
isPickImage: Boolean, isPickVideo: Boolean, favoritePaths: ArrayList<String>
|
||||
): HashMap<String, ArrayList<Medium>> {
|
||||
val media = HashMap<String, ArrayList<Medium>>()
|
||||
if (!isRPlus()) {
|
||||
return media
|
||||
}
|
||||
|
||||
val filterMedia = context.config.filterMedia
|
||||
val showHidden = context.config.shouldShowHidden
|
||||
|
||||
|
|
Loading…
Reference in a new issue