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 {
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'

View file

@ -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
@ -35,6 +35,7 @@ abstract class GalleryDatabase : RoomDatabase() {
.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")
}
}
}
}

View file

@ -450,7 +450,7 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, 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)

View file

@ -11,9 +11,9 @@ interface DateTakensDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
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>
@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>
}

View file

@ -14,4 +14,5 @@ data class DateTaken(
@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_fixed") var lastFixed: Int,
@ColumnInfo(name = "last_modified") var lastModified: Long)