From a7b7881d732caab95874acb4f5864b68ca924143 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 25 Jan 2020 09:34:33 +0100 Subject: [PATCH] moving the favorite toggling function into FavoritesDao --- .../gallery/pro/activities/ViewPagerActivity.kt | 2 +- .../gallery/pro/adapters/MediaAdapter.kt | 3 +-- .../simplemobiletools/gallery/pro/extensions/Context.kt | 9 +++++++++ .../gallery/pro/interfaces/MediumDao.kt | 3 --- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 1e456721b..1befd61d9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -864,7 +864,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val medium = getCurrentMedium() ?: return medium.isFavorite = !medium.isFavorite ensureBackgroundThread { - galleryDB.MediumDao().updateFavorite(medium.path, medium.isFavorite) + updateFavorite(medium.path, medium.isFavorite) if (medium.isFavorite) { mFavoritePaths.add(medium.path) } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 298a90def..5dcf75275 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -266,10 +266,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList { fun Context.getFavoriteFromPath(path: String) = Favorite(null, path, path.getFilenameFromPath(), path.getParentPath()) +fun Context.updateFavorite(path: String, isFavorite: Boolean) { + val favoritesDAO = galleryDB.FavoritesDAO() + if (isFavorite) { + favoritesDAO.insert(getFavoriteFromPath(path)) + } else { + favoritesDAO.deleteFavoritePath(path) + } +} + // remove the "recycle_bin" from the file path prefix, replace it with real bin path /data/user... fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList { val media = try { 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 1ce2bb641..3f89a2f5d 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 @@ -39,9 +39,6 @@ interface MediumDao { @Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath COLLATE NOCASE") fun updateMedium(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String) - @Query("UPDATE media SET is_favorite = :isFavorite WHERE full_path = :path COLLATE NOCASE") - fun updateFavorite(path: String, isFavorite: Boolean) - @Query("UPDATE OR REPLACE media SET full_path = :newPath, deleted_ts = :deletedTS WHERE full_path = :oldPath COLLATE NOCASE") fun updateDeleted(newPath: String, deletedTS: Long, oldPath: String)