store last_modified in a custom db with date_takens too

This commit is contained in:
tibbi 2020-09-15 22:26:26 +02:00
parent d689708cf6
commit 54bb8232c5
5 changed files with 25 additions and 17 deletions

View file

@ -77,7 +77,7 @@ android {
} }
dependencies { 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 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'

View file

@ -9,7 +9,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import com.simplemobiletools.gallery.pro.interfaces.* import com.simplemobiletools.gallery.pro.interfaces.*
import com.simplemobiletools.gallery.pro.models.* 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 class GalleryDatabase : RoomDatabase() {
abstract fun DirectoryDao(): DirectoryDao abstract fun DirectoryDao(): DirectoryDao
@ -30,12 +30,13 @@ abstract class GalleryDatabase : RoomDatabase() {
synchronized(GalleryDatabase::class) { synchronized(GalleryDatabase::class) {
if (db == null) { if (db == null) {
db = Room.databaseBuilder(context.applicationContext, GalleryDatabase::class.java, "gallery.db") db = Room.databaseBuilder(context.applicationContext, GalleryDatabase::class.java, "gallery.db")
.fallbackToDestructiveMigration() .fallbackToDestructiveMigration()
.addMigrations(MIGRATION_4_5) .addMigrations(MIGRATION_4_5)
.addMigrations(MIGRATION_5_6) .addMigrations(MIGRATION_5_6)
.addMigrations(MIGRATION_6_7) .addMigrations(MIGRATION_6_7)
.addMigrations(MIGRATION_7_8) .addMigrations(MIGRATION_7_8)
.build() .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") 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")
}
}
} }
} }

View file

@ -450,7 +450,7 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, showToasts: Boolean, hasResc
mediaDB.updateFavoriteDateTaken(path, timestamp) mediaDB.updateFavoriteDateTaken(path, timestamp)
didUpdateFile = true 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) dateTakens.add(dateTaken)
if (!hasRescanned && getFileDateTaken(path) == 0L) { if (!hasRescanned && getFileDateTaken(path) == 0L) {
pathsToRescan.add(path) pathsToRescan.add(path)

View file

@ -11,9 +11,9 @@ interface DateTakensDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(dateTakens: List<DateTaken>) fun insertAll(dateTakens: List<DateTaken>)
@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<DateTaken> fun getDateTakensFromPath(path: String): List<DateTaken>
@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<DateTaken> fun getAllDateTakens(): List<DateTaken>
} }

View file

@ -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 // 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)]) @Entity(tableName = "date_takens", indices = [Index(value = ["full_path"], unique = true)])
data class DateTaken( data class DateTaken(
@PrimaryKey(autoGenerate = true) var id: Int?, @PrimaryKey(autoGenerate = true) var id: Int?,
@ColumnInfo(name = "full_path") var fullPath: String, @ColumnInfo(name = "full_path") var fullPath: String,
@ColumnInfo(name = "filename") var filename: String, @ColumnInfo(name = "filename") var filename: String,
@ColumnInfo(name = "parent_path") var parentPath: String, @ColumnInfo(name = "parent_path") var parentPath: String,
@ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "date_taken") var taken: Long,
@ColumnInfo(name = "last_fixed") var lastFixed: Int) @ColumnInfo(name = "last_fixed") var lastFixed: Int,
@ColumnInfo(name = "last_modified") var lastModified: Long)