create an own table for storing favorite items too
This commit is contained in:
parent
ca6b84be81
commit
402fccbc21
|
@ -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`)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.simplemobiletools.gallery.pro.interfaces
|
||||
|
||||
import androidx.room.Dao
|
||||
|
||||
@Dao
|
||||
interface FavoritesDAO {
|
||||
|
||||
}
|
|
@ -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)
|
Loading…
Reference in New Issue