mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
prefetch all Last Modified values, not folder by folder
This commit is contained in:
parent
ff2cbbf533
commit
f815c626fc
4 changed files with 49 additions and 18 deletions
|
@ -909,6 +909,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
val favoritePaths = getFavoritePaths()
|
||||
val dirPathsToRemove = ArrayList<String>()
|
||||
|
||||
val lastModifieds = if (isRPlus()) mLastMediaFetcher!!.getLastModifieds() else HashMap<String, Long>()
|
||||
|
||||
try {
|
||||
for (directory in dirs) {
|
||||
if (mShouldStopFetching || isDestroyed || isFinishing) {
|
||||
|
@ -927,7 +929,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
|
||||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
|
||||
|
||||
val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, false)
|
||||
val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
|
||||
getProperFileSize, favoritePaths, false, lastModifieds)
|
||||
|
||||
val newDir = if (curMedia.isEmpty()) {
|
||||
if (directory.path != tempFolderPath) {
|
||||
dirPathsToRemove.add(directory.path)
|
||||
|
@ -1019,7 +1023,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
|
||||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
|
||||
|
||||
val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, false)
|
||||
val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
|
||||
getProperFileSize, favoritePaths, false, lastModifieds)
|
||||
|
||||
if (newMedia.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.os.AsyncTask
|
|||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.commons.helpers.isRPlus
|
||||
import com.simplemobiletools.gallery.pro.extensions.config
|
||||
import com.simplemobiletools.gallery.pro.extensions.getFavoritePaths
|
||||
import com.simplemobiletools.gallery.pro.helpers.*
|
||||
|
@ -32,19 +33,23 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
|
|||
val getProperFileSize = fileSorting and SORT_BY_SIZE != 0
|
||||
val favoritePaths = context.getFavoritePaths()
|
||||
val getVideoDurations = context.config.showThumbnailVideoDuration
|
||||
val lastModifieds = if (isRPlus()) mediaFetcher.getLastModifieds() else HashMap<String, Long>()
|
||||
val media = if (showAll) {
|
||||
val foldersToScan = mediaFetcher.getFoldersToScan().filter { it != RECYCLE_BIN && it != FAVORITES && !context.config.isFolderProtected(it) }
|
||||
val media = ArrayList<Medium>()
|
||||
foldersToScan.forEach {
|
||||
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations)
|
||||
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, getVideoDurations, lastModifieds)
|
||||
media.addAll(newMedia)
|
||||
}
|
||||
|
||||
mediaFetcher.sortMedia(media, context.config.getFolderSorting(SHOW_ALL))
|
||||
media
|
||||
} else {
|
||||
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations)
|
||||
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths,
|
||||
getVideoDurations, lastModifieds)
|
||||
}
|
||||
|
||||
return mediaFetcher.groupMedia(media, pathToUse)
|
||||
}
|
||||
|
||||
|
|
|
@ -869,6 +869,7 @@ fun Context.getDirectorySortingValue(media: ArrayList<Medium>, path: String, nam
|
|||
|
||||
fun Context.updateDirectoryPath(path: String) {
|
||||
val mediaFetcher = MediaFetcher(applicationContext)
|
||||
val lastModifieds = mediaFetcher.getFolderLastModifieds(path)
|
||||
val getImagesOnly = false
|
||||
val getVideosOnly = false
|
||||
val hiddenString = getString(R.string.hidden)
|
||||
|
@ -889,7 +890,8 @@ fun Context.updateDirectoryPath(path: String) {
|
|||
|
||||
val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0
|
||||
val favoritePaths = getFavoritePaths()
|
||||
val curMedia = mediaFetcher.getFilesFrom(path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, false)
|
||||
val curMedia = mediaFetcher.getFilesFrom(path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, false, lastModifieds)
|
||||
val directory = createDirectoryFromMedia(path, curMedia, albumCovers, hiddenString, includedFolders, getProperFileSize)
|
||||
updateDBDirectory(directory)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@ class MediaFetcher(val context: Context) {
|
|||
var shouldStop = false
|
||||
|
||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperLastModified: Boolean,
|
||||
getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean): ArrayList<Medium> {
|
||||
getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean,
|
||||
lastModifieds: HashMap<String, Long> = HashMap<String, Long>()): ArrayList<Medium> {
|
||||
val filterMedia = context.config.filterMedia
|
||||
if (filterMedia == 0) {
|
||||
return ArrayList()
|
||||
|
@ -35,7 +36,8 @@ class MediaFetcher(val context: Context) {
|
|||
curMedia.addAll(newMedia)
|
||||
}
|
||||
} else {
|
||||
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations)
|
||||
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, getVideoDurations, lastModifieds)
|
||||
curMedia.addAll(newMedia)
|
||||
}
|
||||
|
||||
|
@ -223,7 +225,8 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
|
||||
private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean,
|
||||
getProperLastModified: Boolean, getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean): ArrayList<Medium> {
|
||||
getProperLastModified: Boolean, getProperFileSize: Boolean, favoritePaths: ArrayList<String>,
|
||||
getVideoDurations: Boolean, lastModifieds: HashMap<String, Long>): ArrayList<Medium> {
|
||||
val media = ArrayList<Medium>()
|
||||
val isRecycleBin = folder == RECYCLE_BIN
|
||||
val deletedMedia = if (isRecycleBin) {
|
||||
|
@ -238,7 +241,6 @@ class MediaFetcher(val context: Context) {
|
|||
val showHidden = config.shouldShowHidden
|
||||
val showPortraits = filterMedia and TYPE_PORTRAITS != 0
|
||||
val dateTakens = if (getProperDateTaken && !isRecycleBin) getFolderDateTakens(folder) else HashMap()
|
||||
val lastModifieds = if (getProperLastModified && !isRecycleBin && isRPlus()) getFolderLastModifieds(folder) else HashMap()
|
||||
val fileSizes = if (checkProperFileSize || checkFileExistence) getFolderSizes(folder) else HashMap()
|
||||
|
||||
val files = when (folder) {
|
||||
|
@ -472,7 +474,7 @@ class MediaFetcher(val context: Context) {
|
|||
return dateTakens
|
||||
}
|
||||
|
||||
private fun getFolderLastModifieds(folder: String): HashMap<String, Long> {
|
||||
fun getFolderLastModifieds(folder: String): HashMap<String, Long> {
|
||||
val lastModifieds = HashMap<String, Long>()
|
||||
if (folder != FAVORITES) {
|
||||
val projection = arrayOf(
|
||||
|
@ -501,15 +503,31 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
val lastModifiedValues = if (folder == FAVORITES) {
|
||||
context.dateTakensDB.getAllDateTakens()
|
||||
} else {
|
||||
context.dateTakensDB.getDateTakensFromPath(folder)
|
||||
return lastModifieds
|
||||
}
|
||||
|
||||
lastModifiedValues.forEach {
|
||||
if (!lastModifieds.containsKey(it.fullPath)) {
|
||||
lastModifieds[it.fullPath] = it.lastModified
|
||||
fun getLastModifieds(): HashMap<String, Long> {
|
||||
val lastModifieds = HashMap<String, Long>()
|
||||
val projection = arrayOf(
|
||||
Images.Media.DATA,
|
||||
Images.Media.DATE_MODIFIED
|
||||
)
|
||||
|
||||
val uri = Files.getContentUri("external")
|
||||
|
||||
val cursor = context.contentResolver.query(uri, projection, null, null, null)
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
try {
|
||||
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
|
||||
if (lastModified != 0L) {
|
||||
val path = cursor.getStringValue(Images.Media.DATA)
|
||||
lastModifieds[path] = lastModified
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue