diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index cd68b5c55..4af66f86e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -604,23 +604,25 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag callback(grouped.clone() as ArrayList) val OTGPath = config.OTGPath - val mediaToDelete = ArrayList() - media.filter { !getDoesFilePathExist(it.path, OTGPath) }.forEach { - if (it.path.startsWith(recycleBinPath)) { - deleteDBPath(it.path) - } else { - mediaToDelete.add(it) - } - } - try { - if (mediaToDelete.isNotEmpty()) { - mediaDB.deleteMedia(*mediaToDelete.toTypedArray()) - - mediaToDelete.filter { it.isFavorite }.forEach { - favoritesDB.deleteFavoritePath(it.path) + val mediaToDelete = ArrayList() + Thread { + media.filter { !getDoesFilePathExist(it.path, OTGPath) }.forEach { + if (it.path.startsWith(recycleBinPath)) { + deleteDBPath(it.path) + } else { + mediaToDelete.add(it) + } } - } + + if (mediaToDelete.isNotEmpty()) { + mediaDB.deleteMedia(*mediaToDelete.toTypedArray()) + + mediaToDelete.filter { it.isFavorite }.forEach { + favoritesDB.deleteFavoritePath(it.path) + } + } + }.start() } catch (ignored: Exception) { } }