mirror of
https://github.com/SimpleMobileTools/Simple-Gallery.git
synced 2025-06-05 21:59:19 +02:00
do not check every file existence at fetching, just once a week do a cleanup
This commit is contained in:
@ -300,4 +300,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
var extendedDetails: Int
|
||||
get() = prefs.getInt(EXTENDED_DETAILS, EXT_RESOLUTION or EXT_LAST_MODIFIED or EXT_EXIF_PROPERTIES)
|
||||
set(extendedDetails) = prefs.edit().putInt(EXTENDED_DETAILS, extendedDetails).apply()
|
||||
|
||||
var lastFileCleanup: Long
|
||||
get() = prefs.getLong(LAST_FILE_CLEANUP, 0L)
|
||||
set(lastFileCleanup) = prefs.edit().putLong(LAST_FILE_CLEANUP, lastFileCleanup).apply()
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ val VIEW_TYPE_FOLDERS = "view_type_folders"
|
||||
val VIEW_TYPE_FILES = "view_type_files"
|
||||
val SHOW_EXTENDED_DETAILS = "show_extended_details"
|
||||
val EXTENDED_DETAILS = "extended_details"
|
||||
val LAST_FILE_CLEANUP = "last_file_cleanup"
|
||||
|
||||
// slideshow
|
||||
val SLIDESHOW_INTERVAL = "slideshow_interval"
|
||||
|
@ -40,6 +40,16 @@ class MediaFetcher(val context: Context) {
|
||||
directories.remove(it)
|
||||
}
|
||||
|
||||
Thread {
|
||||
val ONE_WEEK = 7 * 24 * 60 * 60 * 1000
|
||||
if (System.currentTimeMillis() - context.config.lastFileCleanup > ONE_WEEK) {
|
||||
media.filter { !File(it.path).exists() }.forEach {
|
||||
context.deleteFromMediaStore(File(it.path))
|
||||
}
|
||||
context.config.lastFileCleanup = System.currentTimeMillis()
|
||||
}
|
||||
}.start()
|
||||
|
||||
return directories
|
||||
}
|
||||
|
||||
@ -140,9 +150,6 @@ class MediaFetcher(val context: Context) {
|
||||
if (size <= 0L)
|
||||
continue
|
||||
|
||||
if (!file.exists())
|
||||
continue
|
||||
|
||||
val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||
val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
||||
|
||||
|
Reference in New Issue
Block a user