From ad0706847534b6e22bfc6e544d3a46919f3ea196 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 26 May 2018 09:53:41 +0200 Subject: [PATCH] clone cached media/directories before sending them back to the app --- .../com/simplemobiletools/gallery/extensions/Context.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index 80fb91dee..d8b9f702a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -293,9 +293,10 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: } }) as ArrayList - callback(filteredDirectories.distinctBy { it.path.getDistinctPath() } as ArrayList) + val clone = filteredDirectories.clone() as ArrayList + callback(clone.distinctBy { it.path.getDistinctPath() } as ArrayList) - removeInvalidDBDirectories(directories, directoryDao) + removeInvalidDBDirectories(filteredDirectories, directoryDao) }.start() } @@ -326,7 +327,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag }) as ArrayList MediaFetcher(this).sortMedia(media, config.getFileSorting(path)) - callback(media) + callback(media.clone() as ArrayList) media.filter { !getDoesFilePathExist(it.path) }.forEach { mediumDao.deleteMediumPath(it.path)