From a19d0953469635503256534ff65439d4bf36fa36 Mon Sep 17 00:00:00 2001 From: ocean <503259349@qq.com> Date: Fri, 12 Sep 2025 18:17:47 +0800 Subject: [PATCH] update --- .../pro/app/room/dao/RecentReadDao.kt | 2 +- .../pro/app/room/entity/NoteEntity.kt | 2 +- .../pro/app/room/repository/PdfRepository.kt | 28 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/all/pdfreader/pro/app/room/dao/RecentReadDao.kt b/app/src/main/java/com/all/pdfreader/pro/app/room/dao/RecentReadDao.kt index 5023ed0..e2e1c8a 100644 --- a/app/src/main/java/com/all/pdfreader/pro/app/room/dao/RecentReadDao.kt +++ b/app/src/main/java/com/all/pdfreader/pro/app/room/dao/RecentReadDao.kt @@ -12,7 +12,7 @@ interface RecentReadDao { suspend fun insertOrUpdate(recentRead: RecentReadEntity) @Query("SELECT * FROM recently_read WHERE filePath = :filePath") - suspend fun getByPdfHash(filePath: String): RecentReadEntity? + suspend fun getByFilePath(filePath: String): RecentReadEntity? @Query(""" SELECT pdf_documents.* diff --git a/app/src/main/java/com/all/pdfreader/pro/app/room/entity/NoteEntity.kt b/app/src/main/java/com/all/pdfreader/pro/app/room/entity/NoteEntity.kt index a55cbb6..7a0eac8 100644 --- a/app/src/main/java/com/all/pdfreader/pro/app/room/entity/NoteEntity.kt +++ b/app/src/main/java/com/all/pdfreader/pro/app/room/entity/NoteEntity.kt @@ -19,7 +19,7 @@ data class NoteEntity( @PrimaryKey(autoGenerate = true) val id: Long = 0, - val filePath: String, // 关联PdfDocumentEntity的fileHash + val filePath: String, // 关联PdfDocumentEntity的 filePath val pageNumber: Int, // 页码(从0开始) val noteType: String, // 注释类型: HIGHLIGHT, TEXT_NOTE, DRAWING val content: String, // 注释内容(文本或序列化的绘制数据) diff --git a/app/src/main/java/com/all/pdfreader/pro/app/room/repository/PdfRepository.kt b/app/src/main/java/com/all/pdfreader/pro/app/room/repository/PdfRepository.kt index 1ba32f0..de3d475 100644 --- a/app/src/main/java/com/all/pdfreader/pro/app/room/repository/PdfRepository.kt +++ b/app/src/main/java/com/all/pdfreader/pro/app/room/repository/PdfRepository.kt @@ -89,7 +89,7 @@ class PdfRepository private constructor(context: Context) { // 最近阅读相关操作 suspend fun addToRecent(filePath: String, page: Int = 0) { - val existing = recentDao.getByPdfHash(filePath) + val existing = recentDao.getByFilePath(filePath) if (existing != null) { recentDao.updateOpenTime(filePath) } else { @@ -107,29 +107,29 @@ class PdfRepository private constructor(context: Context) { suspend fun addBookmark(bookmark: BookmarkEntity): Long = bookmarkDao.insert(bookmark) suspend fun updateBookmark(bookmark: BookmarkEntity) = bookmarkDao.update(bookmark) suspend fun deleteBookmark(bookmark: BookmarkEntity) = bookmarkDao.delete(bookmark) - fun getBookmarksByPdf(pdfHash: String): Flow> = - bookmarkDao.getBookmarksByPdf(pdfHash) + fun getBookmarksByPdf(filePath: String): Flow> = + bookmarkDao.getBookmarksByPdf(filePath) - suspend fun getBookmarksByPage(pdfHash: String, page: Int): List = - bookmarkDao.getBookmarksByPage(pdfHash, page) + suspend fun getBookmarksByPage(filePath: String, page: Int): List = + bookmarkDao.getBookmarksByPage(filePath, page) // 注释相关操作 suspend fun addNote(note: NoteEntity): Long = noteDao.insert(note) suspend fun updateNote(note: NoteEntity) = noteDao.update(note) suspend fun deleteNote(note: NoteEntity) = noteDao.delete(note) - fun getNotesByPdf(pdfHash: String): Flow> = noteDao.getNotesByPdf(pdfHash) - suspend fun getNotesByPage(pdfHash: String, page: Int): List = - noteDao.getNotesByPage(pdfHash, page) + fun getNotesByPdf(filePath: String): Flow> = noteDao.getNotesByPdf(filePath) + suspend fun getNotesByPage(filePath: String, page: Int): List = + noteDao.getNotesByPage(filePath, page) - fun getNotesByType(pdfHash: String, noteType: String): Flow> = - noteDao.getNotesByType(pdfHash, noteType) + fun getNotesByType(filePath: String, noteType: String): Flow> = + noteDao.getNotesByType(filePath, noteType) // 组合查询 - suspend fun getPdfWithDetails(pdfHash: String): Flow { - return combine(pdfDao.getByHash(pdfHash)?.let { kotlinx.coroutines.flow.flowOf(it) } + suspend fun getPdfWithDetails(filePath: String): Flow { + return combine(pdfDao.getByPath(filePath)?.let { kotlinx.coroutines.flow.flowOf(it) } ?: kotlinx.coroutines.flow.flowOf(null), - bookmarkDao.getBookmarksByPdf(pdfHash), - noteDao.getNotesByPdf(pdfHash)) { document, bookmarks, notes -> + bookmarkDao.getBookmarksByPdf(filePath), + noteDao.getNotesByPdf(filePath)) { document, bookmarks, notes -> PdfDetails(document, bookmarks, notes) } }