From 811d5e88c56e2a508148fde6f842c8cfbe0f664b Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Oct 2021 13:59:54 +0200 Subject: [PATCH] fixed some glitches with favorites un/marking --- .../gallery/pro/activities/MediaActivity.kt | 9 +++++++-- .../gallery/pro/interfaces/MediumDao.kt | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) 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()