Implement AUID
parent
290d8c6bed
commit
d9e1c2a95d
|
@ -15,6 +15,8 @@ class Fields {
|
|||
const val SIZE = "size"
|
||||
const val ETAG = "etag"
|
||||
const val DATETAKEN = "datetaken"
|
||||
const val EPOCH = "epoch"
|
||||
const val AUID = "auid"
|
||||
const val DAYID = "dayid"
|
||||
const val ISVIDEO = "isvideo"
|
||||
const val VIDEO_DURATION = "video_duration"
|
||||
|
|
|
@ -136,6 +136,10 @@ class SystemImage {
|
|||
}
|
||||
}
|
||||
|
||||
val epoch get(): Long {
|
||||
return dateTaken / 1000
|
||||
}
|
||||
|
||||
val utcDate get(): Long {
|
||||
// Get EXIF date using ExifInterface if image
|
||||
if (!isVideo) {
|
||||
|
@ -146,7 +150,7 @@ class SystemImage {
|
|||
val sdf = SimpleDateFormat("yyyy:MM:dd HH:mm:ss")
|
||||
sdf.timeZone = TimeZone.GMT_ZONE
|
||||
sdf.parse(exifDate).let {
|
||||
return it.time
|
||||
return it.time / 1000
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to read EXIF data: " + e.message)
|
||||
|
@ -154,17 +158,14 @@ class SystemImage {
|
|||
}
|
||||
|
||||
// No way to get the actual local date, so just assume current timezone
|
||||
return dateTaken + TimeZone.getDefault().getOffset(dateTaken).toLong()
|
||||
return (dateTaken + TimeZone.getDefault().getOffset(dateTaken).toLong()) / 1000
|
||||
}
|
||||
|
||||
val auid get(): Long {
|
||||
val crc = java.util.zip.CRC32()
|
||||
|
||||
// get date in seconds
|
||||
val date = dateTaken / 1000
|
||||
|
||||
// pass date taken + size as decimal string
|
||||
crc.update((date.toString() + size.toString()).toByteArray())
|
||||
crc.update((epoch.toString() + size.toString()).toByteArray())
|
||||
|
||||
return crc.value
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.database.sqlite.SQLiteOpenHelper
|
|||
import android.database.sqlite.SQLiteDatabase
|
||||
import gallery.memories.R
|
||||
|
||||
class DbService(val context: Context) : SQLiteOpenHelper(context, "memories", null, 36) {
|
||||
class DbService(val context: Context) : SQLiteOpenHelper(context, "memories", null, 37) {
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
db.execSQL("""
|
||||
CREATE TABLE images (
|
||||
|
|
|
@ -109,18 +109,14 @@ import java.util.concurrent.CountDownLatch
|
|||
// Filter for enabled buckets
|
||||
val enabledBuckets = getEnabledBucketIds().joinToString(",")
|
||||
|
||||
// Get list of images from DB
|
||||
// Get list of image IDs from DB
|
||||
val imageIds: MutableSet<Long> = ArraySet()
|
||||
val datesTaken: MutableMap<Long, Long> = HashMap()
|
||||
mDb.rawQuery("""
|
||||
SELECT local_id, date_taken FROM images
|
||||
WHERE dayid = ?
|
||||
AND bucket_id IN ($enabledBuckets)
|
||||
SELECT local_id FROM images
|
||||
WHERE dayid = ? AND bucket_id IN ($enabledBuckets)
|
||||
""", arrayOf(dayId.toString())).use { cursor ->
|
||||
while (cursor.moveToNext()) {
|
||||
val localId = cursor.getLong(0)
|
||||
datesTaken[localId] = cursor.getLong(1)
|
||||
imageIds.add(localId)
|
||||
imageIds.add(cursor.getLong(0))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,7 +134,8 @@ import java.util.concurrent.CountDownLatch
|
|||
.put(Fields.Photo.WIDTH, image.width)
|
||||
.put(Fields.Photo.SIZE, image.size)
|
||||
.put(Fields.Photo.ETAG, image.mtime.toString())
|
||||
.put(Fields.Photo.DATETAKEN, datesTaken[image.fileId])
|
||||
.put(Fields.Photo.EPOCH, image.epoch)
|
||||
.put(Fields.Photo.AUID, image.auid)
|
||||
.put(Fields.Photo.DAYID, dayId)
|
||||
|
||||
if (image.isVideo) {
|
||||
|
@ -352,8 +349,7 @@ import java.util.concurrent.CountDownLatch
|
|||
}
|
||||
}
|
||||
|
||||
val auid = image.auid
|
||||
val dateTaken = image.utcDate / 1000
|
||||
val dateTaken = image.utcDate
|
||||
val dayId = dateTaken / 86400
|
||||
|
||||
// Delete file with same local_id and insert new one
|
||||
|
@ -361,21 +357,21 @@ import java.util.concurrent.CountDownLatch
|
|||
mDb.execSQL("DELETE FROM images WHERE local_id = ?", arrayOf(fileId))
|
||||
mDb.execSQL("""
|
||||
INSERT OR IGNORE INTO images
|
||||
(local_id, mtime, basename, auid, date_taken, dayid, bucket_id, bucket_name)
|
||||
(local_id, mtime, date_taken, dayid, auid, basename, bucket_id, bucket_name)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", arrayOf(
|
||||
image.fileId,
|
||||
image.mtime,
|
||||
image.baseName,
|
||||
auid,
|
||||
dateTaken,
|
||||
dayId,
|
||||
image.auid,
|
||||
image.baseName,
|
||||
image.bucketId,
|
||||
image.bucketName
|
||||
))
|
||||
mDb.setTransactionSuccessful()
|
||||
mDb.endTransaction()
|
||||
Log.v(TAG, "Inserted file to local DB: $fileId / $baseName / $dayId / $auid")
|
||||
Log.v(TAG, "Inserted file to local DB: $fileId / $baseName / $dayId")
|
||||
}
|
||||
|
||||
fun getEnabledBucketIds(): Set<String> {
|
||||
|
|
Loading…
Reference in New Issue