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)