mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
improve the performance at checking file size too
This commit is contained in:
parent
e4dc231589
commit
f034ad5786
1 changed files with 43 additions and 6 deletions
|
@ -221,6 +221,7 @@ class MediaFetcher(val context: Context) {
|
||||||
val showPortraits = filterMedia and TYPE_PORTRAITS != 0
|
val showPortraits = filterMedia and TYPE_PORTRAITS != 0
|
||||||
val dateTakens = if (getProperDateTaken && !isRecycleBin) getFolderDateTakens(folder) else HashMap()
|
val dateTakens = if (getProperDateTaken && !isRecycleBin) getFolderDateTakens(folder) else HashMap()
|
||||||
val lastModifieds = if (getProperLastModified && !isRecycleBin) getFolderLastModifieds(folder) else HashMap()
|
val lastModifieds = if (getProperLastModified && !isRecycleBin) getFolderLastModifieds(folder) else HashMap()
|
||||||
|
val fileSizes = if (checkProperFileSize || checkFileExistence) getFolderSizes(folder) else HashMap()
|
||||||
|
|
||||||
val files = when (folder) {
|
val files = when (folder) {
|
||||||
FAVORITES -> favoritePaths.filter { showHidden || !it.contains("/.") }.map { File(it) }.toMutableList() as ArrayList<File>
|
FAVORITES -> favoritePaths.filter { showHidden || !it.contains("/.") }.map { File(it) }.toMutableList() as ArrayList<File>
|
||||||
|
@ -277,7 +278,15 @@ class MediaFetcher(val context: Context) {
|
||||||
if (!showHidden && filename.startsWith('.'))
|
if (!showHidden && filename.startsWith('.'))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val size = if (checkProperFileSize || checkFileExistence) file.length() else 1L
|
var size = 0L
|
||||||
|
if (checkProperFileSize || checkFileExistence) {
|
||||||
|
var newSize = fileSizes.remove(path)
|
||||||
|
if (newSize == null) {
|
||||||
|
newSize = file.length()
|
||||||
|
}
|
||||||
|
size = newSize
|
||||||
|
}
|
||||||
|
|
||||||
if ((checkProperFileSize || checkFileExistence) && size <= 0L) {
|
if ((checkProperFileSize || checkFileExistence) && size <= 0L) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -295,11 +304,7 @@ class MediaFetcher(val context: Context) {
|
||||||
if (getProperLastModified) {
|
if (getProperLastModified) {
|
||||||
var newLastModified = lastModifieds.remove(path)
|
var newLastModified = lastModifieds.remove(path)
|
||||||
if (newLastModified == null) {
|
if (newLastModified == null) {
|
||||||
newLastModified = if (getProperLastModified) {
|
newLastModified = file.lastModified()
|
||||||
lastModified
|
|
||||||
} else {
|
|
||||||
file.lastModified()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lastModified = newLastModified
|
lastModified = newLastModified
|
||||||
}
|
}
|
||||||
|
@ -487,6 +492,38 @@ class MediaFetcher(val context: Context) {
|
||||||
return lastModifieds
|
return lastModifieds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFolderSizes(folder: String): HashMap<String, Long> {
|
||||||
|
val sizes = HashMap<String, Long>()
|
||||||
|
if (folder != FAVORITES) {
|
||||||
|
val projection = arrayOf(
|
||||||
|
Images.Media.DISPLAY_NAME,
|
||||||
|
Images.Media.SIZE
|
||||||
|
)
|
||||||
|
|
||||||
|
val uri = Files.getContentUri("external")
|
||||||
|
val selection = "${Images.Media.DATA} LIKE ? AND ${Images.Media.DATA} NOT LIKE ?"
|
||||||
|
val selectionArgs = arrayOf("$folder/%", "$folder/%/%")
|
||||||
|
|
||||||
|
val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
|
cursor?.use {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
val size = cursor.getLongValue(Images.Media.SIZE)
|
||||||
|
if (size != 0L) {
|
||||||
|
val name = cursor.getStringValue(Images.Media.DISPLAY_NAME)
|
||||||
|
sizes["$folder/$name"] = size
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sizes
|
||||||
|
}
|
||||||
|
|
||||||
fun sortMedia(media: ArrayList<Medium>, sorting: Int) {
|
fun sortMedia(media: ArrayList<Medium>, sorting: Int) {
|
||||||
if (sorting and SORT_BY_RANDOM != 0) {
|
if (sorting and SORT_BY_RANDOM != 0) {
|
||||||
media.shuffle()
|
media.shuffle()
|
||||||
|
|
Loading…
Reference in a new issue