renaming some DAO to Dao

This commit is contained in:
tibbi 2020-01-25 09:51:28 +01:00
parent 61c4db155d
commit b9369139f1
7 changed files with 17 additions and 15 deletions

View file

@ -375,7 +375,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
else -> TYPE_IMAGES 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 duration = if (type == TYPE_VIDEOS) mPath.getVideoDuration() else 0
val ts = System.currentTimeMillis() val ts = System.currentTimeMillis()
val medium = Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0) val medium = Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0)

View file

@ -555,7 +555,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
tryEmptyRecycleBin(false) tryEmptyRecycleBin(false)
} else { } else {
ensureBackgroundThread { ensureBackgroundThread {
activity.galleryDB.MediumDao().clearFavorites() activity.favoritesDB.clearFavorites()
listener?.refreshItems() listener?.refreshItems()
} }
} }

View file

@ -18,9 +18,9 @@ abstract class GalleryDatabase : RoomDatabase() {
abstract fun WidgetsDao(): WidgetsDao abstract fun WidgetsDao(): WidgetsDao
abstract fun DateTakensDAO(): DateTakensDAO abstract fun DateTakensDao(): DateTakensDao
abstract fun FavoritesDAO(): FavoritesDAO abstract fun FavoritesDao(): FavoritesDao
companion object { companion object {
private var db: GalleryDatabase? = null private var db: GalleryDatabase? = null

View file

@ -26,6 +26,7 @@ import com.simplemobiletools.gallery.pro.asynctasks.GetMediaAsynctask
import com.simplemobiletools.gallery.pro.databases.GalleryDatabase import com.simplemobiletools.gallery.pro.databases.GalleryDatabase
import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.helpers.*
import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao
import com.simplemobiletools.gallery.pro.interfaces.FavoritesDao
import com.simplemobiletools.gallery.pro.interfaces.MediumDao import com.simplemobiletools.gallery.pro.interfaces.MediumDao
import com.simplemobiletools.gallery.pro.interfaces.WidgetsDao import com.simplemobiletools.gallery.pro.interfaces.WidgetsDao
import com.simplemobiletools.gallery.pro.models.* import com.simplemobiletools.gallery.pro.models.*
@ -116,6 +117,8 @@ val Context.widgetsDB: WidgetsDao get() = GalleryDatabase.getInstance(applicatio
val Context.directoryDB: DirectoryDao get() = GalleryDatabase.getInstance(applicationContext).DirectoryDao() val Context.directoryDB: DirectoryDao get() = GalleryDatabase.getInstance(applicationContext).DirectoryDao()
val Context.favoritesDB: FavoritesDao get() = GalleryDatabase.getInstance(applicationContext).FavoritesDao()
val Context.recycleBin: File get() = filesDir val Context.recycleBin: File get() = filesDir
val Context.recycleBinPath: String get() = filesDir.absolutePath val Context.recycleBinPath: String get() = filesDir.absolutePath
@ -712,7 +715,7 @@ fun Context.getOTGFolderChildrenNames(path: String) = getOTGFolderChildren(path)
fun Context.getFavoritePaths(): ArrayList<String> { fun Context.getFavoritePaths(): ArrayList<String> {
return try { return try {
galleryDB.FavoritesDAO().getValidFavoritePaths() as ArrayList<String> favoritesDB.getValidFavoritePaths() as ArrayList<String>
} catch (e: Exception) { } catch (e: Exception) {
ArrayList() ArrayList()
} }
@ -721,11 +724,10 @@ 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) { fun Context.updateFavorite(path: String, isFavorite: Boolean) {
val favoritesDAO = galleryDB.FavoritesDAO()
if (isFavorite) { if (isFavorite) {
favoritesDAO.insert(getFavoriteFromPath(path)) favoritesDB.insert(getFavoriteFromPath(path))
} else { } 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) { fun Context.deleteMediumWithPath(mediumDao: MediumDao, path: String) {
try { try {
mediumDao.deleteMediumPath(path) mediumDao.deleteMediumPath(path)
galleryDB.FavoritesDAO().deleteFavoritePath(path) favoritesDB.deleteFavoritePath(path)
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
} }
@ -840,7 +842,7 @@ fun Context.addPathToDB(path: String) {
try { try {
val mediumDao = galleryDB.MediumDao() 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 videoDuration = if (type == TYPE_VIDEOS) path.getVideoDuration() else 0
val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(), val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(),
File(path).length(), type, videoDuration, isFavorite, 0L) File(path).length(), type, videoDuration, isFavorite, 0L)

View file

@ -3,6 +3,6 @@ package com.simplemobiletools.gallery.pro.interfaces
import androidx.room.Dao import androidx.room.Dao
@Dao @Dao
interface DateTakensDAO { interface DateTakensDao {
} }

View file

@ -7,7 +7,7 @@ import androidx.room.Query
import com.simplemobiletools.gallery.pro.models.Favorite import com.simplemobiletools.gallery.pro.models.Favorite
@Dao @Dao
interface FavoritesDAO { interface FavoritesDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(favorite: Favorite) fun insert(favorite: Favorite)
@ -25,4 +25,7 @@ interface FavoritesDAO {
@Query("DELETE FROM favorites WHERE full_path = :path COLLATE NOCASE") @Query("DELETE FROM favorites WHERE full_path = :path COLLATE NOCASE")
fun deleteFavoritePath(path: String) fun deleteFavoritePath(path: String)
@Query("DELETE FROM favorites")
fun clearFavorites()
} }

View file

@ -44,7 +44,4 @@ interface MediumDao {
@Query("DELETE FROM media WHERE deleted_ts != 0") @Query("DELETE FROM media WHERE deleted_ts != 0")
fun clearRecycleBin() fun clearRecycleBin()
@Query("UPDATE media SET is_favorite = 0")
fun clearFavorites()
} }