cache all Date Taken values at once, not folder by folder
This commit is contained in:
parent
44f5bb5c1e
commit
8d7a5b1771
|
@ -908,8 +908,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0
|
||||
val favoritePaths = getFavoritePaths()
|
||||
val dirPathsToRemove = ArrayList<String>()
|
||||
|
||||
val lastModifieds = if (isRPlus()) mLastMediaFetcher!!.getLastModifieds() else HashMap<String, Long>()
|
||||
val lastModifieds = if (isRPlus()) mLastMediaFetcher!!.getLastModifieds() else HashMap()
|
||||
val dateTakens = mLastMediaFetcher!!.getDateTakens()
|
||||
|
||||
try {
|
||||
for (directory in dirs) {
|
||||
|
@ -930,7 +930,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
|
||||
|
||||
val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
|
||||
getProperFileSize, favoritePaths, false, lastModifieds)
|
||||
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens)
|
||||
|
||||
val newDir = if (curMedia.isEmpty()) {
|
||||
if (directory.path != tempFolderPath) {
|
||||
|
@ -1024,7 +1024,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
|
||||
|
||||
val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
|
||||
getProperFileSize, favoritePaths, false, lastModifieds)
|
||||
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens)
|
||||
|
||||
if (newMedia.isEmpty()) {
|
||||
continue
|
||||
|
|
|
@ -34,12 +34,14 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
|
|||
val favoritePaths = context.getFavoritePaths()
|
||||
val getVideoDurations = context.config.showThumbnailVideoDuration
|
||||
val lastModifieds = if (isRPlus() && getProperLastModified) mediaFetcher.getLastModifieds() else HashMap()
|
||||
val dateTakens = if (getProperLastModified) mediaFetcher.getDateTakens() else HashMap()
|
||||
|
||||
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, lastModifieds)
|
||||
favoritePaths, getVideoDurations, lastModifieds, dateTakens)
|
||||
media.addAll(newMedia)
|
||||
}
|
||||
|
||||
|
@ -47,7 +49,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
|
|||
media
|
||||
} else {
|
||||
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths,
|
||||
getVideoDurations, lastModifieds)
|
||||
getVideoDurations, lastModifieds, dateTakens)
|
||||
}
|
||||
|
||||
return mediaFetcher.groupMedia(media, pathToUse)
|
||||
|
|
|
@ -869,7 +869,6 @@ 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,9 +888,12 @@ fun Context.updateDirectoryPath(path: String) {
|
|||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
|
||||
|
||||
val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0
|
||||
|
||||
val lastModifieds = if (isRPlus() && getProperLastModified) mediaFetcher.getFolderLastModifieds(path) else HashMap()
|
||||
val dateTakens = mediaFetcher.getFolderDateTakens(path)
|
||||
val favoritePaths = getFavoritePaths()
|
||||
val curMedia = mediaFetcher.getFilesFrom(path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, false, lastModifieds)
|
||||
favoritePaths, false, lastModifieds, dateTakens)
|
||||
val directory = createDirectoryFromMedia(path, curMedia, albumCovers, hiddenString, includedFolders, getProperFileSize)
|
||||
updateDBDirectory(directory)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class MediaFetcher(val context: Context) {
|
|||
|
||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperLastModified: Boolean,
|
||||
getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean,
|
||||
lastModifieds: HashMap<String, Long> = HashMap<String, Long>()): ArrayList<Medium> {
|
||||
lastModifieds: HashMap<String, Long>, dateTakens: HashMap<String, Long>): ArrayList<Medium> {
|
||||
val filterMedia = context.config.filterMedia
|
||||
if (filterMedia == 0) {
|
||||
return ArrayList()
|
||||
|
@ -37,7 +37,7 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
} else {
|
||||
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperLastModified, getProperFileSize,
|
||||
favoritePaths, getVideoDurations, lastModifieds)
|
||||
favoritePaths, getVideoDurations, lastModifieds, dateTakens)
|
||||
curMedia.addAll(newMedia)
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ 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, lastModifieds: HashMap<String, Long>): ArrayList<Medium> {
|
||||
getVideoDurations: Boolean, lastModifieds: HashMap<String, Long>, dateTakens: HashMap<String, Long>): ArrayList<Medium> {
|
||||
val media = ArrayList<Medium>()
|
||||
val isRecycleBin = folder == RECYCLE_BIN
|
||||
val deletedMedia = if (isRecycleBin) {
|
||||
|
@ -240,7 +240,6 @@ class MediaFetcher(val context: Context) {
|
|||
val checkFileExistence = config.fileLoadingPriority == PRIORITY_VALIDITY
|
||||
val showHidden = config.shouldShowHidden
|
||||
val showPortraits = filterMedia and TYPE_PORTRAITS != 0
|
||||
val dateTakens = if (getProperDateTaken && !isRecycleBin) getFolderDateTakens(folder) else HashMap()
|
||||
val fileSizes = if (checkProperFileSize || checkFileExistence) getFolderSizes(folder) else HashMap()
|
||||
|
||||
val files = when (folder) {
|
||||
|
@ -432,7 +431,7 @@ class MediaFetcher(val context: Context) {
|
|||
return media
|
||||
}
|
||||
|
||||
private fun getFolderDateTakens(folder: String): HashMap<String, Long> {
|
||||
fun getFolderDateTakens(folder: String): HashMap<String, Long> {
|
||||
val dateTakens = HashMap<String, Long>()
|
||||
if (folder != FAVORITES) {
|
||||
val projection = arrayOf(
|
||||
|
@ -474,6 +473,40 @@ class MediaFetcher(val context: Context) {
|
|||
return dateTakens
|
||||
}
|
||||
|
||||
fun getDateTakens(): HashMap<String, Long> {
|
||||
val dateTakens = HashMap<String, Long>()
|
||||
val projection = arrayOf(
|
||||
Images.Media.DATA,
|
||||
Images.Media.DATE_TAKEN
|
||||
)
|
||||
|
||||
val uri = Files.getContentUri("external")
|
||||
|
||||
val cursor = context.contentResolver.query(uri, projection, null, null, null)
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
try {
|
||||
val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN)
|
||||
if (dateTaken != 0L) {
|
||||
val path = cursor.getStringValue(Images.Media.DATA)
|
||||
dateTakens[path] = dateTaken
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
}
|
||||
|
||||
val dateTakenValues = context.dateTakensDB.getAllDateTakens()
|
||||
|
||||
dateTakenValues.forEach {
|
||||
dateTakens[it.fullPath] = it.taken
|
||||
}
|
||||
|
||||
return dateTakens
|
||||
}
|
||||
|
||||
fun getFolderLastModifieds(folder: String): HashMap<String, Long> {
|
||||
val lastModifieds = HashMap<String, Long>()
|
||||
if (folder != FAVORITES) {
|
||||
|
|
Loading…
Reference in New Issue