do not check every file existence at fetching, just once a week do a cleanup

This commit is contained in:
tibbi 2017-12-29 15:28:33 +01:00
parent b9187adfc0
commit da80d24606
4 changed files with 16 additions and 4 deletions

View file

@ -42,7 +42,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.4.2' implementation 'com.simplemobiletools:commons:3.4.15'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0' implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.9.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
implementation 'com.android.support:multidex:1.0.2' implementation 'com.android.support:multidex:1.0.2'

View file

@ -300,4 +300,8 @@ class Config(context: Context) : BaseConfig(context) {
var extendedDetails: Int var extendedDetails: Int
get() = prefs.getInt(EXTENDED_DETAILS, EXT_RESOLUTION or EXT_LAST_MODIFIED or EXT_EXIF_PROPERTIES) get() = prefs.getInt(EXTENDED_DETAILS, EXT_RESOLUTION or EXT_LAST_MODIFIED or EXT_EXIF_PROPERTIES)
set(extendedDetails) = prefs.edit().putInt(EXTENDED_DETAILS, extendedDetails).apply() 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()
} }

View file

@ -42,6 +42,7 @@ val VIEW_TYPE_FOLDERS = "view_type_folders"
val VIEW_TYPE_FILES = "view_type_files" val VIEW_TYPE_FILES = "view_type_files"
val SHOW_EXTENDED_DETAILS = "show_extended_details" val SHOW_EXTENDED_DETAILS = "show_extended_details"
val EXTENDED_DETAILS = "extended_details" val EXTENDED_DETAILS = "extended_details"
val LAST_FILE_CLEANUP = "last_file_cleanup"
// slideshow // slideshow
val SLIDESHOW_INTERVAL = "slideshow_interval" val SLIDESHOW_INTERVAL = "slideshow_interval"

View file

@ -40,6 +40,16 @@ class MediaFetcher(val context: Context) {
directories.remove(it) 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 return directories
} }
@ -140,9 +150,6 @@ class MediaFetcher(val context: Context) {
if (size <= 0L) if (size <= 0L)
continue continue
if (!file.exists())
continue
val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L