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 b5ac89748..c3b036669 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,14 +6,16 @@ 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 -@Database(entities = [Directory::class, Medium::class, Widget::class], version = 6) +@Database(entities = [Directory::class, Medium::class, Widget::class, DateTaken::class], version = 7) abstract class GalleryDatabase : RoomDatabase() { abstract fun DirectoryDao(): DirectoryDao @@ -22,6 +24,8 @@ abstract class GalleryDatabase : RoomDatabase() { abstract fun WidgetsDao(): WidgetsDao + abstract fun DateTakensDAO(): DateTakensDAO + companion object { private var db: GalleryDatabase? = null @@ -33,6 +37,7 @@ abstract class GalleryDatabase : RoomDatabase() { .fallbackToDestructiveMigration() .addMigrations(MIGRATION_4_5) .addMigrations(MIGRATION_5_6) + .addMigrations(MIGRATION_6_7) .build() } } @@ -56,5 +61,11 @@ abstract class GalleryDatabase : RoomDatabase() { database.execSQL("CREATE UNIQUE INDEX `index_widgets_widget_id` ON `widgets` (`widget_id`)") } } + + private val MIGRATION_6_7 = object : Migration(6, 7) { + 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` LONG NOT NULL)") + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDAO.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDAO.kt new file mode 100644 index 000000000..107801537 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDAO.kt @@ -0,0 +1,8 @@ +package com.simplemobiletools.gallery.pro.interfaces + +import androidx.room.Dao + +@Dao +interface DateTakensDAO { + +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/DateTaken.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/DateTaken.kt new file mode 100644 index 000000000..aeb584e54 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/DateTaken.kt @@ -0,0 +1,15 @@ +package com.simplemobiletools.gallery.pro.models + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.Index +import androidx.room.PrimaryKey + +// Date Taken in the MediaStore is unreliable and hard to work with, keep the values in an own database +// It is used at sorting files by date taken, checking EXIF file by file would be way too slow +@Entity(tableName = "date_takens", indices = [Index(value = ["full_path"], unique = true)]) +data class DateTaken( + @PrimaryKey(autoGenerate = true) var id: Int?, + @ColumnInfo(name = "full_path") var fullPath: String, + @ColumnInfo(name = "parent_path") var parentPath: String, + @ColumnInfo(name = "last_fixed") var lastFixed: Long)