From 402fccbc21e45ba6113f45994b6f9eea88d32858 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 16 Jan 2020 11:26:13 +0100 Subject: [PATCH] create an own table for storing favorite items too --- .../gallery/pro/databases/GalleryDatabase.kt | 17 ++++++++--------- .../gallery/pro/interfaces/FavoritesDAO.kt | 8 ++++++++ .../gallery/pro/models/Favorite.kt | 12 ++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Favorite.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/databases/GalleryDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/databases/GalleryDatabase.kt index 2d0398675..d427a6142 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/databases/GalleryDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/databases/GalleryDatabase.kt @@ -6,16 +6,10 @@ import androidx.room.Room import androidx.room.RoomDatabase import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase -import com.simplemobiletools.gallery.pro.interfaces.DateTakensDAO -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.DateTaken -import com.simplemobiletools.gallery.pro.models.Directory -import com.simplemobiletools.gallery.pro.models.Medium -import com.simplemobiletools.gallery.pro.models.Widget +import com.simplemobiletools.gallery.pro.interfaces.* +import com.simplemobiletools.gallery.pro.models.* -@Database(entities = [Directory::class, Medium::class, Widget::class, DateTaken::class], version = 7) +@Database(entities = [Directory::class, Medium::class, Widget::class, DateTaken::class, Favorite::class], version = 7) abstract class GalleryDatabase : RoomDatabase() { abstract fun DirectoryDao(): DirectoryDao @@ -26,6 +20,8 @@ abstract class GalleryDatabase : RoomDatabase() { abstract fun DateTakensDAO(): DateTakensDAO + abstract fun FavoritesDAO(): FavoritesDAO + companion object { private var db: GalleryDatabase? = null @@ -66,6 +62,9 @@ abstract class GalleryDatabase : RoomDatabase() { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("CREATE TABLE IF NOT EXISTS `date_takens` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `full_path` TEXT NOT NULL, `parent_path` TEXT NOT NULL, `last_fixed` INTEGER NOT NULL)") database.execSQL("CREATE UNIQUE INDEX `index_date_takens_full_path` ON `date_takens` (`full_path`)") + + database.execSQL("CREATE TABLE IF NOT EXISTS `favorites` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `full_path` TEXT NOT NULL, `parent_path` TEXT NOT NULL)") + database.execSQL("CREATE UNIQUE INDEX `index_favorites_full_path` ON `favorites` (`full_path`)") } } } 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 new file mode 100644 index 000000000..1d80c3e80 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/FavoritesDAO.kt @@ -0,0 +1,8 @@ +package com.simplemobiletools.gallery.pro.interfaces + +import androidx.room.Dao + +@Dao +interface FavoritesDAO { + +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Favorite.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Favorite.kt new file mode 100644 index 000000000..a6c3fe001 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Favorite.kt @@ -0,0 +1,12 @@ +package com.simplemobiletools.gallery.pro.models + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.Index +import androidx.room.PrimaryKey + +@Entity(tableName = "favorites", indices = [Index(value = ["full_path"], unique = true)]) +data class Favorite( + @PrimaryKey(autoGenerate = true) var id: Int?, + @ColumnInfo(name = "full_path") var fullPath: String, + @ColumnInfo(name = "parent_path") var parentPath: String)