moving the favorite toggling function into FavoritesDao
This commit is contained in:
parent
fb0badeca5
commit
a7b7881d73
4 changed files with 11 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -266,10 +266,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
|||
|
||||
private fun toggleFavorites(add: Boolean) {
|
||||
ensureBackgroundThread {
|
||||
val mediumDao = activity.galleryDB.MediumDao()
|
||||
getSelectedItems().forEach {
|
||||
it.isFavorite = add
|
||||
mediumDao.updateFavorite(it.path, add)
|
||||
activity.updateFavorite(it.path, add)
|
||||
}
|
||||
activity.runOnUiThread {
|
||||
listener?.refreshItems()
|
||||
|
|
|
@ -720,6 +720,15 @@ fun Context.getFavoritePaths(): ArrayList<String> {
|
|||
|
||||
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<Medium> {
|
||||
val media = try {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue