mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
store the fixed Date Taken values in the new table
This commit is contained in:
parent
665690c819
commit
2517170aeb
3 changed files with 23 additions and 4 deletions
|
@ -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<String>, showToasts: Boolean, hasResc
|
|||
val operations = ArrayList<ContentProviderOperation>()
|
||||
|
||||
ensureBackgroundThread {
|
||||
val dateTakens = ArrayList<DateTaken>()
|
||||
|
||||
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<String>, 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<String>, 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<DateTaken>)
|
||||
|
||||
@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<DateTaken>
|
||||
|
||||
@Query("SELECT full_path, filename, parent_path, date_taken, last_fixed FROM date_takens")
|
||||
fun getAllDateTakens(): List<DateTaken>
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue