From 54bb8232c524946da92e2a565b4ff94d7c13fa0f Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 15 Sep 2020 22:26:26 +0200 Subject: [PATCH] store last_modified in a custom db with date_takens too --- app/build.gradle | 2 +- .../gallery/pro/databases/GalleryDatabase.kt | 21 ++++++++++++------- .../gallery/pro/extensions/Activity.kt | 2 +- .../gallery/pro/interfaces/DateTakensDao.kt | 4 ++-- .../gallery/pro/models/DateTaken.kt | 13 ++++++------ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0b8482f3b..8d47bfbbc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -77,7 +77,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.30.2' + implementation 'com.simplemobiletools:commons:5.30.4' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' 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 6e2be4788..0b41a17d6 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 @@ -9,7 +9,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase import com.simplemobiletools.gallery.pro.interfaces.* import com.simplemobiletools.gallery.pro.models.* -@Database(entities = [Directory::class, Medium::class, Widget::class, DateTaken::class, Favorite::class], version = 8) +@Database(entities = [Directory::class, Medium::class, Widget::class, DateTaken::class, Favorite::class], version = 9) abstract class GalleryDatabase : RoomDatabase() { abstract fun DirectoryDao(): DirectoryDao @@ -30,12 +30,13 @@ abstract class GalleryDatabase : RoomDatabase() { synchronized(GalleryDatabase::class) { if (db == null) { db = Room.databaseBuilder(context.applicationContext, GalleryDatabase::class.java, "gallery.db") - .fallbackToDestructiveMigration() - .addMigrations(MIGRATION_4_5) - .addMigrations(MIGRATION_5_6) - .addMigrations(MIGRATION_6_7) - .addMigrations(MIGRATION_7_8) - .build() + .fallbackToDestructiveMigration() + .addMigrations(MIGRATION_4_5) + .addMigrations(MIGRATION_5_6) + .addMigrations(MIGRATION_6_7) + .addMigrations(MIGRATION_7_8) + .addMigrations(MIGRATION_8_9) + .build() } } } @@ -74,5 +75,11 @@ abstract class GalleryDatabase : RoomDatabase() { database.execSQL("ALTER TABLE directories ADD COLUMN sort_value TEXT default '' NOT NULL") } } + + private val MIGRATION_8_9 = object : Migration(8, 9) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE date_takens ADD COLUMN last_modified INTEGER default 0 NOT NULL") + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 14d9a2e0c..ed7f6da3b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -450,7 +450,7 @@ fun Activity.fixDateTaken(paths: ArrayList, showToasts: Boolean, hasResc mediaDB.updateFavoriteDateTaken(path, timestamp) didUpdateFile = true - val dateTaken = DateTaken(null, path, path.getFilenameFromPath(), path.getParentPath(), timestamp, (System.currentTimeMillis() / 1000).toInt()) + val dateTaken = DateTaken(null, path, path.getFilenameFromPath(), path.getParentPath(), timestamp, (System.currentTimeMillis() / 1000).toInt(), File(path).lastModified()) dateTakens.add(dateTaken) if (!hasRescanned && getFileDateTaken(path) == 0L) { pathsToRescan.add(path) 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 index 6f8b609a8..5041727e9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DateTakensDao.kt @@ -11,9 +11,9 @@ interface DateTakensDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(dateTakens: List) - @Query("SELECT full_path, filename, parent_path, date_taken, last_fixed FROM date_takens WHERE parent_path = :path COLLATE NOCASE") + @Query("SELECT full_path, filename, parent_path, date_taken, last_fixed, last_modified FROM date_takens WHERE parent_path = :path COLLATE NOCASE") fun getDateTakensFromPath(path: String): List - @Query("SELECT full_path, filename, parent_path, date_taken, last_fixed FROM date_takens") + @Query("SELECT full_path, filename, parent_path, date_taken, last_fixed, last_modified FROM date_takens") fun getAllDateTakens(): List } 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 index 293e2a619..98171df7b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/DateTaken.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/DateTaken.kt @@ -9,9 +9,10 @@ import androidx.room.PrimaryKey // 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 = "filename") var filename: String, - @ColumnInfo(name = "parent_path") var parentPath: String, - @ColumnInfo(name = "date_taken") var taken: Long, - @ColumnInfo(name = "last_fixed") var lastFixed: Int) + @PrimaryKey(autoGenerate = true) var id: Int?, + @ColumnInfo(name = "full_path") var fullPath: String, + @ColumnInfo(name = "filename") var filename: String, + @ColumnInfo(name = "parent_path") var parentPath: String, + @ColumnInfo(name = "date_taken") var taken: Long, + @ColumnInfo(name = "last_fixed") var lastFixed: Int, + @ColumnInfo(name = "last_modified") var lastModified: Long)