From da80d246060cd35c2a73251d0ec3b7e7f7d0ef96 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 29 Dec 2017 15:28:33 +0100 Subject: [PATCH] do not check every file existence at fetching, just once a week do a cleanup --- app/build.gradle | 2 +- .../com/simplemobiletools/gallery/helpers/Config.kt | 4 ++++ .../simplemobiletools/gallery/helpers/Constants.kt | 1 + .../gallery/helpers/MediaFetcher.kt | 13 ++++++++++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cd09b01ca..ba11cf9e6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,7 +42,7 @@ ext { } 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.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.android.support:multidex:1.0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 8c2f7cdb1..9b27f1346 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -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() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index b9ebd1071..7318c6d9e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -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" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index efad5c169..e0e199df2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -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