mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
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
|
val medium = getCurrentMedium() ?: return
|
||||||
medium.isFavorite = !medium.isFavorite
|
medium.isFavorite = !medium.isFavorite
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
galleryDB.MediumDao().updateFavorite(medium.path, medium.isFavorite)
|
updateFavorite(medium.path, medium.isFavorite)
|
||||||
if (medium.isFavorite) {
|
if (medium.isFavorite) {
|
||||||
mFavoritePaths.add(medium.path)
|
mFavoritePaths.add(medium.path)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -266,10 +266,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
|
|
||||||
private fun toggleFavorites(add: Boolean) {
|
private fun toggleFavorites(add: Boolean) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val mediumDao = activity.galleryDB.MediumDao()
|
|
||||||
getSelectedItems().forEach {
|
getSelectedItems().forEach {
|
||||||
it.isFavorite = add
|
it.isFavorite = add
|
||||||
mediumDao.updateFavorite(it.path, add)
|
activity.updateFavorite(it.path, add)
|
||||||
}
|
}
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
listener?.refreshItems()
|
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.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...
|
// remove the "recycle_bin" from the file path prefix, replace it with real bin path /data/user...
|
||||||
fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
|
fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
|
||||||
val media = try {
|
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")
|
@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)
|
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")
|
@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)
|
fun updateDeleted(newPath: String, deletedTS: Long, oldPath: String)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue