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 7df4bbf73..e2e7278c6 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 @@ -611,8 +611,13 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { val newMedia = it try { gotMedia(newMedia, false) - oldMedia.filter { !newMedia.contains(it) }.mapNotNull { it as? Medium }.filter { !getDoesFilePathExist(it.path) }.forEach { - mediaDB.deleteMediumPath(it.path) + oldMedia.filter { !newMedia.contains(it) }.mapNotNull { it as? Medium }.forEach { + if (!getDoesFilePathExist(it.path)) { + mediaDB.deleteMediumPath(it.path) + } else if (mPath == FAVORITES) { + favoritesDB.deleteFavoritePath(it.path) + mediaDB.updateFavorite(it.path, false) + } } } catch (e: Exception) { } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt index 4affa1995..999ca60ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/MediumDao.kt @@ -42,6 +42,9 @@ interface MediumDao { @Query("UPDATE media SET date_taken = :dateTaken WHERE full_path = :path COLLATE NOCASE") fun updateFavoriteDateTaken(path: String, dateTaken: Long) + @Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path COLLATE NOCASE") + fun updateFavorite(path: String, isFavorite: Boolean) + @Query("UPDATE media SET is_favorite = 0") fun clearFavorites()