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 ea861a884..eb41408b1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -391,13 +391,16 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag callback(grouped.clone() as ArrayList) val recycleBinPath = filesDir.absolutePath + val mediaToDelete = ArrayList() media.filter { !getDoesFilePathExist(it.path) }.forEach { if (it.path.startsWith(recycleBinPath)) { mediumDao.deleteMediumPath(it.path.removePrefix(recycleBinPath)) } else { - mediumDao.deleteMediumPath(it.path) + mediaToDelete.add(it) } } + + mediumDao.deleteMedia(*mediaToDelete.toTypedArray()) }.start() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt index 03090d6b5..a5829dd98 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/MediumDao.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.gallery.interfaces import android.arch.persistence.room.Dao +import android.arch.persistence.room.Delete import android.arch.persistence.room.Insert import android.arch.persistence.room.OnConflictStrategy.REPLACE import android.arch.persistence.room.Query @@ -26,6 +27,9 @@ interface MediumDao { @Insert(onConflict = REPLACE) fun insertAll(media: List) + @Delete + fun deleteMedia(vararg medium: Medium) + @Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE") fun deleteMediumPath(path: String)