From b9369139f190f15ae8121cefd32da039f11ecc16 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 25 Jan 2020 09:51:28 +0100 Subject: [PATCH] renaming some DAO to Dao --- .../gallery/pro/activities/ViewPagerActivity.kt | 2 +- .../gallery/pro/adapters/DirectoryAdapter.kt | 2 +- .../gallery/pro/databases/GalleryDatabase.kt | 4 ++-- .../gallery/pro/extensions/Context.kt | 14 ++++++++------ .../{DateTakensDAO.kt => DateTakensDao.kt} | 2 +- .../{FavoritesDAO.kt => FavoritesDao.kt} | 5 ++++- .../gallery/pro/interfaces/MediumDao.kt | 3 --- 7 files changed, 17 insertions(+), 15 deletions(-) rename app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/{DateTakensDAO.kt => DateTakensDao.kt} (77%) rename app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/{FavoritesDAO.kt => FavoritesDao.kt} (91%) 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 1befd61d9..4ffb2d73d 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 @@ -375,7 +375,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View else -> TYPE_IMAGES } - val isFavorite = galleryDB.FavoritesDAO().isFavorite(mPath) + val isFavorite = favoritesDB.isFavorite(mPath) val duration = if (type == TYPE_VIDEOS) mPath.getVideoDuration() else 0 val ts = System.currentTimeMillis() val medium = Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index abc71941e..a70362d67 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -555,7 +555,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList { return try { - galleryDB.FavoritesDAO().getValidFavoritePaths() as ArrayList + favoritesDB.getValidFavoritePaths() as ArrayList } catch (e: Exception) { ArrayList() } @@ -721,11 +724,10 @@ fun Context.getFavoritePaths(): ArrayList { 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)) + favoritesDB.insert(getFavoriteFromPath(path)) } else { - favoritesDAO.deleteFavoritePath(path) + favoritesDB.deleteFavoritePath(path) } } @@ -750,7 +752,7 @@ fun Context.deleteDBPath(mediumDao: MediumDao, path: String) { fun Context.deleteMediumWithPath(mediumDao: MediumDao, path: String) { try { mediumDao.deleteMediumPath(path) - galleryDB.FavoritesDAO().deleteFavoritePath(path) + favoritesDB.deleteFavoritePath(path) } catch (ignored: Exception) { } } @@ -840,7 +842,7 @@ fun Context.addPathToDB(path: String) { try { val mediumDao = galleryDB.MediumDao() - val isFavorite = galleryDB.FavoritesDAO().isFavorite(path) + val isFavorite = favoritesDB.isFavorite(path) val videoDuration = if (type == TYPE_VIDEOS) path.getVideoDuration() else 0 val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(), File(path).length(), type, videoDuration, isFavorite, 0L) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDAO.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDao.kt similarity index 77% rename from app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDAO.kt rename to app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDao.kt index 107801537..0d3380408 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDAO.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDao.kt @@ -3,6 +3,6 @@ package com.simplemobiletools.gallery.pro.interfaces import androidx.room.Dao @Dao -interface DateTakensDAO { +interface DateTakensDao { } 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 similarity index 91% rename from app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt rename to app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDao.kt index f3b97e6ad..d835d9f65 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,7 +7,7 @@ import androidx.room.Query import com.simplemobiletools.gallery.pro.models.Favorite @Dao -interface FavoritesDAO { +interface FavoritesDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(favorite: Favorite) @@ -25,4 +25,7 @@ interface FavoritesDAO { @Query("DELETE FROM favorites WHERE full_path = :path COLLATE NOCASE") fun deleteFavoritePath(path: String) + + @Query("DELETE FROM favorites") + fun clearFavorites() } 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 1bf91b543..ec0a8befc 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 @@ -44,7 +44,4 @@ interface MediumDao { @Query("DELETE FROM media WHERE deleted_ts != 0") fun clearRecycleBin() - - @Query("UPDATE media SET is_favorite = 0") - fun clearFavorites() }