add serverid api

pull/653/merge
Varun Patil 2023-10-02 18:32:40 -07:00
parent e3bea8b35b
commit 500fe57e49
6 changed files with 23 additions and 4 deletions

View File

@ -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()

View File

@ -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

View File

@ -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<String>): List<Photo>
@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<Long>): List<Photo>
@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<String>): List<Day>
@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<Bucket>
@Query("UPDATE photos SET server_id=:serverId WHERE auid=:auid")
fun setServerId(auid: Long, serverId: Long)
}

View File

@ -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,

View File

@ -227,6 +227,7 @@ class SystemImage {
bucketId = bucketId,
bucketName = bucketName,
flag = 0,
serverId = 0
)
}
}

View File

@ -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.