From 500fe57e499272e6a5a97e935024ddea25a0bbe7 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 2 Oct 2023 18:32:40 -0700 Subject: [PATCH] add serverid api --- app/src/main/java/gallery/memories/NativeX.kt | 5 +++++ app/src/main/java/gallery/memories/dao/AppDatabase.kt | 2 +- app/src/main/java/gallery/memories/dao/PhotoDao.kt | 7 +++++-- app/src/main/java/gallery/memories/mapper/Photo.kt | 3 ++- app/src/main/java/gallery/memories/mapper/SystemImage.kt | 1 + .../main/java/gallery/memories/service/TimelineQuery.kt | 9 +++++++++ 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/gallery/memories/NativeX.kt b/app/src/main/java/gallery/memories/NativeX.kt index e318fdd6..4064eede 100644 --- a/app/src/main/java/gallery/memories/NativeX.kt +++ b/app/src/main/java/gallery/memories/NativeX.kt @@ -171,6 +171,11 @@ class NativeX(private val mCtx: MainActivity) { return query.syncStatus } + @JavascriptInterface + fun setServerId(auid: Long, serverId: Long) { + Thread { query.setServerId(auid, serverId) }.start() + } + fun handleRequest(request: WebResourceRequest): WebResourceResponse { val path = request.url.path ?: return makeErrorResponse() diff --git a/app/src/main/java/gallery/memories/dao/AppDatabase.kt b/app/src/main/java/gallery/memories/dao/AppDatabase.kt index 8c20c59f..950f7247 100644 --- a/app/src/main/java/gallery/memories/dao/AppDatabase.kt +++ b/app/src/main/java/gallery/memories/dao/AppDatabase.kt @@ -9,7 +9,7 @@ import gallery.memories.R import gallery.memories.mapper.Photo -@Database(entities = [Photo::class], version = 9) +@Database(entities = [Photo::class], version = 10) abstract class AppDatabase : RoomDatabase() { abstract fun photoDao(): PhotoDao diff --git a/app/src/main/java/gallery/memories/dao/PhotoDao.kt b/app/src/main/java/gallery/memories/dao/PhotoDao.kt index 64d66764..53cc2312 100644 --- a/app/src/main/java/gallery/memories/dao/PhotoDao.kt +++ b/app/src/main/java/gallery/memories/dao/PhotoDao.kt @@ -12,7 +12,7 @@ interface PhotoDao { @Query("SELECT 1") fun ping(): Int - @Query("SELECT * FROM photos WHERE dayid=:dayId AND bucket_id IN (:buckets)") + @Query("SELECT * FROM photos WHERE dayid=:dayId AND bucket_id IN (:buckets) AND server_id = 0") fun getPhotosByDay(dayId: Long, buckets: List): List @Query("SELECT * FROM photos WHERE local_id IN (:fileIds)") @@ -21,7 +21,7 @@ interface PhotoDao { @Query("SELECT * FROM photos WHERE auid IN (:auids)") fun getPhotosByAUIDs(auids: List): List - @Query("SELECT dayid, COUNT(local_id) AS count FROM photos WHERE bucket_id IN (:bucketIds) GROUP BY dayid") + @Query("SELECT dayid, COUNT(local_id) AS count FROM photos WHERE bucket_id IN (:bucketIds) AND server_id = 0 GROUP BY dayid") fun getDays(bucketIds: List): List @Query("DELETE FROM photos WHERE local_id IN (:fileIds)") @@ -41,4 +41,7 @@ interface PhotoDao { @Query("SELECT bucket_id, bucket_name FROM photos GROUP BY bucket_id") fun getBuckets(): List + + @Query("UPDATE photos SET server_id=:serverId WHERE auid=:auid") + fun setServerId(auid: Long, serverId: Long) } \ No newline at end of file diff --git a/app/src/main/java/gallery/memories/mapper/Photo.kt b/app/src/main/java/gallery/memories/mapper/Photo.kt index 82f2d727..5ae0b254 100644 --- a/app/src/main/java/gallery/memories/mapper/Photo.kt +++ b/app/src/main/java/gallery/memories/mapper/Photo.kt @@ -12,12 +12,13 @@ import androidx.room.PrimaryKey Index(value = ["dayid"]), Index(value = ["flag"]), Index(value = ["bucket_id"]), - Index(value = ["bucket_id", "dayid"]) + Index(value = ["bucket_id", "dayid", "server_id"]) ] ) data class Photo( @PrimaryKey(autoGenerate = true) val id: Int? = null, @ColumnInfo(name = "local_id") val localId: Long, + @ColumnInfo(name = "server_id") val serverId: Long, @ColumnInfo(name = "auid") val auid: Long, @ColumnInfo(name = "mtime") val mtime: Long, @ColumnInfo(name = "date_taken") val dateTaken: Long, diff --git a/app/src/main/java/gallery/memories/mapper/SystemImage.kt b/app/src/main/java/gallery/memories/mapper/SystemImage.kt index 382bff27..8fc08b60 100644 --- a/app/src/main/java/gallery/memories/mapper/SystemImage.kt +++ b/app/src/main/java/gallery/memories/mapper/SystemImage.kt @@ -227,6 +227,7 @@ class SystemImage { bucketId = bucketId, bucketName = bucketName, flag = 0, + serverId = 0 ) } } \ No newline at end of file diff --git a/app/src/main/java/gallery/memories/service/TimelineQuery.kt b/app/src/main/java/gallery/memories/service/TimelineQuery.kt index 00220cd7..8030974a 100644 --- a/app/src/main/java/gallery/memories/service/TimelineQuery.kt +++ b/app/src/main/java/gallery/memories/service/TimelineQuery.kt @@ -411,6 +411,15 @@ class TimelineQuery(private val mCtx: MainActivity) { Log.v(TAG, "Inserted file to local DB: $fileId / $baseName") } + /** + * Set server ID for local file. + * @param auid AUID + * @param serverId Server ID + */ + fun setServerId(auid: Long, serverId: Long) { + mPhotoDao.setServerId(auid, serverId) + } + /** * Active local folders response. * This is in timeline query because it calls the database service.