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 4020ed9f5..b23b28522 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 @@ -31,6 +31,7 @@ import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.activities.SimpleActivity import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN +import com.simplemobiletools.gallery.pro.models.DateTaken import com.squareup.picasso.Picasso import java.io.File import java.io.FileOutputStream @@ -414,6 +415,8 @@ fun Activity.fixDateTaken(paths: ArrayList, showToasts: Boolean, hasResc val operations = ArrayList() ensureBackgroundThread { + val dateTakens = ArrayList() + for (path in paths) { val dateTime = ExifInterface(path).getAttribute(ExifInterface.TAG_DATETIME_ORIGINAL) ?: ExifInterface(path).getAttribute(ExifInterface.TAG_DATETIME) ?: continue @@ -443,6 +446,8 @@ 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()) + dateTakens.add(dateTaken) if (!hasRescanned && getFileDateTaken(path) == 0L) { pathsToRescan.add(path) } @@ -454,6 +459,10 @@ fun Activity.fixDateTaken(paths: ArrayList, showToasts: Boolean, hasResc } if (hasRescanned || pathsToRescan.isEmpty()) { + if (dateTakens.isNotEmpty()) { + dateTakensDB.insertAll(dateTakens) + } + runOnUiThread { if (showToasts) { toast(if (didUpdateFile) R.string.dates_fixed_successfully else R.string.unknown_error_occurred) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 179832a97..a3d542674 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -25,10 +25,7 @@ import com.simplemobiletools.gallery.pro.activities.SettingsActivity import com.simplemobiletools.gallery.pro.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.pro.databases.GalleryDatabase import com.simplemobiletools.gallery.pro.helpers.* -import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao -import com.simplemobiletools.gallery.pro.interfaces.FavoritesDao -import com.simplemobiletools.gallery.pro.interfaces.MediumDao -import com.simplemobiletools.gallery.pro.interfaces.WidgetsDao +import com.simplemobiletools.gallery.pro.interfaces.* import com.simplemobiletools.gallery.pro.models.* import com.simplemobiletools.gallery.pro.svg.SvgSoftwareLayerSetter import com.simplemobiletools.gallery.pro.views.MySquareImageView @@ -119,6 +116,8 @@ val Context.directoryDao: DirectoryDao get() = GalleryDatabase.getInstance(appli val Context.favoritesDB: FavoritesDao get() = GalleryDatabase.getInstance(applicationContext).FavoritesDao() +val Context.dateTakensDB: DateTakensDao get() = GalleryDatabase.getInstance(applicationContext).DateTakensDao() + val Context.recycleBin: File get() = filesDir val Context.recycleBinPath: String get() = filesDir.absolutePath 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 0d3380408..6f8b609a8 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 @@ -1,8 +1,19 @@ package com.simplemobiletools.gallery.pro.interfaces import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import com.simplemobiletools.gallery.pro.models.DateTaken @Dao 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") + fun getDateTakensFromPath(path: String): List + + @Query("SELECT full_path, filename, parent_path, date_taken, last_fixed FROM date_takens") + fun getAllDateTakens(): List }