create an own table DateTakens to be used at sorting

This commit is contained in:
tibbi 2020-01-15 21:43:39 +01:00
parent 39ed883479
commit 8b02b93161
3 changed files with 35 additions and 1 deletions

View file

@ -6,14 +6,16 @@ import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import androidx.room.migration.Migration import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase 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.DirectoryDao
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.DateTaken
import com.simplemobiletools.gallery.pro.models.Directory import com.simplemobiletools.gallery.pro.models.Directory
import com.simplemobiletools.gallery.pro.models.Medium import com.simplemobiletools.gallery.pro.models.Medium
import com.simplemobiletools.gallery.pro.models.Widget 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 class GalleryDatabase : RoomDatabase() {
abstract fun DirectoryDao(): DirectoryDao abstract fun DirectoryDao(): DirectoryDao
@ -22,6 +24,8 @@ abstract class GalleryDatabase : RoomDatabase() {
abstract fun WidgetsDao(): WidgetsDao abstract fun WidgetsDao(): WidgetsDao
abstract fun DateTakensDAO(): DateTakensDAO
companion object { companion object {
private var db: GalleryDatabase? = null private var db: GalleryDatabase? = null
@ -33,6 +37,7 @@ abstract class GalleryDatabase : RoomDatabase() {
.fallbackToDestructiveMigration() .fallbackToDestructiveMigration()
.addMigrations(MIGRATION_4_5) .addMigrations(MIGRATION_4_5)
.addMigrations(MIGRATION_5_6) .addMigrations(MIGRATION_5_6)
.addMigrations(MIGRATION_6_7)
.build() .build()
} }
} }
@ -56,5 +61,11 @@ abstract class GalleryDatabase : RoomDatabase() {
database.execSQL("CREATE UNIQUE INDEX `index_widgets_widget_id` ON `widgets` (`widget_id`)") 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)")
}
}
} }
} }

View file

@ -0,0 +1,8 @@
package com.simplemobiletools.gallery.pro.interfaces
import androidx.room.Dao
@Dao
interface DateTakensDAO {
}

View file

@ -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)