From b64f1647420ad6a882efdf2e28bf8130cc45a09f Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 11 Dec 2018 12:47:18 +0100 Subject: [PATCH] delete invalid files from cache at loading thumbnails --- .../gallery/pro/activities/MediaActivity.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 791cabd78..a8390793d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -585,7 +585,15 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { mCurrAsyncTask?.stopFetching() mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) { Thread { - gotMedia(it) + val oldMedia = mMedia.clone() as ArrayList + val newMedia = it + gotMedia(newMedia, false) + try { + oldMedia.filter { !newMedia.contains(it) }.mapNotNull { it as? Medium }.filter { !File(it.path).exists() }.forEach { + mMediumDao.deleteMediumPath(it.path) + } + } catch (e: Exception) { + } }.start() } @@ -820,7 +828,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } } - private fun gotMedia(media: ArrayList, isFromCache: Boolean = false) { + private fun gotMedia(media: ArrayList, isFromCache: Boolean) { mIsGettingMedia = false checkLastMediaChanged() mMedia = media