From e578036a227b22000d58814f32816cf852eed59e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 25 Jan 2020 11:11:23 +0100 Subject: [PATCH] delete favorites at deleting media --- .../simplemobiletools/gallery/pro/extensions/Context.kt | 2 ++ .../gallery/pro/interfaces/FavoritesDao.kt | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) 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 31c37b75a..be0f31756 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 @@ -674,6 +674,8 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag try { if (mediaToDelete.isNotEmpty()) { mediaDB.deleteMedia(*mediaToDelete.toTypedArray()) + val favorites = mediaToDelete.map { getFavoriteFromPath(it.path) } + favoritesDB.deleteFavorites(*favorites.toTypedArray()) } } 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 d835d9f65..8a890e20a 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 @@ -1,9 +1,6 @@ package com.simplemobiletools.gallery.pro.interfaces -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy -import androidx.room.Query +import androidx.room.* import com.simplemobiletools.gallery.pro.models.Favorite @Dao @@ -23,6 +20,9 @@ interface FavoritesDao { @Query("SELECT id FROM favorites WHERE full_path = :path COLLATE NOCASE") fun isFavorite(path: String): Boolean + @Delete + fun deleteFavorites(vararg favorite: Favorite) + @Query("DELETE FROM favorites WHERE full_path = :path COLLATE NOCASE") fun deleteFavoritePath(path: String)