From fb0badeca5288d4a7d5583c43e68ef2b13e9354c Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 24 Jan 2020 23:29:03 +0100 Subject: [PATCH] adding a few more favorites related queries --- .../gallery/pro/extensions/Context.kt | 7 +++---- .../gallery/pro/interfaces/FavoritesDAO.kt | 15 +++++++++++++++ 2 files changed, 18 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 5ead9ba4e..b013354bf 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 @@ -28,10 +28,7 @@ import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao import com.simplemobiletools.gallery.pro.interfaces.MediumDao import com.simplemobiletools.gallery.pro.interfaces.WidgetsDao -import com.simplemobiletools.gallery.pro.models.AlbumCover -import com.simplemobiletools.gallery.pro.models.Directory -import com.simplemobiletools.gallery.pro.models.Medium -import com.simplemobiletools.gallery.pro.models.ThumbnailItem +import com.simplemobiletools.gallery.pro.models.* import com.simplemobiletools.gallery.pro.svg.SvgSoftwareLayerSetter import com.simplemobiletools.gallery.pro.views.MySquareImageView import pl.droidsonroids.gif.GifDrawable @@ -721,6 +718,8 @@ fun Context.getFavoritePaths(): ArrayList { } } +fun Context.getFavoriteFromPath(path: String) = Favorite(null, path, path.getFilenameFromPath(), path.getParentPath()) + // 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/FavoritesDAO.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt index 6daa09356..f3b97e6ad 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,10 +1,25 @@ package com.simplemobiletools.gallery.pro.interfaces import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy import androidx.room.Query +import com.simplemobiletools.gallery.pro.models.Favorite @Dao interface FavoritesDAO { + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(favorite: Favorite) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insertAll(favorites: List) + + @Query("SELECT full_path FROM favorites") + fun getFavoriteRawPaths(): List + + @Query("SELECT favorites.full_path FROM favorites INNER JOIN media ON favorites.full_path = media.full_path WHERE media.deleted_ts = 0") + fun getValidFavoritePaths(): List + @Query("SELECT id FROM favorites WHERE full_path = :path COLLATE NOCASE") fun isFavorite(path: String): Boolean