This commit is contained in:
ocean 2025-09-12 18:17:47 +08:00
parent 5f1990f830
commit a19d095346
3 changed files with 16 additions and 16 deletions

View File

@ -12,7 +12,7 @@ interface RecentReadDao {
suspend fun insertOrUpdate(recentRead: RecentReadEntity) suspend fun insertOrUpdate(recentRead: RecentReadEntity)
@Query("SELECT * FROM recently_read WHERE filePath = :filePath") @Query("SELECT * FROM recently_read WHERE filePath = :filePath")
suspend fun getByPdfHash(filePath: String): RecentReadEntity? suspend fun getByFilePath(filePath: String): RecentReadEntity?
@Query(""" @Query("""
SELECT pdf_documents.* SELECT pdf_documents.*

View File

@ -19,7 +19,7 @@ data class NoteEntity(
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
val id: Long = 0, val id: Long = 0,
val filePath: String, // 关联PdfDocumentEntity的fileHash val filePath: String, // 关联PdfDocumentEntity的 filePath
val pageNumber: Int, // 页码(从0开始) val pageNumber: Int, // 页码(从0开始)
val noteType: String, // 注释类型: HIGHLIGHT, TEXT_NOTE, DRAWING val noteType: String, // 注释类型: HIGHLIGHT, TEXT_NOTE, DRAWING
val content: String, // 注释内容(文本或序列化的绘制数据) val content: String, // 注释内容(文本或序列化的绘制数据)

View File

@ -89,7 +89,7 @@ class PdfRepository private constructor(context: Context) {
// 最近阅读相关操作 // 最近阅读相关操作
suspend fun addToRecent(filePath: String, page: Int = 0) { suspend fun addToRecent(filePath: String, page: Int = 0) {
val existing = recentDao.getByPdfHash(filePath) val existing = recentDao.getByFilePath(filePath)
if (existing != null) { if (existing != null) {
recentDao.updateOpenTime(filePath) recentDao.updateOpenTime(filePath)
} else { } else {
@ -107,29 +107,29 @@ class PdfRepository private constructor(context: Context) {
suspend fun addBookmark(bookmark: BookmarkEntity): Long = bookmarkDao.insert(bookmark) suspend fun addBookmark(bookmark: BookmarkEntity): Long = bookmarkDao.insert(bookmark)
suspend fun updateBookmark(bookmark: BookmarkEntity) = bookmarkDao.update(bookmark) suspend fun updateBookmark(bookmark: BookmarkEntity) = bookmarkDao.update(bookmark)
suspend fun deleteBookmark(bookmark: BookmarkEntity) = bookmarkDao.delete(bookmark) suspend fun deleteBookmark(bookmark: BookmarkEntity) = bookmarkDao.delete(bookmark)
fun getBookmarksByPdf(pdfHash: String): Flow<List<BookmarkEntity>> = fun getBookmarksByPdf(filePath: String): Flow<List<BookmarkEntity>> =
bookmarkDao.getBookmarksByPdf(pdfHash) bookmarkDao.getBookmarksByPdf(filePath)
suspend fun getBookmarksByPage(pdfHash: String, page: Int): List<BookmarkEntity> = suspend fun getBookmarksByPage(filePath: String, page: Int): List<BookmarkEntity> =
bookmarkDao.getBookmarksByPage(pdfHash, page) bookmarkDao.getBookmarksByPage(filePath, page)
// 注释相关操作 // 注释相关操作
suspend fun addNote(note: NoteEntity): Long = noteDao.insert(note) suspend fun addNote(note: NoteEntity): Long = noteDao.insert(note)
suspend fun updateNote(note: NoteEntity) = noteDao.update(note) suspend fun updateNote(note: NoteEntity) = noteDao.update(note)
suspend fun deleteNote(note: NoteEntity) = noteDao.delete(note) suspend fun deleteNote(note: NoteEntity) = noteDao.delete(note)
fun getNotesByPdf(pdfHash: String): Flow<List<NoteEntity>> = noteDao.getNotesByPdf(pdfHash) fun getNotesByPdf(filePath: String): Flow<List<NoteEntity>> = noteDao.getNotesByPdf(filePath)
suspend fun getNotesByPage(pdfHash: String, page: Int): List<NoteEntity> = suspend fun getNotesByPage(filePath: String, page: Int): List<NoteEntity> =
noteDao.getNotesByPage(pdfHash, page) noteDao.getNotesByPage(filePath, page)
fun getNotesByType(pdfHash: String, noteType: String): Flow<List<NoteEntity>> = fun getNotesByType(filePath: String, noteType: String): Flow<List<NoteEntity>> =
noteDao.getNotesByType(pdfHash, noteType) noteDao.getNotesByType(filePath, noteType)
// 组合查询 // 组合查询
suspend fun getPdfWithDetails(pdfHash: String): Flow<PdfDetails> { suspend fun getPdfWithDetails(filePath: String): Flow<PdfDetails> {
return combine(pdfDao.getByHash(pdfHash)?.let { kotlinx.coroutines.flow.flowOf(it) } return combine(pdfDao.getByPath(filePath)?.let { kotlinx.coroutines.flow.flowOf(it) }
?: kotlinx.coroutines.flow.flowOf(null), ?: kotlinx.coroutines.flow.flowOf(null),
bookmarkDao.getBookmarksByPdf(pdfHash), bookmarkDao.getBookmarksByPdf(filePath),
noteDao.getNotesByPdf(pdfHash)) { document, bookmarks, notes -> noteDao.getNotesByPdf(filePath)) { document, bookmarks, notes ->
PdfDetails(document, bookmarks, notes) PdfDetails(document, bookmarks, notes)
} }
} }