From b867d2a2eb872d9dfef857eba97a9f37758e950e Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 24 Jan 2020 23:10:40 +0100 Subject: [PATCH] at deleting a file path from db, delete it from favorites too --- .../simplemobiletools/gallery/pro/extensions/Context.kt | 7 ++++++- .../gallery/pro/interfaces/FavoritesDAO.kt | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 b21e4a390..5ead9ba4e 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 @@ -736,8 +736,13 @@ fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList { } fun Context.deleteDBPath(mediumDao: MediumDao, path: String) { + deleteMediumWithPath(mediumDao, path.replaceFirst(recycleBinPath, RECYCLE_BIN)) +} + +fun Context.deleteMediumWithPath(mediumDao: MediumDao, path: String) { try { - mediumDao.deleteMediumPath(path.replaceFirst(recycleBinPath, RECYCLE_BIN)) + mediumDao.deleteMediumPath(path) + galleryDB.FavoritesDAO().deleteFavoritePath(path) } catch (ignored: Exception) { } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt index d1fa0856e..6daa09356 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt @@ -7,4 +7,7 @@ import androidx.room.Query interface FavoritesDAO { @Query("SELECT id FROM favorites WHERE full_path = :path COLLATE NOCASE") fun isFavorite(path: String): Boolean + + @Query("DELETE FROM favorites WHERE full_path = :path COLLATE NOCASE") + fun deleteFavoritePath(path: String) }